Skip to content

Conversation

@mozhou52
Copy link
Collaborator

@mozhou52 mozhou52 commented Jan 28, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Blocked accidental deletion of OSS and NAS root storage mount points; attempts to remove these roots are now prevented with guidance to use the respective OSS/NAS console.
  • Tests
    • Updated unit tests to reflect NAS mount configuration handling and ensure removal behavior is validated.

✏️ Tip: You can customize this high-level summary in your review settings.

@mozhou52 mozhou52 requested a review from rsonghuster January 28, 2026 07:47
@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

Adds pre-delete validations in removeModel to prevent deleting OSS bucket roots or NAS root mounts by inspecting the first OSS mount's bucketPath and deriving NAS path from nasMountPoints[0].serverAddr; throws instructive errors before constructing the removal request.

Changes

Cohort / File(s) Summary
Model Removal Guards
src/subCommands/model/model.ts
Inserted guard checks in removeModel to: detect OSS mounts with empty or / bucketPath and detect NAS mounts where derived nasPath is /; throw errors directing users to use OSS/NAS consoles instead of proceeding with deletion.
Tests — NAS serverAddr added
__tests__/ut/commands/modelService_test.ts
Updated three tests to include serverAddr in nasMountPoints entries (e.g., { mountDir: '/mnt/test', serverAddr: 'xxxxx:/test' }) to align with NAS path extraction in the removal logic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • rsonghuster

Poem

🐰 I sniffed the mounts both near and far,
Found roots that sparkle like a star,
If bucket or NAS stands at /'s gate,
I pause and say, "Use the console, mate!"
A tiny hop to keep your data straight. 🥕

🚥 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: Remove root directory error' directly relates to the main change: adding guards to prevent deletion of OSS and NAS root directories, which is the primary modification in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings

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: 2

🤖 Fix all issues with AI agents
In `@src/subCommands/model/model.ts`:
- Around line 112-120: The OSS root check incorrectly treats any non-empty
bucketPath as root because the condition uses
(processedOssMountPoints[0].bucketPath || processedOssMountPoints[0].bucketPath
=== '/'); update the guard around storage === 'oss' to explicitly detect
undefined/empty or the literal root by checking processedOssMountPoints[0]
exists and then (processedOssMountPoints[0].bucketPath === undefined ||
processedOssMountPoints[0].bucketPath === '' ||
processedOssMountPoints[0].bucketPath === '/'); throw the Error only in that
case so valid non-root bucketPath values (e.g., '/models/mymodel') are allowed
to proceed.
- Around line 110-111: NAS_ROOT_REGEX currently only matches China regions
because it hardcodes "cn-[a-z]+"; update the regex (symbol NAS_ROOT_REGEX in
model.ts) to accept any region token so non‑China domains (e.g., ap-southeast-1,
us-west-1) are matched. Replace the region part with a more general character
class such as [a-z0-9-]+ (for example change \.cn-[a-z]+\. to \.[a-z0-9-]+\.) so
the full pattern becomes something like
/^[\w-]+\.[a-z0-9-]+\.nas\.aliyuncs\.com:\/$/ and retain the rest of the pattern
and anchors.


const processedOssMountPoints = extractOssMountDir(ossMountPoints);

const NAS_ROOT_REGEX = /^[\w-]+\.((?:cn|ap|us|eu|me|sa)-[a-z]+-[0-9])\.nas\.aliyuncs\.com:\/$/;
Copy link
Contributor

Choose a reason for hiding this comment

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

你这个nas 挂载点的校验是不是太狠了,我理解你只需要关注 split by :, arr[1] 不会 / 即可

(!processedOssMountPoints[0].bucketPath || processedOssMountPoints[0].bucketPath === '/')
) {
throw new Error(
'The current deleted directory is the OSS root directory. To delete the current model, please go to the OSS console to delete the model.',
Copy link
Contributor

Choose a reason for hiding this comment

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

之前那个 ignore remove 的环境变量似乎没有生效啊

@mozhou52 mozhou52 force-pushed the fileManager-remove branch 3 times, most recently from 3052f59 to 4afbc29 Compare January 29, 2026 05:23
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

🤖 Fix all issues with AI agents
In `@src/subCommands/model/model.ts`:
- Around line 120-123: The code currently accesses nasMountPoints[0].serverAddr
and splits it before checking storage, which can crash for empty or non-NAS
cases; move the parsing of serverAddr (the split and trim that produces nasPath)
inside the branch that only runs when storage === 'nas' and nasMountPoints[0]
exists, first validate nasMountPoints.length>0 and that
nasMountPoints[0].serverAddr is a non-empty string, then split into parts and
ensure parts.length>1 and parts[1] is defined before calling trim(); if
validation fails, handle it gracefully (throw a clear Error or treat as non-NAS)
so functions using nasPath (the nasPath variable) never operate on undefined.

Comment on lines 120 to 123
const nasPath = nasMountPoints[0].serverAddr.split(':')[1];

if (storage === 'nas' && nasMountPoints[0] && nasPath.trim() === '/') {
throw new Error(
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

Guard NAS parsing to avoid crashes for non‑NAS or empty mount points.

nasMountPoints[0].serverAddr is accessed unconditionally, so OSS deletions (or empty NAS configs) can throw before the NAS guard runs. Also split(':')[1] can be undefined (no colon/IPv6), causing .trim() to crash. Move parsing inside the NAS branch and validate the format.

🛠️ Suggested fix
-    const nasPath = nasMountPoints[0].serverAddr.split(':')[1];
-
-    if (storage === 'nas' && nasMountPoints[0] && nasPath.trim() === '/') {
+    if (storage === 'nas' && nasMountPoints[0]?.serverAddr) {
+      const idx = nasMountPoints[0].serverAddr.lastIndexOf(':');
+      const nasPath = idx >= 0 ? nasMountPoints[0].serverAddr.slice(idx + 1) : '';
+      if (nasPath.trim() === '/') {
         throw new Error(
           'The current deleted directory is the NAS root directory. To delete the current model, please go to the NAS console to delete the model.',
         );
-    }
+      }
+    }
🤖 Prompt for AI Agents
In `@src/subCommands/model/model.ts` around lines 120 - 123, The code currently
accesses nasMountPoints[0].serverAddr and splits it before checking storage,
which can crash for empty or non-NAS cases; move the parsing of serverAddr (the
split and trim that produces nasPath) inside the branch that only runs when
storage === 'nas' and nasMountPoints[0] exists, first validate
nasMountPoints.length>0 and that nasMountPoints[0].serverAddr is a non-empty
string, then split into parts and ensure parts.length>1 and parts[1] is defined
before calling trim(); if validation fails, handle it gracefully (throw a clear
Error or treat as non-NAS) so functions using nasPath (the nasPath variable)
never operate on undefined.

@rsonghuster rsonghuster merged commit b0ae8ab into master Jan 29, 2026
6 checks passed
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.

3 participants