Skip to content

fix(tools): scripts that moved out of www/ still resolve their output from it - #525

Merged
oddharsh merged 1 commit into
mainfrom
claude/stale-files-code-cleanup-215deb
Aug 24, 2026
Merged

oddharsh merged 1 commit into
mainfrom
claude/stale-files-code-cleanup-215deb

Conversation

@oddharsh

Copy link
Copy Markdown
Owner

A stale-code passthrough. What it found is that most of the stale LoC here is not dead, it is broken: code left pointing at directories that three renames moved out from under it. Whole-file deadness is nearly zero (one unused function in ~23k lines of Worker code, no commented-out blocks, no unused deps, no orphaned /i tiers, dictionaries at their KEEP=3 retention).

The photo pipeline has been writing to directories that do not exist

Eight sites across six scripts find their output with $SCRIPT_DIR/... That was the served tree when these lived in www/scripts/; it has been tools/ since #452 and #453.

site resolved to should be
extract-photo-metadata.sh OUT, META_DIR, --root tools/images/… public/images/…
hash-thumbnails.sh SRC_DIR, OUT_DIR tools/images, tools/i public/images, public/i
hash-thumbnails.sh fingerprints call tools/scripts/… tools/photos/…
add-car-photo.sh DEST tools/cars public/cars
gen-encoding-{grids,samples}.sh DEST tools/garage/enc public/garage/enc
add-photos.sh histogram --root <repo>/www <repo>/public

Every one was correct when written. A rename sweep greps for the old string, and there is no old string here, only a relative expression whose meaning is a function of where the file sits.

Two things kept it silent. zenc histogram prints cannot read …/images/hashes.json and exits 0, and both callers pipe it to tail -1, so the bake skips without failing. And add-photos.sh / reencode-thumbnails.sh resolve through $PROJECT_DIR rather than $SCRIPT_DIR/.., so those two were updated by the split, which left the pipeline looking half-migrated and plausibly fine. No photo has been added since the move, so nobody ran into it.

Measured: --root <repo>/www answers cannot read; --root <repo>/public reads all 158 stems.

The build has printed 14 warnings a run since 2026-08-18

The same rename left build.mjs's taste exemption anchored on /^www\/(garage|lwe)\//, matching nothing, so the /garage and /lwe demo pages it exists to exempt lost the exemption. Every one of the 14 warnings was on a demo page. A warn block nobody can clear is how a warn block gets ignored.

Re-anchored on the SERVED_SOURCES roots. Controls both directions, since this change re-enables a continue: an injected @font-face url() on /garage/tooltips still hard-fails the deploy, and a 99px radius on that same page is silent again. The two hard rules run before the exemption, so nothing lost enforcement.

A guard whose one exemption hid the only offender

lens-seed.mjs still spawned execFileSync("pnpm", ["exec", "wrangler", …]). pnpm is gone from this repo (no lockfile, no workspace file, packageManager is bun) and refuses outright on a bun tree, so every seed run has been dying.

contract-the-typescript-quarantine bans exactly this. It carried lens-seed.mjs as its single RECORDED exception, justified as "drives a package script as the subject of the browser recording rather than using a manager to reach another binary". That described no code in the file. The single genuine offender was the single exempted file, and the suite reported green.

The spawn goes through wranglerCommand() now and the allowlist is deleted. Control: re-adding a pnpm spawn fails the test by name, which it could not do before.

Dead or wrong, removed

  • explorerChrome(), exported and called by nothing anywhere including its own file
  • an isCallable doc comment orphaned fifteen lines above its function
  • build.mjs told you to run node public/scripts/build-histogram-index.mjs, which is not a path
  • check-wrangler.mjs told you to run pnpm install. Its transitive-copy scan reads node_modules/.pnpm, so it reports 0 forever on a bun tree; logic unchanged, blind spot now named at the code
  • MAINTENANCE.md documented zenc histogram --root www and two .ts modules as .js

CLAUDE.md counts, re-derived from the tree

