Skip to content

test: contract tests for how callers use nodkey run - #209

Merged
groupsky merged 1 commit into
mainfrom
hq-job/nodkey-release-ci-1/contract-tests
Nov 17, 2026
Merged

groupsky merged 1 commit into
mainfrom
hq-job/nodkey-release-ci-1/contract-tests

Conversation

@groupsky

@groupsky groupsky commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #198

The masking change of #171 passed every test, but it broke two kinds of callers (#191). These tests pin what a caller of nodkey run sees today (0.7.0), as DESIGN.md section 5 ("What the command gets") and docs/setup.md section 11 ("Keep the mask on") describe it.

  • test/contract/: black-box tests against the built nodkey binary and a trial broker (nodkey try). The tests answer its requests on its stdin: approve for demo-token, deny for all else.
    1. A password command reads *** through a pipe; the documented way (the program runs inside nodkey run and reads its own environment) gets the value. Values are compared as SHA-256 only; no test prints a value.
    2. Parent process: masked, the parent is nodkey (its /proc/PID/stat readable, its /proc/PID/exe not), whose parent is the caller; with execve, the command has nodkey's PID and the caller as parent.
    3. Exit codes, death by signal, and which signals reach the command (SIGTERM and SIGHUP yes; masked, SIGINT and SIGUSR1 no).
    4. The command reads nodkey's stdin, and fd 3 of the caller reaches it.
    5. Each of these on pipes, on a pseudo-terminal, masked and with execve (5 modes).
      Also a deny: exit 77, and the command never runs.
  • test/contract/README.md: a change to a test here is a change in behavior for callers.
  • docs/setup.md links each pattern to its test. AGENTS.md and DESIGN.md (section 17) name the folder.

The tests have no build tag and run in the go test -race ./... job of every PR (about 5 s on a laptop). They pass on main: no difference between the docs and the code turned up.

This PR only adds new test files under test/contract/ and its README, so the new gate (#197) does not count it as a change in behavior.

Behavior for callers

Changes behavior for existing callers: no

Tests

  • go vet ./..., go test -race ./..., go test -race -count=3 ./test/contract/..., golangci-lint run --build-tags e2e, gofmt -l .: all pass.
  • Security review (.claude/agents/security-reviewer.md, two runs) and a correctness review: no critical, high or medium security finding. Fixed: a masked SIGINT check could pass by chance (Linux delivers SIGHUP before SIGINT; now the test waits 500 ms before the last signal), the deny failure no longer prints stderr, the trial's stdin closes on stop, an ignored signal (as under nohup) is a failure in CI and a skip elsewhere in both signal tests, and the README says that any change to a file here (also the harness) counts.
  • Not fixed (low): the deny count in TestDenied is for the whole run, so only the first subtest proves that the deny came from a tap; the later ones rely on the deny cache, as the comment says. The exit 77 and "the command never ran" are checked in every subtest.
  • Not covered by a test yet (gaps, not wrong claims): the same argument list and working directory, SIGQUIT, and a command that runs on after nodkey gets SIGKILL.

Progress

  • Contract tests for patterns 1 to 5, and a deny
  • test/contract/README.md
  • docs/setup.md links the patterns to their tests
  • Security review
  • CI green. The first run of test (stable) failed in internal/broker TestLoginRememberedTimer ("value 2 that the store gave out is not cleared"); this PR does not touch that code, the contract tests passed in that run, and the rerun passed. 20 local runs of that test pass. It is a rare flake.

🤖 Generated with Claude Code

Fixes #198

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@groupsky
groupsky marked this pull request as ready for review November 17, 2026 19:09
@groupsky
groupsky merged commit 542fd35 into main Nov 17, 2026
13 of 14 checks passed
@groupsky
groupsky deleted the hq-job/nodkey-release-ci-1/contract-tests branch November 17, 2026 19:10
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.

test: contract tests for how callers use nodkey run (pipe, parent process, signals, exit codes, fds)

1 participant