Skip to content

fix(skills): mktemp templates with a non-trailing X suffix break on macOS - #2343

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-2157-mktemp-macos
Aug 8, 2026
Merged

carlos-alm merged 2 commits into
mainfrom
fix/issue-2157-mktemp-macos

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

Closes #2157

BSD mktemp (macOS) only randomizes a trailing run of Xs — a suffix directly after it (mktemp "tmp.XXXXXXXXXX.ext") returns the template literally instead of creating a unique path:

$ mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX.txt"
/var/folders/.../T//tmp.XXXXXXXXXX.txt      # not randomized
$ mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX.json"   # second run, file now exists
mktemp: mkstemp failed on /var/folders/.../T//tmp.XXXXXXXXXX.json: File exists

.claude/skills/create-skill/SKILL.md mandated exactly this broken pattern in Patterns 2, 3, 13, 14 and the Phase 5 idempotency checklist — every skill generated by /create-skill following it inherited a fixed, non-unique temp path on macOS:

  • Concurrent sessions collide on the same literal path (a real risk given this repo's parallel-worktree workflow).
  • Re-runs fail outright with mkstemp failed ... File exists once the literal file is left behind.
  • Failures are silent until the second run, so they look like flakes.

lint-skill.sh and smoke-test-skill.sh (the skill's own linting/smoke-test tooling) reproduced the identical broken pattern in their own mktemp calls.

Fix

  • Rewrote every mandated mktemp example in SKILL.md (Patterns 2, 3, 13, 14, Phase 5 checklist) to use a trailing-X mktemp -d directory template, placing the extensioned file inside that directory when an extension is required (matches the issue's own suggested fix).
  • Fixed lint-skill.sh's and smoke-test-skill.sh's own mktemp calls — neither actually needed an extension on the temp file they create, so both now use a bare trailing-X template.
  • Added a new lint-skill.sh check that flags any mktemp template whose X run is not trailing, so a future skill reintroducing this pattern is caught automatically instead of silently shipping.

Test plan

  • New tests/unit/lint-skill-mktemp-trailing-x.test.ts: the new lint check fires on the exact reported bug pattern and a generic non-extension suffix, does not false-positive on the recommended trailing-X / mktemp -d forms, and confirms SKILL.md itself is clean.
  • Ran lint-skill.sh and smoke-test-skill.sh against the updated SKILL.md directly — 0 errors/warnings, all 10 bash blocks pass bash -n.
  • Full npm test suite passes (4615 tests, 288 files).
  • npx tsc --noEmit and npm run lint clean.

…acOS (#2157)

BSD mktemp (macOS) only randomizes a TRAILING run of X's — a suffix
directly after it (mktemp "tmp.XXXXXXXXXX.ext") returns the template
literally instead of creating a unique path. create-skill/SKILL.md
mandated exactly this broken pattern in Patterns 2/3/13/14 and the
Phase 5 checklist, so every generated skill following it got a fixed,
non-unique temp path on macOS: concurrent sessions collided on the
same literal file, and re-runs failed with "mkstemp failed ... File
exists". lint-skill.sh and smoke-test-skill.sh reproduced the same
broken pattern in their own mktemp calls.

Fix: rewrite every mandated example to mktemp -d a trailing-X
directory template, placing the extensioned file inside it when an
extension is required. Add a lint-skill.sh check that flags any
mktemp template whose X run is not trailing, so a future skill
reintroducing this is caught automatically instead of silently
shipping.

docs check acknowledged.
@greptile-apps

greptile-apps Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR makes generated skill temp-path guidance and validation portable to BSD mktemp on macOS.

  • Replaces extension-suffixed mktemp templates with trailing-X templates or temporary directories.
  • Updates the lint and smoke-test scripts to use unique portable paths.
  • Adds lint detection and regression coverage for non-trailing X templates.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
.claude/skills/create-skill/SKILL.md Updates mandatory skill-authoring patterns and examples to use portable trailing-X mktemp templates.
.claude/skills/create-skill/scripts/lint-skill.sh Makes the linter's temporary file portable and adds detection for non-trailing X runs.
.claude/skills/create-skill/scripts/smoke-test-skill.sh Removes the nonportable suffix from the smoke test's temporary-file template.
tests/unit/lint-skill-mktemp-trailing-x.test.ts Adds regression coverage for accepted and rejected mktemp template forms.

Reviews (2): Last reviewed commit: "fix(test): resolve a real bash 4+ for li..." | Re-trigger Greptile

Comment on lines +56 to +57
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'lint-skill-mktemp-'));
const skillPath = path.join(dir, 'SKILL.md');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Fixture Fails Unrelated Name Check

runLint writes SKILL.md under a randomly named directory while its frontmatter declares name: lint-test-skill, so the linter reports a name mismatch and exits non-zero. Because the negative cases inspect only stdout and ignore status, they pass despite this unrelated error and therefore do not establish that the recommended mktemp forms pass lint cleanly.

Fix in Claude Code

…ly ran (#2157 CI)

Two bugs in the new regression test:

1. lint-skill.sh requires bash 4+; macOS ships bash 3.2 as the `bash`
   on PATH (including GitHub Actions' macos-latest runner), so
   execFileSync('bash', ...) invoked a bash that rejects the script
   outright. Resolve a real bash 4+ explicitly (checking common
   Homebrew install paths) and skip the suite if none is found, rather
   than assuming plain "bash" is adequate.

2. The "does not flag ..." assertions used stdout.not.toContain(...),
   which passes vacuously on an EMPTY stdout — exactly what happens
   when the script fails to even start. This is why only the "flags
   ..." tests (which assert toContain, not not.toContain) surfaced the
   bash-version failure in CI; the others silently "passed" for the
   wrong reason. Every case now also asserts the script actually
   reached its own summary line.

docs check acknowledged.
@carlos-alm
carlos-alm merged commit 63197d7 into main Aug 8, 2026
23 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2157-mktemp-macos branch August 8, 2026 06:39
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-skill: mandated mktemp template is broken on macOS (BSD mktemp ignores non-trailing X's)

1 participant