Lifecycle
The hooks follow the set-up / tear-down model shared by test frameworks such as JUnit, pytest, Jest or Vitest: what is set up before is torn down after, even when a step fails.
Hooks
| proctor | Declared on | Runs | JUnit 5 | pytest | Jest, Vitest |
|---|---|---|---|---|---|
.beforeAll(fn) | suite | once, before the first trial | @BeforeAll | scope="session" fixture | beforeAll |
.fixture(f) | case | per trial, set up before the agent, torn down after | — | function fixture with yield | — |
.beforeEach(fn) | variant | per trial, after fixtures and agent.prepare | @BeforeEach | autouse fixture, before yield | beforeEach |
act: agent.run | — | per trial, inside the sandbox | test body | test body | it / test body |
assert: .expect(grader) | case | per trial, after act | assertions | assert | expect |
.afterEach(fn) | variant | per trial, after grading, even when beforeEach throws | @AfterEach | autouse fixture, after yield | afterEach |
.afterAll(fn) | suite | once, after the last trial, even when beforeAll throws | @AfterAll | scope="session" fixture, after yield | afterAll |
ts
import { appendFile } from "node:fs/promises"
import { join } from "node:path"
import { regex, suite } from "@fluce/proctor"
export default suite("lifecycle")
.beforeAll(() => console.log("once, before the first trial"))
.afterAll(() => console.log("once, after the last trial"))
.variant("baseline", (v) =>
v
.prompt("Say hello")
.beforeEach(({ workspace }) => appendFile(join(workspace.cwd, "NOTES.md"), "Be polite.\n"))
.afterEach(({ caseId, variant, trial }) => console.log(`${caseId} [${variant}] #${trial} done`)),
)
.case("greets", (c) => c.expect(regex("says-hello", /hello/i)))| Hook | Receives | May return |
|---|---|---|
beforeAll, afterAll | nothing | void or a promise |
beforeEach, afterEach | { caseId, variant, trial, workspace }: trial is 1-based, workspace holds cwd, home, env | void or a promise |
- Several hooks of the same kind run in declaration order,
afterEachandafterAllincluded. - A
beforeAll,beforeEachorafterAllthat throws skips the hooks of the same kind declared after it; everyafterEachruns, even when another one threw. - There is no case hook: a case sets up its state with a fixture, which returns its own teardown (see Fixtures).
- Hooks run outside the agent's sandbox: see what runs where.
Run
A run wraps its trials between beforeAll and afterAll, each called once.
Trial
Each trial sets up, acts, asserts, then tears down. Each step that succeeds stacks its undo; the stack unwinds after assert, or at the first throw.
What runs where
| Step | Runs | Why |
|---|---|---|
fixtures (gitRepo: git with the host env), agent.prepare (plugin install: sandbox env, no credential, open network), suite and variant hooks, graders | outside the agent's sandbox | they need git credentials or the network, and the harness trusts them; nothing the agent writes runs there |
agent.run | inside the sandbox | the evaluated agent is untrusted |
Order and cleanup
afterEachruns as soon as the fixtures are set up and the agent prepared, even ifbeforeEachthrows.sandbox.createreceivesaccess: what the agent (sandboxAccess) and the suite (.allowDomains,.allowRead,.allowWrite) must let through.- Graders receive the run's judge (
RunOptions.judge: its agent, its sandbox, its default model), never the evaluated agent. grader.prepare(workspace), optional:fileChangedtakes its snapshot there.- A reporter that throws in
onTrialEnddoes not stop the run: the error goes intosuiteErrors. - A failed
afterAllchanges no trial: it goes intosuiteErrors, written to the CTRF'sresults.extraand at the bottom of the summary.
Timeouts and interruption
- On timeout, the signal passed to the agent is aborted and the trial becomes
other(agent run failed: timed out after 1m: raise the case .timeout(...)…). - Cleanup waits for the agent to stop, 5 s at most (
ABORT_GRACE_MS), so as not to tear down a workspace it is still writing to. - An interruption (
runSuite({ signal }), Ctrl-C in the CLI) follows the same path: the agent,prepareand the judge receive the signal, the running trial becomesotherafter its cleanups, the next ones do not start. - A failed agent run keeps its transcript:
AgentRunError.transcriptPathgoes up intoTrialResult.transcriptPathand the CTRF'sextra.transcript. - Each launched command has its own process group: on abort, SIGTERM then SIGKILL after 2 s; on normal exit, whatever it left in the background is killed.
Statuses
The first condition met, top down, decides the status.
| Status | When |
|---|---|
passed | all graders pass |
failed | a grader returns passed: false, or a principal criterion is missed even if the grader says passed; the message lists the missed criteria |
other | infra error: sandbox, fixture, prepare, hook, agent, init probe, grader that throws, cleanup, timeout, interruption, beforeAll; or nothing was graded |
skipped | .skip(); no sandbox created |