Skip to content

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 ​

proctorDeclared onRunsJUnit 5pytestJest, Vitest
.beforeAll(fn)suiteonce, before the first trial@BeforeAllscope="session" fixturebeforeAll
.fixture(f)caseper trial, set up before the agent, torn down after—function fixture with yield—
.beforeEach(fn)variantper trial, after fixtures and agent.prepare@BeforeEachautouse fixture, before yieldbeforeEach
act: agent.run—per trial, inside the sandboxtest bodytest bodyit / test body
assert: .expect(grader)caseper trial, after actassertionsassertexpect
.afterEach(fn)variantper trial, after grading, even when beforeEach throws@AfterEachautouse fixture, after yieldafterEach
.afterAll(fn)suiteonce, after the last trial, even when beforeAll throws@AfterAllscope="session" fixture, after yieldafterAll
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)))
HookReceivesMay return
beforeAll, afterAllnothingvoid or a promise
beforeEach, afterEach{ caseId, variant, trial, workspace }: trial is 1-based, workspace holds cwd, home, envvoid or a promise
  • Several hooks of the same kind run in declaration order, afterEach and afterAll included.
  • A beforeAll, beforeEach or afterAll that throws skips the hooks of the same kind declared after it; every afterEach runs, 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 ​

StepRunsWhy
fixtures (gitRepo: git with the host env), agent.prepare (plugin install: sandbox env, no credential, open network), suite and variant hooks, gradersoutside the agent's sandboxthey need git credentials or the network, and the harness trusts them; nothing the agent writes runs there
agent.runinside the sandboxthe evaluated agent is untrusted

Order and cleanup ​

  • afterEach runs as soon as the fixtures are set up and the agent prepared, even if beforeEach throws.
  • sandbox.create receives access: 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: fileChanged takes its snapshot there.
  • A reporter that throws in onTrialEnd does not stop the run: the error goes into suiteErrors.
  • A failed afterAll changes no trial: it goes into suiteErrors, written to the CTRF's results.extra and 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, prepare and the judge receive the signal, the running trial becomes other after its cleanups, the next ones do not start.
  • A failed agent run keeps its transcript: AgentRunError.transcriptPath goes up into TrialResult.transcriptPath and the CTRF's extra.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.

StatusWhen
passedall graders pass
faileda grader returns passed: false, or a principal criterion is missed even if the grader says passed; the message lists the missed criteria
otherinfra error: sandbox, fixture, prepare, hook, agent, init probe, grader that throws, cleanup, timeout, interruption, beforeAll; or nothing was graded
skipped.skip(); no sandbox created