Skip to content

fix: layer code support http bug#147

Open
mozhou52 wants to merge 1 commit intomasterfrom
layer-publish
Open

fix: layer code support http bug#147
mozhou52 wants to merge 1 commit intomasterfrom
layer-publish

Conversation

@mozhou52
Copy link
Collaborator

@mozhou52 mozhou52 commented Mar 20, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Ensure downloaded packages consistently use a .zip file extension and validate ZIP file format before proceeding.
  • Chores

    • Bumped component version to 0.1.18.
  • Tests

    • Added CI step that publishes a temporary layer, removes it, and restores directory state to validate publishing/removal flow.

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2b6f3977-b604-45e7-8645-b02c695ebade

📥 Commits

Reviewing files that changed from the base of the PR and between 94f92bc and 0e926fe.

📒 Files selected for processing (3)
  • __tests__/e2e/ci-mac-linux.sh
  • publish.yaml
  • src/utils/index.ts
✅ Files skipped from review due to trivial changes (3)
  • tests/e2e/ci-mac-linux.sh
  • src/utils/index.ts
  • publish.yaml

📝 Walkthrough

Walkthrough

Adds a CI step that publishes and removes a layer, bumps fc3 Version 0.1.17→0.1.18 in publish.yaml, and updates _downloadFromUrl to ensure returned paths end with .zip and to validate the downloaded file is a ZIP (throwing on invalid ZIPs).

Changes

Cohort / File(s) Summary
CI Test Enhancement
__tests__/e2e/ci-mac-linux.sh
Added CI commands to publish a layer from https://images.devsapp.cn/bin/supergateway (--compatible-runtime custom.debian12 --layer-name test), remove that layer, and run cd .. to restore directory state.
Component Version Update
publish.yaml
Bumped component fc3 Version from 0.1.170.1.18.
Utility Function Logic
src/utils/index.ts
_downloadFromUrl(url: string) now ensures the returned download path ends with .zip, logs the adjusted path, and verifies the file is a valid ZIP (throws an Error if validation fails).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • rsonghuster

Poem

🐰 I hopped to publish, quick and neat,
I shelled a layer and kept it sweet,
A version nudged, a zip ensured,
No stray files left—everything cured,
Hooray! I’ll nibble a carrot treat.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: layer code support http bug' directly addresses the main change: adding HTTP support for layer code downloads with file validation, as evidenced by the HTTP URL usage in CI tests and ZIP file validation logic in utils.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch layer-publish

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/utils/index.ts (1)

331-344: ⚠️ Potential issue | 🔴 Critical

Returned path may not exist after forced .zip suffix.

On Line [344], the function mutates the returned path string but does not ensure the downloaded file is written with that exact name. This can return a non-existent file path.

Proposed fix
-    const parsedPathName = path.parse(urlPath).name;
-    const filename = path.basename(urlPath) || `downloaded_code_${Date.now()}`;
+    const parsed = path.parse(urlPath);
+    const baseName = parsed.name || `downloaded_code_${Date.now()}`;
+    const filename = parsed.ext ? parsed.base : `${baseName}.zip`;
     downloadPath = path.join(tempDir, filename);

     await downloads(url, {
       dest: tempDir,
-      filename: parsedPathName,
+      filename,
       extract: false,
     });

     logger.debug(`Downloaded file to: ${downloadPath}`);

-    // 返回下载文件路径,由主流程决定是否需要压缩
-    return downloadPath.endsWith('.zip') ? downloadPath : `${downloadPath}.zip`;
+    // 返回真实下载文件路径
+    return downloadPath;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/index.ts` around lines 331 - 344, The code returns downloadPath
with a forced .zip suffix which may not match the actual downloaded file name;
update the download flow so the saved file and returned path always match:
compute the desired saved filename (use parsedPathName or filename plus desired
extension), pass that exact filename/path into downloads (or save into
downloadPath directly) and, if needed, after downloads finishes rename/move the
saved file to downloadPath (or create a zip at downloadPath) before returning;
adjust references to parsedPathName, filename, downloadPath and the downloads
call so the returned path points to an existing file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@__tests__/e2e/ci-mac-linux.sh`:
- Around line 160-162: Replace the hardcoded layer name and add non-interactive
removal: generate a unique layer name (e.g., using timestamp or CI JOB_ID)
instead of the literal `--layer-name test` when calling `s layer publish` and
use that same generated name for `s layer remove`; also add the auto-confirm
flag `-y` to the `s layer remove` invocation so the CI won't wait for
interactive confirmation. Ensure the generated name is stored in a variable and
referenced in both `s layer publish` and `s layer remove -y`.

