Skip to content

Commit 5c2064f

Browse files
Kyu-seokclaude
andauthored
Dev-tooling batch: branch servers, walkthrough checks, judge-run (#348) (#349)
* merge-ticket: document --checks-and-push <branch> as the flake rerun The header and the usage line now show the mode's integration branch argument, and the header names it as how to rerun the checks and push after a failure that turned out flaky. (#246) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * walkthrough-app-check: wait for the tabs before checking their language The tabs-language check read the Description tab once, so a slow render on a loaded machine failed it with "(null)". It now waits for the tab with waitFor, like the checks around it. (#298) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * dev-branch-servers: status exits 1 when not running (#331) An agent starting the servers in the background had nothing to wait on: status printed "not running" and exited 0. CLAUDE.md names the wait loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * WalkthroughsMatchSamplesTest: breakage cases on fixtures (#332) Every breakage case now breaks a small Walkthrough it builds (samples, moves and map, table, intervals, set, board, graph, span fixtures) instead of a real Walkthrough at a fixed frame or move, so regenerating a tracer can no longer make a case fail for the wrong reason or pass vacuously. Each case asserts the message it is caught with, and aFixtureUnbrokenPasses shows every fixture passes before it is broken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * dev-branch-servers: claim ports under a lock, check listeners (#291) A port was checked free with lsof and bound only minutes later, so two worktrees starting at once could both take it. Each port is now claimed under a mkdir mutex, in a file naming the database and the start's pid, until its stop releases it or the start is gone. start and status also check that each port's listener is this checkout's process (CODEBITE_DEV_BRANCH): a start fails at once when another server answers on its port, and status exits 1 naming who holds it, or which app isn't up yet. restate-problem no longer asks for an lsof by hand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * CODING_STANDARDS: Walkthrough breakage cases build their fixtures (#332) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * WalkthroughsMatchSamplesTest: run labels match the Examples (#340) Run N of a Walkthrough must be labelled "Example N" ("예시 N") exactly when the problem's description has **Example N:** (**예시 N:**), and "Case N" ("케이스 N") otherwise, so a Restatement that turns a sample into an Example can't leave a stale "Case N" behind. Breakage cases on a fixture cover a Case label for an Example and an Example label for a non-Example in both languages. Every Walkthrough on master passes, so none is regenerated. restate-problem names the tracer rerun and add-walkthrough the new check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * dev-branch-servers: migrate, a branch database with no servers (#245) Reading a problem as the branch has it needed start, about six minutes of npm ci and three servers only for Flyway. migrate creates the branch database as start does and runs this checkout's migrations, SQL and Java, through common's migrateDatabase task (a source set of its own, so no jar ships it), in seconds. The BEHIND warnings, restate-problem step 1, triage-labels and CLAUDE.md point at it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: judge-run.sh runs reference solutions on a branch backend Sends each problem's scripts/replay-solutions files to the Run endpoint of the backend dev-branch-servers.sh status prints (or --backend), printing one verdict per Language and NOT JUDGED where no reference solution exists; --former checks a Former Slug resolves. Runs are spaced past the 5 s cooldown and a 429 is waited out; a refused connection says to restart the branch servers and exits 2. (#339) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: restate-problem step 5 runs scripts/judge-run.sh Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * ship-branch: drop the shipped worktree's branch database (#294) ship-branch removed a worktree but left the database, Kafka topics and Redis index dev-branch-servers.sh made for it, and drop can't run from a worktree that is gone. ship-branch now stops that worktree's branch servers and drops their data from inside it before removing it; a failure only warns. A worktree that never ran them has nothing to drop. For those already left behind, dev-branch-servers.sh orphans lists the branch databases whose worktree is gone and drop <name> drops one, from any checkout, refusing any other database or one whose servers run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: trim CLAUDE.md back under its size ceiling after #339 and #245 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: kit --check fails on a recorded commit not on kit main With the kit on the machine, copy-walkthrough-kit.py --check now fails when KIT_VERSION.json's kit commit is not an ancestor of the kit's main, naming both commits and the git merge --ff-only that fixes it. A kit without a main branch is noted, not failed; without the kit (CI) the check is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: ship-branch runs the kit check on the branch before merging CI has no walkthrough kit, so ship-branch.sh runs the branch's own copy-walkthrough-kit.py --check on its tree (git archive) with the kit beside the main checkout, before waiting on CI; a failure merges nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: judge-run exits 0 past a Language NOT JUDGED A Language without a reference solution no longer turns the exit code to 2: most problems have only a Python one. Exit 2 is now only an unreachable backend, an endless 429 or a missing problem; a problem with no judged Language fails (1). The per-problem result is an ordered Outcome, worst wins, in place of re-ranking 'failed'/'missing' strings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: judge-run.sh header points to judge-run.py The header repeated the docstring, spacing included, and would drift from it; it is now a usage line and a pointer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: dev-branch-servers main-checkout exceptions in CLAUDE.md CLAUDE.md said the script refuses the main checkout outright; orphans and drop <name> work there. Reading a problem says migrate runs from a worktree again. Tighter wording elsewhere keeps CLAUDE.md under 25,000 bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(walkthrough): label check cases just outside its exceptions A sample run with a free label (as only an extra run may have) or no label is caught, in either language. A problem with no Korean description had its Korean labels skipped, so any one passed; they now follow the English description's Examples, the same samples. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: break the port mutex only when its start is dead Two waiters that both found the mutex older than a minute could both break it: the second removed the first's new one, and a start holding it longer than a minute lost it too. The mutex is now a symlink naming the holder's pid, broken only when that pid is gone and only under a breaker link, so one waiter breaks it. The two-minute message no longer rests on find -mmin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: dev-branch-servers status reads its ports into locals listeners_ours and summary sourced $state/ports into the global shell, overwriting a caller's port variables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: one helper names the globals of a branch database setup and drop <name> each derived prefix and state from the database name; use_database does it for both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * scripts: name the port listener helpers by what they return port_listeners and port_listener differed by one letter: one prints pids, the other a verdict. They are now listener_pids and listener_verdict. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * merge-ticket: gate also runs the pre-commit hook's repo-wide checks A ticket committed with --no-verify skipped check-doc-references, the kit copy check, shellcheck and the script tests, and the gate ran only Gradle and the frontend, so #348's servers merge pushed a CLAUDE.md over its size ceiling that CI would have failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: CLAUDE.md points at dev-branch-servers.sh's header for subcommands The paragraph had grown into a copy of the script's header, so every subcommand change touched CLAUDE.md, which #348 left 10 bytes under its ceiling. 24,404 bytes now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: Agent Briefs name what they edit, for parallel runs (#348 retro) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d9ab397 commit 5c2064f

25 files changed

Lines changed: 1636 additions & 165 deletions

‎.claude/skills/add-walkthrough/SKILL.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Done when both captures end `✓ no console errors, no sideways scroll, no view
6262
./gradlew :backend:test --tests 'com.codebite.problem.*'
6363
```
6464

65-
`WalkthroughsMatchSamplesTest` checks every file in `walkthroughs/` against the migrated samples (one run per sample, in order, by `sampleInput` and `expected`, each ending on its answer) and the format; `ProblemSlugsTest` that the file names a current Slug. The rest of the package runs too because a new file changes what the endpoint and `hasWalkthrough` answer: #264's first file broke `WalkthroughEndpointTest`. It also fails on a caption of three or more sentences in either language, and on a frame breaking either of step 3's two rules. Wait until no other worktree's Gradle test run is going (`pgrep -f "Gradle Test Executor"` prints nothing): the machine fits one. Don't run it while `dev-branch-servers.sh` is compiling the backend: two Gradle builds in one worktree corrupt the backend build output (`./gradlew :backend:clean` recovers). Done when the package is green.
65+
`WalkthroughsMatchSamplesTest` checks every file in `walkthroughs/` against the migrated samples (one run per sample, in order, by `sampleInput` and `expected`, each ending on its answer) and the format; `ProblemSlugsTest` that the file names a current Slug. The rest of the package runs too because a new file changes what the endpoint and `hasWalkthrough` answer: #264's first file broke `WalkthroughEndpointTest`. It also fails on a run labelled against the description (run N is "Example N"/"예시 N" exactly when the description has `**Example N:**`/`**예시 N:**`, else "Case N"/"케이스 N"), on a caption of three or more sentences in either language, and on a frame breaking either of step 3's two rules. Wait until no other worktree's Gradle test run is going (`pgrep -f "Gradle Test Executor"` prints nothing): the machine fits one. Don't run it while `dev-branch-servers.sh` is compiling the backend: two Gradle builds in one worktree corrupt the backend build output (`./gradlew :backend:clean` recovers). Done when the package is green.
6666

6767
## 5. Check the tab
6868

@@ -81,4 +81,4 @@ Commit `feat(problem): Walkthrough for <slug>` with the tracer and the JSON toge
8181
## When a problem changes
8282

8383
- **A sample Test Case changes** (`correct-test-cases`): `WalkthroughsMatchSamplesTest` goes red; run the tracer against a database with the correction and commit the new JSON with it.
84-
- **The Slug, title or parameter names change**: `.claude/skills/restate-problem/SKILL.md`, step 4, moves or regenerates the Walkthrough.
84+
- **The Slug, title, parameter names or Examples change**: `.claude/skills/restate-problem/SKILL.md`, step 4, moves or regenerates the Walkthrough.

‎.claude/skills/restate-problem/SKILL.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Work in your own worktree, per CLAUDE.md. One Restatement is one commit.
2525

2626
## 1. Read the problem as it stands
2727

28-
1. From your worktree, print the problem as it stands, English and Korean text and every Test Case, hidden ones too: `scripts/problem-text.sh <slug> --all`. It reads the local database (`docker compose -f infra/docker-compose.yml up -d`) and warns when the database hasn't run this checkout's migrations; the main checkout can trail `origin/master` along with its database, and then nothing warns. On that warning, run `scripts/dev-branch-servers.sh start --detach` and rerun with `CODEBITE_DB=<the database it prints>`; or, when no migration newer than the database's version names the slug (`grep -l '<slug>' common/src/main/resources/db/migration/V<version+1 and up>__*.sql` finds nothing), the database's text is current and the output stands. Without a database, the newest migration that sets each column wins: `grep -ln '<slug>' common/src/main/resources/db/migration/ common/src/main/java/db/migration/` (Java migrations redraw some Diagrams) and read from the highest version down, minding Former Slugs in older migrations.
28+
1. From your worktree, print the problem as it stands, English and Korean text and every Test Case, hidden ones too: `scripts/problem-text.sh <slug> --all`. It reads the local database (`docker compose -f infra/docker-compose.yml up -d`) and warns when the database hasn't run this checkout's migrations; the main checkout can trail `origin/master` along with its database, and then nothing warns. On that warning, run `scripts/dev-branch-servers.sh migrate` (it migrates a database of this worktree's in seconds and starts no server) and rerun with `CODEBITE_DB=<the database it prints>`; or, when no migration newer than the database's version names the slug (`grep -l '<slug>' common/src/main/resources/db/migration/V<version+1 and up>__*.sql` finds nothing), the database's text is current and the output stands. Without a database, the newest migration that sets each column wins: `grep -ln '<slug>' common/src/main/resources/db/migration/ common/src/main/java/db/migration/` (Java migrations redraw some Diagrams) and read from the highest version down, minding Former Slugs in older migrations; a migration listed in `KNOWN_NO_OPS` in `MigrationSlugReferencesTest` (backend) matched no row and changed nothing.
2929
2. Read all 4 Drivers and all 4 Starter Code files. Grep the method name in all 4: a Python Starter Code sometimes named it differently (`count_decodings` beside `countDecodings`); `StarterMethodNamesTest` (common) now fails when the four Starter Codes name different methods, so a rename goes into all four together.
3030
3. Compare with production, since a Restatement overwrites any edit made through the admin page: `scripts/prod-text.sh <slug>` prints each language's title, description and constraints. A difference from step 1 is such an edit: carry it into the new statement.
3131
4. Check every constraint against every case and against the return type: each maximum a case reaches (or none does), and whether the answer at the stated bound fits an `int`. The audit found false bounds and 8 problems that overflow at their own maximum.
@@ -81,7 +81,8 @@ Leave out the `problem_former_slugs` insert and the `slug =` line when the Slug
8181
2. When the method or parameter names change: edit all 4 Starter Code files and all 4 Drivers together. The Driver's call (`new Solution().<method>(…)`, `Solution().<method>(…)`) must name the Starter Code's method. Rename the Driver's local variables to match too, so the files read alike. Keep this commit's Driver changes to names: its parsing and printing are what make the Test Cases pass. A Driver that step 5 shows failing a correct solution gets its fix in a commit of its own, `fix(problem): …`, in the same PR.
8282
3. When the Slug changes and the problem has a Guarantee (`backend/src/test/java/com/codebite/problem/guarantee/`), rename it and its `slug()` to match; `ProblemGuaranteesTest` fails on a Guarantee whose Slug no problem has.
8383
4. `git grep -n '<old-slug>\|<oldMethod>'` outside `db/migration/` and update every hit: tests, frontend, docs, and skills that cite the problem as an example (`.claude/skills/`). With `perl -pi` (macOS `sed -E` has no `\b`), keep a whole-word rename of a short name (`n`, `x`) off escapes (`'\n'`, `%n`) and read the Driver diff: a design problem's method rename can hit unrelated calls (`List.get`). Older migrations stay as they are: Flyway runs them before yours, under the old names.
84-
5. When the Slug or title changes: update the CodeBite Name and CodeBite Slug in the problem's row of `docs/PROBLEMS_MAPPING.md` (gitignored: it exists only in the main checkout, `/Users/kyu/Work/CodeBite/docs/`, so that grep misses it and the commit leaves it out). The problem number and LeetCode columns stay.
84+
5. When the Restatement changes which samples are Examples (a sample made an **Example N:**, or one dropped) and the problem has a Walkthrough, rerun its tracer (`.claude/skills/add-walkthrough/SKILL.md`, step 2), whether or not the Slug changes: it labels run N "Example N" or "Case N" by the description, and `WalkthroughsMatchSamplesTest` goes red on a stale label.
85+
6. When the Slug or title changes: update the CodeBite Name and CodeBite Slug in the problem's row of `docs/PROBLEMS_MAPPING.md` (gitignored: it exists only in the main checkout, `/Users/kyu/Work/CodeBite/docs/`, so that grep misses it and the commit leaves it out). The problem number and LeetCode columns stay.
8586

8687
Done when that grep finds nothing outside the migrations and the problem's row in `PROBLEMS_MAPPING.md` shows its new title and Slug.
8788

@@ -90,7 +91,7 @@ Done when that grep finds nothing outside the migrations and the problem's row i
9091
A **text-only Restatement** (the Slug, the method and parameter names, the Drivers and the Starter Code all stay, so only `problems` and `problem_translations` columns change) is verified by step 1 alone: the other steps exercise files it didn't touch. Everything else runs all five.
9192

9293
1. `./gradlew :common:test --tests '*DriverStarterMethodTest' --tests '*ProblemAssetsTest'` and `./gradlew :backend:test --tests 'com.codebite.problem.*'`. Tests such as `DiagramMigrationTest` and `UnpassableTestDataTest` pin a problem's Examples or Diagram literally, so when one goes red on the Restated problem, re-pin it to the new data keeping what it guards. ProblemSlugsTest runs every migration and goes red when a Slug and its asset directories disagree, or a Former Slug clashes with a Slug. `StatementsMatchTestCasesTest`'s exemption sets list the known statement defects; when the Restatement fixes one, remove its slug from the set in the same commit, since the test also goes red on a listed slug that passes. Every run of it writes one report per check under `backend/build/reports/statements/`, each problem's mismatch lines with listed ones marked `[listed]`: read the report of the check that failed for what a listed defect is, before and after the Restatement. MigrationSlugReferencesTest goes red when a `WHERE slug = …` names a slug no problem has when the migration runs (an UPDATE that silently matches nothing), e.g. one another branch Restated first: rebase, and point the migration at the current Slug.
93-
2. Run `scripts/dev-branch-servers.sh start --detach` from your worktree, or `restart` when step 1 started it before your migration existed: it migrates a database of its own and prints that database and the backend and frontend ports; `lsof -i :<port>` should show your worktree's process, since a parallel session can hold the port it reports as up. Read the result back:
94+
2. Run `scripts/dev-branch-servers.sh start --detach` from your worktree, or `restart` when step 1 started it before your migration existed: it migrates a database of its own and prints that database and the backend and frontend ports, and fails when another session's server holds one of them. Read the result back:
9495
```bash
9596
docker exec codebite-postgres psql -U codebite -d <its database> -c "
9697
SELECT p.slug, p.title, t.title, f.slug AS former
@@ -99,8 +100,7 @@ A **text-only Restatement** (the Slug, the method and parameter names, the Drive
99100
WHERE p.slug = '<new-slug>'"
100101
```
101102
3. Bring the reference solutions from step 1.6 to the new Starter Code in each Language, `scripts/replay-solutions/<new-slug>.<py|java|js|cpp>`, and judge every case, hidden ones too: `CODEBITE_DB=<its database> scripts/judge-local.sh <new-slug>`. The Driver brings Java's imports (an `import` in the solution is a compile error); C++ brings its own `#include`s and stays C++14, since local clang only warns on C++17 where Judge0's gnu++14 fails, so only step 5.4 catches it; JavaScript tree and list solutions define `TreeNode`/`ListNode` themselves. Run reaches samples only, so this is what catches a Driver that can't read a hidden input.
102-
4. Run those solutions through the Run endpoint, so Java and C++ compile against the renamed Drivers on Judge0 and every sample passes, one Run every 5 s (a sooner one answers 429):
103-
`curl -s -X POST http://127.0.0.1:<backend port>/api/problems/<new-slug>/run -H 'Content-Type: application/json' -d '{"language":"<language>","sourceCode":"…"}'` for each of the 4 Languages.
103+
4. Run those solutions through the Run endpoint, so Java and C++ compile against the renamed Drivers on Judge0 and every sample passes, and check the Former Slug resolves: `scripts/judge-run.sh <new-slug> --former <old-slug>` (drop `--former` when the Slug stays). It finds the branch backend through `scripts/dev-branch-servers.sh status`, spaces the Runs past the 429 cooldown and prints one verdict per Language. Exit 0 means every Language with a reference solution was Accepted (one without is NOT JUDGED and doesn't change it) and the Former Slug resolves; 1, a verdict, an HTTP error or a Former Slug to fix; 2, the servers are down or haven't migrated the problem (`restart`).
104104
5. Open `http://127.0.0.1:<frontend port>/problems/<old-slug>`: the page lands on `/problems/<new-slug>`.
105105

106106
Done when all five are green and `judge-local.sh` says ACCEPTED for all 4 Languages (step 1 green, for a text-only Restatement). Then `scripts/dev-branch-servers.sh stop`.
@@ -111,7 +111,7 @@ A ticket of several problems is one branch, one PR and one commit per problem. W
111111

112112
- **Number the migrations up front**, one per problem in commit order, from one above `origin/master`'s highest (step 3).
113113
- **Check the rule against every case before drafting.** A short script over every problem's cases (`scripts/problem-text.sh <slug> --json`) that brute-forces the rule you are about to state (the tie-break, the modulus, what is counted) catches what reading misses: a sample with three valid answers where the statement said "unique".
114-
- **The branch database runs only the migrations it started with.** Once a commit moves a Slug, `judge-local.sh <new-slug>` finds no Test Cases and `judge-local.sh <old-slug>` no Driver until `scripts/dev-branch-servers.sh restart` migrates it. Start the servers with `start --detach`, `restart` once after the last migration, and run step 5.2 to 5.5 for the whole batch then: a single script can Run every problem in every Language, 5.5 s apart.
114+
- **The branch database runs only the migrations it started with.** Once a commit moves a Slug, `judge-local.sh <new-slug>` finds no Test Cases and `judge-local.sh <old-slug>` no Driver until `scripts/dev-branch-servers.sh restart` migrates it. Start the servers with `start --detach`, `restart` once after the last migration, and run step 5.2 to 5.5 for the whole batch then: `scripts/judge-run.sh <a> --former <old-a> <b> --former <old-b> …` Runs every problem in every Language in one call.
115115
- **Run the tests once per batch.** The pre-commit hook runs every module's full suite on each commit; commit the later problems with `--no-verify` and run step 5.1, then the full suite, at the end. `--no-verify` also skips the commit-msg hook; CI's `scripts/check-commit-subjects.sh` step catches a subject over 72 characters (step 6).
116116
- **A fix found later goes into its problem's commit**: `git commit --fixup=<that commit>`, then `GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash origin/master` (without `-i`, `--autosquash` does nothing). A rebase that moves the base under migrations the branch database already ran makes Flyway refuse the lower versions: `scripts/dev-branch-servers.sh drop` and start again.
117117

0 commit comments

Comments
 (0)