Skip to content

Commit b1a0af2

Browse files
sahrizviclaude
andcommitted
fix(workspace): junk-file names are case-folded, and a worktree's .git file is junk too
- `.ENV` and `.ENV.production` are the same file as `.env` on the case-insensitive file systems Windows and macOS default to, and slipped past a case-sensitive match. - `git worktree add` leaves `.git` as a regular file, which the directory skip did not see. - The update-path conflict test now actually renames: the second publish carries a new name, and the assertions pin that it went out as a PATCH rename rather than a create. Verified: 506 pass across the workspace + plugin suites, typecheck clean. Mutation-checked: dropping the case fold and dropping the `.git` file rule each fail a test. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012Q51zFUmPg1WwtS5CrGJE6
1 parent e807448 commit b1a0af2

2 files changed

Lines changed: 42 additions & 9 deletions

File tree

‎packages/opencode/src/altimate/workspace/skill-publish.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,21 @@ const MAX_BUNDLE_FILES = 200
6666
* did not mean to publish either. */
6767
const NEVER_PUBLISH_DIRS = new Set([".git", "node_modules", "__pycache__"])
6868
function isJunkFile(name: string): boolean {
69+
// Case-folded: Windows and macOS file systems are case-insensitive by
70+
// default, so `.ENV` is the same file as `.env` there and must not slip
71+
// past a case-sensitive match.
72+
const lower = name.toLowerCase()
6973
return (
70-
name === ".DS_Store" ||
71-
name === "Thumbs.db" ||
72-
name === ".env" ||
73-
name.startsWith(".env.") ||
74-
name.endsWith("~") ||
75-
name.endsWith(".swp") ||
76-
name.endsWith(".swo")
74+
// A worktree's `.git` is a regular FILE pointing at the main repository,
75+
// not a directory — so the directory skip alone did not cover it.
76+
lower === ".git" ||
77+
lower === ".ds_store" ||
78+
lower === "thumbs.db" ||
79+
lower === ".env" ||
80+
lower.startsWith(".env.") ||
81+
lower.endsWith("~") ||
82+
lower.endsWith(".swp") ||
83+
lower.endsWith(".swo")
7784
)
7885
}
7986
/** The shared request budget is 15s and covers the upload itself; a legal 10MB

‎packages/opencode/test/altimate/workspace/skill-publish.test.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ describe("the bundle size guard", () => {
418418
// A public skill's bundle is readable tenant-wide, and a secret that
419419
// reaches it cannot be recalled by deleting the local file.
420420
writeFileSync(path.join(skillDir, ".env"), "ALTIMATE_API_KEY=secret")
421+
writeFileSync(path.join(skillDir, ".ENV.production"), "ALTIMATE_API_KEY=secret") // case-insensitive file systems
421422
writeFileSync(path.join(skillDir, ".DS_Store"), "junk")
422423
writeFileSync(path.join(skillDir, "SKILL.md~"), "editor backup")
423424
mkdirSync(path.join(skillDir, ".git"), { recursive: true })
@@ -428,17 +429,42 @@ describe("the bundle size guard", () => {
428429
expect(files.map((f) => f.path)).toEqual(["SKILL.md"])
429430
})
430431

432+
test("a worktree's .git file is junk too, not only a .git directory", async () => {
433+
// `git worktree add` leaves a regular file named `.git` holding
434+
// `gitdir: /path/to/main/.git/worktrees/...`. The directory skip does not
435+
// see it.
436+
const wt = path.join(project, "skills", "wt")
437+
mkdirSync(wt, { recursive: true })
438+
writeFileSync(path.join(wt, "SKILL.md"), "---\nname: wt\n---\n")
439+
writeFileSync(path.join(wt, ".git"), "gitdir: /somewhere/.git/worktrees/wt\n")
440+
441+
const files = await collectBundle(wt)
442+
443+
expect(files.map((f) => f.path)).toEqual(["SKILL.md"])
444+
})
445+
431446
test("a rename that collides on the update path is a typed conflict", async () => {
432447
// The create path mapped 409 to SkillNameConflictError; the update path did
433448
// not, so a PATCH that renames onto an existing name surfaced the raw
434449
// server envelope — the exact thing this module's typed errors exist to
435-
// prevent.
450+
// prevent. The second publish carries a NEW name, so it is a rename.
436451
await publish() // records the id, so the next call takes the PATCH branch
437452
statuses.PATCH = 409
453+
conflictDetail = "You already have a skill named 'release'"
454+
requests = []
438455

439-
const err = await publish().catch((e) => e)
456+
const err = await publishSkill({
457+
projectDirectory: project,
458+
skillDirectory: skillDir,
459+
name: "release",
460+
description: "d",
461+
}).catch((e) => e)
440462

441463
expect(err).toBeInstanceOf(SkillNameConflictError)
464+
expect((err as { skillName: string }).skillName).toBe("release")
465+
// It was a rename on the PATCH, not a create under the new name.
466+
expect(requests.find((r) => r.method === "PATCH")?.body.name).toBe("release")
467+
expect(requests.filter((r) => r.method === "POST")).toHaveLength(0)
442468
})
443469
})
444470

0 commit comments

Comments
 (0)