Skip to content

foundry-build cast --check creates its destination directory #360

Description

@jmchilton

Posted by Claude (AI assistant) on behalf of @jmchilton — not authored by them personally.

foundry-build cast <mold> --check is a read-only drift gate, but it creates the bundle directory as a side effect. On a Mold that has never been cast, this leaves an empty casts/claude/skills/<mold>/ behind.

Cause

packages/build-cli/src/commands/cast-mold.ts:1266mkdirSync(bundleRoot, { recursive: true }) runs unconditionally in runCastMoldCommand, before anything branches on args.check.

Reproduction

$ rm -rf casts/claude/skills/validate-cwl
$ test -d casts/claude/skills/validate-cwl && echo YES || echo NO
NO
$ npx tsx packages/build-cli/src/bin/foundry-build.ts cast --root . validate-cwl --check
drift: SKILL.md — SKILL.md missing
drift: _verify.json — verify manifest missing
check failed: 0 error(s), 2 drift(s)
$ test -d casts/claude/skills/validate-cwl && echo YES || echo NO
YES        # empty

Why it bites

tests/plugin-packaging.test.ts (keeps non-skill artifacts outside the discovered skills directory) enumerates real directories under casts/claude/skills/ and asserts each has a SKILL.md. Git doesn't track empty directories, so these are invisible to git status — the failure looks like it came from nowhere.

Running a repo-wide drift scan is the natural way to answer "what's stale?":

for f in content/molds/*/index.md; do
  m=$(basename $(dirname "$f"))
  npx tsx packages/build-cli/src/bin/foundry-build.ts cast --root . "$m" --check
done

That currently creates one empty dir per uncast Mold (14 at the moment — the CWL and paper Molds, repair-galaxy-draft-topology, paper-to-test-data) and breaks an unrelated test until they're cleaned with find casts/claude/skills -type d -empty -delete.

Suggested fix

Skip the mkdirSync when args.check is set, or defer it to the first actual write. A --check run that finds drift should report it without touching the tree.

Worth a regression test: --check against a never-cast Mold should leave no directory behind.

Context

Found while closing out #322 residue (#359).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions