Skip to content

refactor: single responsibility - #37

Merged
Aleksandergreg merged 3 commits into
mainfrom
refactor/single-responsibility
Sep 30, 2026
Merged

Aleksandergreg merged 3 commits into
mainfrom
refactor/single-responsibility

Conversation

@Aleksandergreg

Copy link
Copy Markdown
Owner

No description provided.

Aleksandergreg and others added 3 commits September 30, 2026 20:44
isMissingNetwork matched any Docker output containing "not found". When
the selected Docker context is unavailable, the CLI prints
`context "x": context not found`, and that was misread as a missing
network. docker_network_absent then passed while the network still
existed, and Close dropped the network from its retryable cleanup set,
so every lab network leaked once the context recovered.

A network now counts as missing only when Docker names the exact
reference: "network <ref> not found" (current engines) or
"No such network: <ref>" (older engines). Every caller passes its exact
reference (inspect, Close, and the orphan janitor), so context,
transport, and CLI failures now propagate as errors.

Regression tests cover:
- classification against messages captured from Docker 29.7.2;
- context failure and recovery, for both validation and Close;
- the janitor's network removal path.
All three fail against the old substring match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Session.Run, previously one 360-line function, is now a short read loop over an attempt type, with separate methods for each built-in command, command execution, recording practice, and completion.
- runPlay and listMissions are split into option parsing, choosing the starting mission, and rendering helpers.
- Docker adapter:
  - The six copies of the ownership check are now one owns() helper. As a side effect, the two reconcile paths now also check the schema label; they previously skipped it.
  - The duplicated redaction code is now one redact function over a shared identity type.
  - Execute is a table-like dispatcher.
  - Factory.Create delegates to named setup steps.
  - Container creation builds its arguments from small builders.
- Mission validation runs as four ordered checks, and condition validation is split into the field rules and each type's value rules.

Left alone on purpose: the shell lexer, grep, tar, find, and the command dispatcher. They're security-sensitive or long flat switches, heavily tested, and splitting them would add risk without making them clearer.

Docs and skills: references to moved code in the safety doc, the mission checklist, and the add-mission, extend-sandbox-command, and prepare-iteration skills now point at the new files.

Validation

- make check-all: passed, including race detection and the smoke test.
- go vet for Windows, Linux, and macOS: passed.
- make docs-check: passed in strict mode.
- All 6 real-Docker integration tests passed, with 0 containers or networks left behind.
- git diff --check: clean.
Main gained the squash-merged fix from #35 (1fa140c), which is identical
to this branch's fix commit (9a760c2). Both sides touched the files the
refactor later moved, so the three conflicts keep this branch's side:

- dockerlab_test.go stays deleted. Its contents, including the fix's
  context-failure fake fields, live in fake_runner_test.go and the
  related split test files.
- network.go keeps the refactored layout. The fixed isMissingNetwork
  lives in transport.go.
- network_test.go keeps the refactored layout. The fix's regression
  tests live in network_errors_test.go.

The merged tree is identical to a22146f, and make check-all passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Aleksandergreg
Aleksandergreg merged commit e1bc27f into main Sep 30, 2026
5 checks passed
@Aleksandergreg
Aleksandergreg deleted the refactor/single-responsibility branch September 30, 2026 19:19
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