idstack icon indicating copy to clipboard operation
idstack copied to clipboard

Atomic writes replace a symlinked manifest, report or learnings file with a regular file

Open savvides opened this issue 3 weeks ago • 0 comments

Found in the documentation audit (the PR that adds docs/cli-reference.md).

CLAUDE.md gives the rule for atomic writes: mkstemp in the directory of os.path.realpath(target), then os.replace onto the real path. Only scripts/idstack-migrate (line 239) follows it. Three tools call os.replace on the path as given, so a symlink becomes a regular file and the link target keeps the old content:

  • scripts/idstack-manifest-merge (line 184)
  • scripts/idstack-report-section (line 271)
  • scripts/idstack-learnings delete (line 112)

Reproduce:

mkdir real .idstack
scripts/idstack-migrate --init real/project.json >/dev/null
ln -s ../real/project.json .idstack/project.json
echo '{"a":1}' > p.json
scripts/idstack-manifest-merge --section context --payload p.json
ls -l .idstack/project.json   # a regular file, not a link

Fix: resolve the target with os.path.realpath before mkstemp and os.replace, as idstack-migrate does. Add a test and a mutation for each tool. docs/cli-reference.md states the current behaviour in three places; update it with the fix.

savvides avatar Nov 12 '26 15:11 savvides