Skip to content

Make tsCodegenSampleCheck actually able to fail - #24

Merged
kubukoz merged 1 commit into
mainfrom
worktree-fix-22-codegen-check
Sep 2, 2026
Merged

Make tsCodegenSampleCheck actually able to fail#24
kubukoz merged 1 commit into
mainfrom
worktree-fix-22-codegen-check

Conversation

@kubukoz

@kubukoz kubukoz commented Sep 2, 2026

Copy link
Copy Markdown
Member

tsCodegenSampleCheck is the CI gate meant to fail when typecheck/src/generated.ts is out of date. It could never fail: before was read in the task body, but sbt evaluates the sampleCodegenRun.value dependency before any of the body runs — so codegen had already rewritten the file by the time before was read, and before == after always held. Worse, running the check destroyed the stale content instead of reporting it, leaving git status clean.

Fix

Parameterise the codegen run on its output path so the check generates into a temp file and compares, leaving the committed sample untouched:

def sampleCodegenRunTo(out: File) = Def.taskDyn { ... }

tsCodegenSampleCheck := Def.taskDyn {
  val out = tsCodegenSampleFile.value
  val tmp = IO.createTemporaryDirectory / "generated.ts"
  sampleCodegenRunTo(tmp).map { _ =>
    if (!out.exists || IO.read(out) != IO.read(tmp)) sys.error(...)
  }
}.value

tsCodegenSample keeps writing to tsCodegenSampleFile. The now-unused sampleCodegenRun key is removed.

Verification

Reproduced by deleting one real export from the committed sample:

before after
stale sample [success] [error] … is out of date — run sbt tsCodegenSample and commit the result
git status after check clean (overwritten) still M (untouched)

Also confirmed the check passes on an up-to-date sample, and that sbt tsCodegenSample regenerates byte-identically to what is committed — so the sample on main is genuinely current.

Note

sbt cannot load this build inside a git worktree at all: sbt-git's bundled JGit throws NoWorkTreeException: Bare Repository has neither a working tree, nor an index on the .git file worktrees use. Pre-existing and unrelated to this change (a dependencyOverrides JGit bump does not help — sbt-git resolves it on the meta-build classpath). Verification was therefore done against a plain clone. Possibly worth its own issue.

Fixes #22

🤖 Generated with Claude Code

`tsCodegenSampleCheck` read the "before" content in its task body, but sbt
evaluates the `sampleCodegenRun.value` dependency before any of the body runs.
Codegen had therefore already rewritten the file by the time `before` was read,
so `before == after` always held: the gate was vacuous, and running the check
destroyed the stale content instead of reporting it.

Parameterise the codegen run on its output path (`sampleCodegenRunTo`) so the
check can generate into a temp file and compare, leaving the committed sample
untouched. `tsCodegenSample` keeps writing to `tsCodegenSampleFile`.

Fixes #22

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kubukoz
kubukoz merged commit fc1d1aa into main Sep 2, 2026
10 checks passed
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.

tsCodegenSampleCheck can never fail: it regenerates the file it is checking

1 participant