Skip to content

test(generate): kill 8 surviving mutants, gate workflows cancel, fix 2 doc claims - #218

Merged
ZacxDev merged 1 commit into
mainfrom
test/generate-coverage-gaps-and-cancel-confirmation
Aug 6, 2026
Merged

ZacxDev merged 1 commit into
mainfrom
test/generate-coverage-gaps-and-cancel-confirmation

Conversation

@ZacxDev

@ZacxDev ZacxDev commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Closes a set of test-coverage gaps in civitai generate (PRs #210 and #215), adds a confirmation to workflows cancel, and fixes two doc claims that were factually wrong.

No test in this PR touches a live server, and no mutation call was ever issued. Everything runs on httptest + t.TempDir().

Part 1 — two doc corrections (measured)

The blob host. AGENTS.md item 17 named orchestration.civitai.com. The host observed in a real upload reply is orchestration-new.civitai.com. Both match *.civitai.com, so isTrustedDownloadHost attaches the bearer token either way and the credential-free seam is required regardless — the wildcard is the load-bearing fact and the subdomain is incidental. Both items now say that explicitly rather than naming a hostname a server-side rename can invalidate. Item 19(e) already used the generic form (the task brief expected it to be wrong; it wasn't) — it gains the observed host and the same caveat. A code comment in generate.go making the same claim is corrected too.

PayloadHash. The comment claimed the field lets a re-attach tell "the same job" from "a different job that reused the key". Nothing reads it back — the only reader of a written record is recordPendingWorkflowID, which rewrites it. Reworded honestly; the field is kept, because the value is only obtainable at submit time, so recording it is what keeps that future comparison possible.

Part 2 — eight coverage gaps

Each was verified-correct code with a missing or merely-spelled guard. Every named mutant was applied, confirmed to fail with that guard's own message, and reverted.

# Guard Mutant Result
1 confirmGenerate default-deny case "y","yes" → case "n","no" (turns [y/N] into [Y/n]) KILLED
2 pendingPath traversal drop filepath.Base KILLED
3 cost-vs-balance boundary > → >= KILLED
4 401-replay is 401-only status == 401 → status != 200 KILLED
5 degenerate dimensions <= 0 → < 0 KILLED
6 unsupported-format branch neuter the if SURVIVES — by design, see below
7 body-close in generate_image.go + blobs.go delete defer …Close() KILLED (both)
8 req.ContentLength delete the line SURVIVES — by design, see below

Two findings worth calling out:

  • Gap 5 is real, not theoretical. Measured with the Go 1.25 stdlib: jpeg.Encode of a 16x0 image produces 591 bytes that image.DecodeConfig reads back as w=16, h=0, err=nil. png.Encode refuses outright, which is why every fixture is a JPEG. So a zero dimension genuinely reaches GraphImage and then the server, where item 19(d) records it as a hard 400 after the graph is priced.
  • Two non-TTY refusals were pinned only by their wording. With empty stdin, deleting !stdinIsTTY() still aborts (the prompt reads EOF), so the submit counter never discriminated and the mutant was killed only by message assertions — a guard killed by a different guard's error. Piping "y" is the real hazard shape (a CI job answering the prompt instead of passing --yes), and it makes the counter the discriminator. Added for both generate and cancel.

Decisions on items 6 and 8

Item 6 — labelled defensive-only (option b). The branch is genuinely unreachable: only png and jpeg have registered decoders, both are keys of supportedImageFormats, so everything else fails earlier with image.ErrFormat. No test can kill a mutation in unreachable code, and claiming otherwise would be a vacuous guard. Forcing it reachable means registering a third decoder — exactly what gifBytes()'s comment documents as the thing that would silently destroy the real unsupported-format test. So the branch is commented as defensive-only with the reason, and the invariant that makes it unreachable is pinned instead (TestSupportedImageFormats_DecoderRegistrationIsInLockstep): every advertised format must actually decode under its map key, the content-type values are asserted, and a negative control confirms gif still fails via the ErrFormat arm. That test goes red the moment a decoder is added without a map entry — i.e. the moment the branch does become reachable.

Item 8 — kept with an honest comment. http.NewRequestWithContext already sets ContentLength (and GetBody) for a *bytes.Reader, so deleting the line changes nothing today — measured, the mutant survives. Kept because the requirement is the endpoint's, not the reader type's: the orchestrator's signed URL rejects a chunked body, and if the body type is ever swapped for something the stdlib cannot size, that guarantee would vanish with no test able to see it. The comment says plainly that it is belt-and-braces, and the existing Content-Length assertion is re-labelled as pinning the outcome, not our line.

Part 3 — workflows cancel now confirms

It is the only irreversible action in this feature and it destroys a job the user has already paid for, while every other destructive path here gates. Matches the house pattern (confirmSubmit / confirmGenerate):

  • --yes / -y proceeds;
  • an interactive TTY prompts, default no;
  • a non-TTY without --yes refuses — including when "y" is piped, because the claim is "a terminal is attached", not "somebody typed something".

The gate runs before the mutation seam, so a refusal cannot have cancelled anything. The existing honest help text is unchanged: cancelling still does not refund. README updated.

Verification

  • Full suite COUNTED (not an exit code): 2076 RUN / 2072 PASS / 0 FAIL / 4 SKIP, 0 panic: test timed out. The 4 skips are the four by-design ones (TestScanDirFromEnv, TestScaffoldPinsSatisfyPublished, TestSubmissionsCapDriftAgainstLiveAPI, TestScaffoldedReadyAckActuallyFires). Baseline before this PR was 1989/1985 — +87 tests.
  • gofmt -s -l . → 0 files flagged, with 258 .go files present as a positive control that it looked at anything.
  • golangci-lint 2.12.2 → 0 issues. Run separately from make ci (which does not run it) and from make lint (which silently falls back to go vet when it is absent). Validated against a known-bad state: a planted misspelling in one of the new files was caught, so the clean verdict demonstrably covers them.
  • go vet clean; -race clean on all three affected packages.
  • Determinism: the affected packages were run 10× consecutively — 1293 RUN / 1293 PASS / 0 FAIL every time. The body-close recorders count on the side the test owns (no server, no goroutine), so there is no timing dependency.

🤖 Generated with Claude Code

…x 2 doc claims

Every gap below was verified-correct code with a missing or merely-spelled
guard. Each mutation named was applied, confirmed to fail the new test WITH
THAT GUARD'S OWN MESSAGE, and reverted.

Coverage gaps closed (mutant -> KILLED):
- confirmGenerate default-deny: `case "y","yes"` -> `case "n","no"` inverted,
  which silently turns [y/N] into [Y/n]. The suite only ever fed "y"/"n", and
  neither can see it. Table of 11 non-committal answers, all 0 submits.
- generate + cancel non-TTY refusal: `!stdinIsTTY()` removed. Empty stdin could
  not discriminate (the prompt aborts on EOF anyway), so the guard was pinned
  by its wording; a piped "y" makes the SUBMIT COUNTER the discriminator.
- pendingPath: `filepath.Base` dropped, letting --external-id ../../evil steer
  the write out of the pending dir. Containment asserted on the resolved parent
  dir plus an on-disk canary.
- cost-vs-balance: `>` -> `>=`, refusing a job the user can exactly afford.
- 401-replay: `status == 401` -> `status != 200`, replaying every 500/502/403.
- degenerate dimensions: `<= 0` -> `< 0`. Measured: jpeg.Encode of a 16x0 image
  round-trips through image.DecodeConfig with err == nil, so a zero dimension
  really does reach the server (png.Encode refuses, hence jpeg fixtures).
- response-body leaks in resolveRemoteImage and UploadImageBlob: `defer
  Close()` deleted. Observed by a recorder on the side the test owns, so there
  is no server-side race; 10/10 identical runs.

Two mutants SURVIVE by design, and that is the finding:
- The unsupported-format branch in decodeImageHeader is UNREACHABLE (only png
  and jpeg have decoders, both are map keys, everything else fails earlier with
  ErrFormat). No test can kill it without registering a third decoder, which
  gifBytes() documents as the thing that would destroy the real
  unsupported-format test. Labelled defensive-only in a comment, and the
  invariant that MAKES it unreachable is now pinned instead.
- `req.ContentLength` in UploadPresigned is redundant: NewRequestWithContext
  already sizes a *bytes.Reader. Kept as documented belt-and-braces rather than
  deleted, and the existing Content-Length assertion is re-labelled as pinning
  the outcome, not our line.

Behaviour change: `civitai workflows cancel` now confirms.
It is the only irreversible action here and it destroys a job already paid for,
while every other destructive path gates. --yes/-y proceeds, a TTY prompts
(default no), a non-TTY without --yes refuses. The gate runs before the seam,
so a refusal cannot have cancelled anything. Existing help text is unchanged:
cancelling still does NOT refund.

Doc corrections:
- AGENTS.md item 17 named `orchestration.civitai.com`; the host observed in a
  real upload reply is `orchestration-new.civitai.com`. Both match
  `*.civitai.com`, so isTrustedDownloadHost attaches the token either way and
  the credential-free seam is required regardless — the wildcard is the
  load-bearing fact, so both items now say so explicitly instead of naming a
  hostname a rename can invalidate. (Item 19(e) already used the generic form;
  it gains the observed host and the same caveat.)
- pendingGeneration.PayloadHash claimed a re-attach could tell "the same job"
  from "a different job that reused the key". Nothing reads the field back —
  the only reader, recordPendingWorkflowID, rewrites it. Reworded honestly; the
  field is kept, since the value is only obtainable at submit time.

Verification: full suite COUNTED at 2076 RUN / 2072 PASS / 0 FAIL / 4 SKIP (the
four by-design skips), 0 timeout panics; gofmt -s -l . flags 0 of 258 files;
golangci-lint 2.12.2 reports 0 issues (validated against a known-bad state — a
planted misspelling in a new file was caught, so the verdict covers them);
go vet clean; -race clean. No test touches a live server and no mutation call
was ever issued.
@ZacxDev
ZacxDev merged commit 39c0683 into main Aug 6, 2026
12 checks passed
@ZacxDev
ZacxDev deleted the test/generate-coverage-gaps-and-cancel-confirmation branch August 6, 2026 04:50
ZacxDev added a commit that referenced this pull request Aug 7, 2026
* docs(handoff): capture the civitai generate session state

Records what shipped (#210/#215/#218/#221), the three platform issues and
their outcomes, and the live diagnosis state for the two open follow-ups so
the next session does not re-run probes that already have answers.

Also captures the traps that cost real time here: make ci runs neither gofmt
nor golangci-lint, zsh does not word-split unquoted parameters, a test hang
prints FAIL with no --- FAIL line, and the img2img promotion detector that
must never be re-added because three edit-capable ecosystems price
identically with and without images.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(handoff): retract a wrong diagnosis before anyone acts on it

Investigation 1 described a hazard that does not exist on main. The finding
was real but against PR #222 -- a competing implementation of the same
feature that DID resolve version ids to names in the render path. #222 was
closed as a duplicate and #221 merged instead; I carried the finding across
without re-reading the merged code.

Verified at ba3136c: reportModelSubstitutions takes (io.Writer, []ModelSubstitution,
substitutionPhase), does zero I/O, and prints raw ids. resolveVersion is called
only in buildGenerateGraph pre-estimate.

A handoff carrying a wrong diagnosis is worse than one carrying none -- it is
the first thing the next session acts on. Retracted in place, with where the
false premise came from, so it cannot be re-derived.

Also records both follow-ups as resolved by #237.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs(handoff): #3667 is a CONFIRMED audit gap, and the "no bypass" note was wrong

The #3667 section said "Ruled out - IMPORTANT, do not re-derive: there is no
known bypass". That is false, and it is the shape of note that gets a security
gate lifted, so it is retracted in place with the reasoning that failed: some
graphs composing a shared promptGraph says nothing about graphs that opt out of
the shared node names, and two do.

Hunyuan3D declares no `prompt` node at all (hunyuan3d-graph.ts:71), so the audit
at orchestration-new.service.ts:1460 never runs, and the handler then maps
`hunyuanPrompt` back to `prompt` for the generator (handler:58). PolyGen`s
`texturePrompt` is covered by no audit block and is the only text in an
img2model3d request. Verified at a7e0bcd668 across all 79 declared node
keys; escalated on civitai/civitai#3667.

Consequently: DECIDED to keep `--input` pinned to txt2img (next-steps item 3),
since the gate`s stated lift condition is now answered in the negative.

Also records the independent re-verification of PR #237 (2377 PASS / 0 FAIL,
10/10 call-site-weighted mutants killed, with a positive control proving the
harness can report a survivor), and warns that the base clone is currently on
another session`s branch with uncommitted work.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.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