36→37 documents, 46→49 test files, 117→147 relative specifiers, 474→632 hashed tiers (the 200px tier from #441 was never written down), 2645/48→2921/50 link refs.

Gotcha 16 named contract-tests.mjs under node --test. Both runners measured: the rule holds and both symptoms changed, so the documented error string finds nothing and the blast radius is one file rather than the whole run.

runner error blast radius
node --test ERR_UNSUPPORTED_ESM_URL_SCHEME the whole run, 0 tests
bun test Cannot find package 'cloudflare:workers' that FILE, 1 pass 1 fail

Gotcha 39 records the $SCRIPT_DIR/.. class so the next rename has something to check against.

Verification

353 tests, typecheck, lint, build (0 warnings), pages:check, photos:check, and the 142-route oracle all green, re-run after rebasing onto the tools/lib TypeScript migration (#522).

Left alone, deliberately

  • tools/verify-baseline.aadhar.sh.json (480 lines) is written by verify-routes.mjs and read by nothing. Clearest stale file in the repo, but a diff on it after a prod run does show route drift, so deleting it may throw away a real if manual use. Delete, or wire it into an actual comparison?
  • ENFORCE_PAGE_HASHES has been stuck true since 2026-08-16, leaving a dead report-only branch plus CSP_TAIL_REPORTABLE and dead arms in gen-md-twins.mjs. Roughly 50 lines, and also the one-line rollback if a page breaks under enforcement.
  • zenc histogram --check reports drift on 158/158 photos against the corrected root, while photos:check passes, so the committed artifacts are self-consistent. Reads like a zenjpeg decoder bump rather than data loss. Deliberately not re-baked, since that would rewrite every photo's histograms from a possibly-different decoder. Worth its own look.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
aadhar-sh dd18360 Aug 24 2026, 01:07 AM

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Wire-size diff vs merge base

1682f73 → 82e11a6

Brotli q11, the quality the edge serves. Every number here is deterministic:
an unchanged file produces no row. Advisory — this check fails on nothing.

Client assets

No change. 22 files, 77.74 KiB Brotli total.

Pages

No change. 50 files, 531.29 KiB Brotli total.

Worker bundle

No change. 237.91 KiB gzip.

Dictionary deltas (pd/)

No change. 146 deltas, 492.24 KiB total.

… from it

Eight sites across six photo and asset scripts find their output with
`$SCRIPT_DIR/..`. That was the served tree when these lived in www/scripts/;
it has been tools/ since #452 and #453, so extract-photo-metadata.sh was
writing tools/images/metadata.json, hash-thumbnails.sh was hashing into
tools/i/, and add-car-photo.sh was aiming at tools/cars. add-photos.sh passed
`--root "$PROJECT_DIR/www"`, and www/ stopped existing on 2026-08-18.

A rename sweep greps for the old string, and there is no old string here, only
a relative expression whose meaning is a function of where the file sits. Two
things then kept it silent: `zenc histogram` prints "cannot read" and exits 0,
and both callers pipe it to `tail -1`, so the bake skips without failing. And
the two scripts resolving through $PROJECT_DIR were correctly updated by the
split, which left the pipeline looking half-migrated rather than broken. No
photo has been added since the move, so nobody ran into any of it.

The same rename left build.mjs's taste exemption anchored on /^www\/(garage|
lwe)\//, matching nothing, so the demo pages it exists to exempt lost the
exemption and the build printed 14 warnings on every run since 2026-08-18. A
warn block nobody can clear is how a warn block gets ignored. Re-anchored on
the SERVED_SOURCES roots. Controls both ways: an injected @font-face url() on
a garage page still hard-fails, and a 99px radius there is silent again.

lens-seed.mjs still spawned execFileSync("pnpm", ["exec", "wrangler", ...]),
which refuses outright on a bun tree. The contract test that bans package
manager spawns carried lens-seed.mjs as its one RECORDED exception, justified
as driving a package script rather than using a manager to reach another
binary. That described no code in the file. So the single genuine offender was
the single exempted file and the suite reported green. The spawn goes through
wranglerCommand() now and the allowlist is gone; a control confirms the guard
catches what it used to exempt.

Also dead or wrong, removed or corrected:

- explorerChrome(), exported and called by nothing anywhere, including its own
  file
- an isCallable doc comment orphaned fifteen lines above its function
- build.mjs told you to run node public/scripts/build-histogram-index.mjs,
  which is not a path
- check-wrangler.mjs told you to run `pnpm install`. Its transitive-copy scan
  reads node_modules/.pnpm and so reports 0 forever on a bun tree; the logic is
  unchanged and the blind spot is now named at the code
- MAINTENANCE.md documented `zenc histogram --root www` and two .ts modules as
  .js

CLAUDE.md counts re-derived from the tree: 36 to 37 documents, 46 to 49 test
files, 117 to 147 relative specifiers, 474 to 632 hashed tiers (the 200px tier
from #441 was never written down), 2645/48 to 2921/50 link refs. Gotcha 16
named contract-tests.mjs under `node --test`; both runners were measured, and
the rule holds while both of its symptoms changed, so the documented error
string now finds nothing and the blast radius is one file rather than the run.
Gotcha 39 records the $SCRIPT_DIR/.. class so the next rename has something to
check against.

353 tests, typecheck, lint, build, pages, photos and the 142-route oracle all
green.
@oddharsh
oddharsh force-pushed the claude/stale-files-code-cleanup-215deb branch from 92e3f13 to dd18360 Compare August 24, 2026 01:06
oddharsh added a commit that referenced this pull request Aug 24, 2026
…uarded

ENFORCE_PAGE_HASHES was pinned true on 2026-08-16 and nothing has flipped it in
either direction since, so its false arm has been dead code for a week. It was
not one line: it cost a second header name, a second tail constant, a `tail`
parameter threaded through both policy builders to feed that constant, an
entries loop in withSecurityHeaders whose only job was carrying a second header
past a bail, and two branches apiece in the contract test and the twin-fact
tripwire.

The emitted policy is byte-identical, checked both ways. CSP_TAIL now holds the
string CSP_TAIL_REPORTABLE plus "; upgrade-insecure-requests" used to compose,
and a build of each side produces the same _headers line.

cspHeadersFor returns exactly ONE header now. The contract test counts the keys
rather than probing one name, since a twin under any other spelling is the same
regression, and the upgrade-insecure-requests assertion inverts with the change:
it used to check the twin OMITTED the directive, and with one policy left the
only way to get it wrong is to lose it, so it now checks presence on both arms.

gen-md-twins no longer reads the flag. It reads the header set cspHeadersFor
actually emits, which is the better check for the reason the flag era proved:
a flag states an intention, and #249's bug was the enforcing half never being
applied to a single document while the flag said it was. /security claims
'unsafe-inline' left script-src, and that claim goes false the moment a
report-only twin returns, so the deploy fails until one of the two is put right.

Controls, both run: reintroducing a report-only twin fails the contract test by
name (it reports the two keys it found) and fails the twin-fact tripwire by name.
Reverting makes both green again.

The rollout story stays. What the DevTools sweep found on /garage/horizon, and
why the enforcing half had never been applied, are gotcha 17 in CLAUDE.md, which
is where it belongs now that the mechanism is gone. Rolling back is `git revert`
rather than a flag, and `bun run csp:sweep` is the signal that would call for
one; its header says so instead of describing a flip that already happened.

353 tests, typecheck, lint, build, pages, photos and the 142-route oracle green.
The build's taste warnings on this branch are the ones #525 fixes, not new.
@oddharsh
oddharsh merged commit c565152 into main Aug 24, 2026
6 checks passed
@oddharsh
oddharsh deleted the claude/stale-files-code-cleanup-215deb branch August 24, 2026 01:08
oddharsh added a commit that referenced this pull request Aug 24, 2026
…uarded

ENFORCE_PAGE_HASHES was pinned true on 2026-08-16 and nothing has flipped it in
either direction since, so its false arm has been dead code for a week. It was
not one line: it cost a second header name, a second tail constant, a `tail`
parameter threaded through both policy builders to feed that constant, an
entries loop in withSecurityHeaders whose only job was carrying a second header
past a bail, and two branches apiece in the contract test and the twin-fact
tripwire.

The emitted policy is byte-identical, checked both ways. CSP_TAIL now holds the
string CSP_TAIL_REPORTABLE plus "; upgrade-insecure-requests" used to compose,
and a build of each side produces the same _headers line.

cspHeadersFor returns exactly ONE header now. The contract test counts the keys
rather than probing one name, since a twin under any other spelling is the same
regression, and the upgrade-insecure-requests assertion inverts with the change:
it used to check the twin OMITTED the directive, and with one policy left the
only way to get it wrong is to lose it, so it now checks presence on both arms.

gen-md-twins no longer reads the flag. It reads the header set cspHeadersFor
actually emits, which is the better check for the reason the flag era proved:
a flag states an intention, and #249's bug was the enforcing half never being
applied to a single document while the flag said it was. /security claims
'unsafe-inline' left script-src, and that claim goes false the moment a
report-only twin returns, so the deploy fails until one of the two is put right.

Controls, both run: reintroducing a report-only twin fails the contract test by
name (it reports the two keys it found) and fails the twin-fact tripwire by name.
Reverting makes both green again.

The rollout story stays. What the DevTools sweep found on /garage/horizon, and
why the enforcing half had never been applied, are gotcha 17 in CLAUDE.md, which
is where it belongs now that the mechanism is gone. Rolling back is `git revert`
rather than a flag, and `bun run csp:sweep` is the signal that would call for
one; its header says so instead of describing a flip that already happened.

353 tests, typecheck, lint, build, pages, photos and the 142-route oracle green.
The build's taste warnings on this branch are the ones #525 fixes, not new.
oddharsh added a commit that referenced this pull request Aug 24, 2026
…uarded (#527)

ENFORCE_PAGE_HASHES was pinned true on 2026-08-16 and nothing has flipped it in
either direction since, so its false arm has been dead code for a week. It was
not one line: it cost a second header name, a second tail constant, a `tail`
parameter threaded through both policy builders to feed that constant, an
entries loop in withSecurityHeaders whose only job was carrying a second header
past a bail, and two branches apiece in the contract test and the twin-fact
tripwire.

The emitted policy is byte-identical, checked both ways. CSP_TAIL now holds the
string CSP_TAIL_REPORTABLE plus "; upgrade-insecure-requests" used to compose,
and a build of each side produces the same _headers line.

cspHeadersFor returns exactly ONE header now. The contract test counts the keys
rather than probing one name, since a twin under any other spelling is the same
regression, and the upgrade-insecure-requests assertion inverts with the change:
it used to check the twin OMITTED the directive, and with one policy left the
only way to get it wrong is to lose it, so it now checks presence on both arms.

gen-md-twins no longer reads the flag. It reads the header set cspHeadersFor
actually emits, which is the better check for the reason the flag era proved:
a flag states an intention, and #249's bug was the enforcing half never being
applied to a single document while the flag said it was. /security claims
'unsafe-inline' left script-src, and that claim goes false the moment a
report-only twin returns, so the deploy fails until one of the two is put right.

Controls, both run: reintroducing a report-only twin fails the contract test by
name (it reports the two keys it found) and fails the twin-fact tripwire by name.
Reverting makes both green again.

The rollout story stays. What the DevTools sweep found on /garage/horizon, and
why the enforcing half had never been applied, are gotcha 17 in CLAUDE.md, which
is where it belongs now that the mechanism is gone. Rolling back is `git revert`
rather than a flag, and `bun run csp:sweep` is the signal that would call for
one; its header says so instead of describing a flip that already happened.

353 tests, typecheck, lint, build, pages, photos and the 142-route oracle green.
The build's taste warnings on this branch are the ones #525 fixes, not new.

Co-authored-by: Aadharsh Pannirselvam <19518661+oddharsh@users.noreply.github.com>
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.

1 participant