---

Outside diff comments:
In `@src/utils/index.ts`:
- Around line 331-344: The code returns downloadPath with a forced .zip suffix
which may not match the actual downloaded file name; update the download flow so
the saved file and returned path always match: compute the desired saved
filename (use parsedPathName or filename plus desired extension), pass that
exact filename/path into downloads (or save into downloadPath directly) and, if
needed, after downloads finishes rename/move the saved file to downloadPath (or
create a zip at downloadPath) before returning; adjust references to
parsedPathName, filename, downloadPath and the downloads call so the returned
path points to an existing file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a3c496a4-78b5-412e-a6d0-9ab97a7cf257

📥 Commits

Reviewing files that changed from the base of the PR and between 3fe39c2 and 7c055d2.

📒 Files selected for processing (3)
  • __tests__/e2e/ci-mac-linux.sh
  • publish.yaml
  • src/utils/index.ts

Comment on lines +160 to +162
echo "test layer code support http"
s layer publish --layer-name test --code https://images.devsapp.cn/bin/supergateway --compatible-runtime custom.debian12
s layer remove --layer-name test
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify remove commands that may be interactive
rg -nP --type=sh '\bs\s+layer\s+remove\b' __tests__/e2e/ci-mac-linux.sh

# Verify hard-coded layer names in CI
rg -nP --type=sh '--layer-name\s+test\b' __tests__/e2e/ci-mac-linux.sh

Repository: devsapp/fc3

Length of output: 532


🏁 Script executed:

# Get exact content at lines 160-162
sed -n '160,162p' __tests__/e2e/ci-mac-linux.sh

# Check if RANDSTR is defined in the script
grep -n "RANDSTR" __tests__/e2e/ci-mac-linux.sh

# Look for any layer remove commands with flags for context
grep -n "layer remove" __tests__/e2e/ci-mac-linux.sh

Repository: devsapp/fc3

Length of output: 1249


🏁 Script executed:

# Search for all layer remove commands across the codebase
rg "s layer remove" -A 1 -B 1

# Check if -y flag is used with layer remove elsewhere
rg "layer remove.*-y" --type=sh

Repository: devsapp/fc3

Length of output: 875


CI layer commands use hardcoded name and lack auto-confirmation flag.

Line 161 uses static --layer-name test, risking collisions with concurrent runs or leftovers. Line 162 omits -y, which can cause CI to hang waiting for interactive confirmation. Other test suites (command-api/run, run-windows.ps1) use dynamic layer names and include -y with layer remove.

Proposed fix
 echo "test layer code support http"
-s layer publish --layer-name test --code https://images.devsapp.cn/bin/supergateway --compatible-runtime custom.debian12
-s layer remove --layer-name test
+layer_name="test-${RANDSTR}-${RANDOM}"
+s layer publish --layer-name "${layer_name}" --code https://images.devsapp.cn/bin/supergateway --compatible-runtime custom.debian12
+s layer remove --layer-name "${layer_name}" -y
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/e2e/ci-mac-linux.sh` around lines 160 - 162, Replace the hardcoded
layer name and add non-interactive removal: generate a unique layer name (e.g.,
using timestamp or CI JOB_ID) instead of the literal `--layer-name test` when
calling `s layer publish` and use that same generated name for `s layer remove`;
also add the auto-confirm flag `-y` to the `s layer remove` invocation so the CI
won't wait for interactive confirmation. Ensure the generated name is stored in
a variable and referenced in both `s layer publish` and `s layer remove -y`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant