Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5a125f4bc |
@@ -5175,5 +5175,3 @@ Before: managed project/thread verbs had no Console conversation area. After: fi
|
||||
|
||||
2026-10-20 05:10:34 UTC | Row 178 #1676 round 2 verified | Before: C1 render refusals lacked killing tests and row 181 base was pending. Rebased onto 931651f2d, kept all COUNTED/count code and tests, appended T178 tail; added independent owner/collision/absolute/charset/header and empty-loopback proof tests. Four files singly 156/156, all 24 mutants killed, metadata and sandbox fixture probes pass; scratch sweep empty. Packet agents/rocko/work/queue-178/r2/, candidate 9300a670, inventory d0dcde7b (59/59), scan 58 files no findings; in-review revs 2166-2167, expected no-token request failure. No live actions or commits.
|
||||
2026-10-21T01:28:05Z | Darkwing | row 232 #1734 installer I1 build, round 1 in review | Before: stack-release.sh managed only user units (systemctl --user), and stack-copy.sh had no bundle copy. After: --units external (adopt, activate, rollback --to, status, confirm, revert, gate --since, AWAITING-UNITS, stale-start, external-pm, --plan --expect-from) and stack-copy check --units external, copy --bundle FILE SHA, wrapper ID --create; user mode byte-identical to the base by test. First build 0af0c73c6 on 00d4cc1f6; rebased onto row 200 (cb5fdb064) as a0ffabc3f on darkwing/row232-r1; --sso refused under external (D9), row 200 config_checks run under external (D10). Gate on Sage's slot (sage-1618): cli 561/0, every scripts/test-*.sh green; 17/17 mutants killed. Results commit 84f1a91e6 (pushed, seat branch only). Manifest 7a3b4ea1 (9 paths), queue revs 2595-2596, request comment 29825, reviewer Filbert. Packet agents/darkwing/work/queue-232/BUILD.md.
|
||||
2026-10-21T04:50:44Z | Darkwing | row 233 #1735 installer I3 build, round 1 in review | Before: root had no upgrade driver for root-owned units and no host run sheet; stack-release.sh had no rehearse --backup last and no external plan refusals. After: scripts/stack-upgrade.sh upgrade and rollback (r6 A1-A5, A2f, R1-R4) with 20 tests, docs/guides/host-run-sheet.md, TOOLS.md lines, and on Sage's rulings stack-release.sh --backup last, BACKUP_STORE and the --plan refusals open-activation and migrate-required (3 tests). Base e65a3ab4d (row 232's landing). Gate on Sage's slot (sage-1704) on d99166ade: cli 616/0, every scripts/test-*.sh green, 1201/0 summed by awk; m1-m8 8/8 killed. Correction: the process sweep after the gate found an orphaned sleep 60 from the lock test's flock holder (N1); 08db6ac3f fixes it test only, Sage ruled the gate stands (sage-1707), rerun c0 20/0 and m1 killed with 0 left (sage-1708). Tip 1a1dc80ca (pushed, seat branch only). Manifest 464ce9eb (7 paths), queue revs 2644 and 2647, request comment 29901, reviewer Filbert. Packet agents/darkwing/work/queue-233/BUILD.md.
|
||||
2026-10-21T06:37:41Z | Darkwing | row 240 #1746 installer I4 build, round 1 in review | Before: root had no host check for the bwrap AppArmor profile, its pins or a boot unit, and stack-upgrade.sh exited 1 args-failed when the args move after A5 failed, while exit 1 means the old copy runs. After: scripts/case1-hostcheck.sh (seven items, --check, --enforce, --upstream), scripts/case1-pins.sh, mosaic-hostcheck.service and 16 tests; the args move failure exits 5 args-failed, documented in TOOLS.md and run sheet section 6 and tested; run sheet section 3 puts the pinned npm on PATH and names the bin/claude.exe --claude path; sections 8 and 10 have precheck lines. Verification: slot run r1 on 47ec9fe2f failed at the singles (the new N1 test's after hook threw ENOENT after the fixture cleanup removed the root); b45852daa drops the hook; r2 on b45852daa green: singles 16/0 and 21/0, c0 plus M1-M8 8/8 killed, cli 639/0, scripts 585/0. Candidate darkwing/row240-r3 ad1b23ab2 on c771a36f4, manifest 573ece95 (9 paths), revs 2694 and 2695, comment 29943.
|
||||
|
||||
+3
-7
@@ -86,8 +86,7 @@ The layers each adapter relies on, and what they don't cover, are in
|
||||
### A role's skills (row 64)
|
||||
|
||||
A managed session's skills reach both adapters as text in the bundle's
|
||||
`prompt.md`, which they pass as a file: `pi` with `--system-prompt <path>`
|
||||
and `claude` with `--system-prompt-file <path>` (row 213). Neither adapter loads a
|
||||
`prompt.md`, which they pass with `--system-prompt`. Neither adapter loads a
|
||||
skill of its own: `pi` keeps `--no-skills`, since role sessions never get
|
||||
`MOSAIC_SKILLS`, and `claude` keeps `--disable-slash-commands` and
|
||||
`--restricted`. Sage chose this on 2026-10-19 from a probe, recorded in
|
||||
@@ -105,8 +104,5 @@ skill of its own: `pi` keeps `--no-skills`, since role sessions never get
|
||||
|
||||
The cost is prompt size: a role's skill text is in every turn, where the
|
||||
other routes load a skill when it's used. The bundle caps a role's skills at
|
||||
64 KiB together. The cap dates from when `claude` passed `prompt.md` as one
|
||||
argument, which Linux caps at 128 KiB; row 213 passes the file instead, so no
|
||||
local user reads the prompt in `/proc/<pid>/cmdline`. Pi 0.85.1 uses the path
|
||||
string itself as the prompt when the file is missing or can't be read, so the
|
||||
pi adapter exits 2 unless the path is a readable regular file.
|
||||
64 KiB together, since `claude` passes `prompt.md` as one argument and Linux
|
||||
caps one argument at 128 KiB.
|
||||
|
||||
@@ -27,11 +27,6 @@ need MOSAIC_CLAUDE_MCP_CONFIG
|
||||
for f in "$MOSAIC_SYSTEM_PROMPT_FILE" "$MOSAIC_CLAUDE_SETTINGS" "$MOSAIC_CLAUDE_MCP_CONFIG"; do
|
||||
[ -r "$f" ] || { echo "claude adapter: not readable: $f" >&2; exit 2; }
|
||||
done
|
||||
PROMPT_FILE=$MOSAIC_SYSTEM_PROMPT_FILE
|
||||
case "$PROMPT_FILE" in
|
||||
/*) ;;
|
||||
*) PROMPT_FILE="$(pwd)/$PROMPT_FILE" ;;
|
||||
esac
|
||||
[ "${MOSAIC_INTERACTIVE:-}" != "1" ] || { echo "claude adapter: interactive mode isn't supported" >&2; exit 2; }
|
||||
CLAUDE=claude
|
||||
if [ -n "${MOSAIC_CLAUDE_BIN:-}" ]; then
|
||||
@@ -61,10 +56,7 @@ fi
|
||||
# Flags:
|
||||
# -p one-shot: print the answer and exit
|
||||
# --output-format text stdout is the answer only
|
||||
# --system-prompt-file the generated prompt replaces the default, given
|
||||
# as a file so no local user reads it in
|
||||
# /proc/<pid>/cmdline (row 213); absolute, since
|
||||
# the cd above changed the working directory
|
||||
# --system-prompt the generated prompt replaces the default
|
||||
# --effort the instance's thinking var (row 65; 2.1.302 takes
|
||||
# low, medium, high, xhigh, max)
|
||||
# --restricted no user/project/local settings files; --settings
|
||||
@@ -84,9 +76,10 @@ fi
|
||||
# text in the system prompt (row 64)
|
||||
ALLOWED=mcp__mosaic
|
||||
[ -z "${MOSAIC_TOOLS:-}" ] || ALLOWED="$MOSAIC_TOOLS,mcp__mosaic"
|
||||
PROMPT_CONTENT="$(cat "$MOSAIC_SYSTEM_PROMPT_FILE")"
|
||||
"$CLAUDE" -p "$MOSAIC_REQUEST" \
|
||||
--output-format text \
|
||||
--system-prompt-file "$PROMPT_FILE" \
|
||||
--system-prompt "$PROMPT_CONTENT" \
|
||||
--model "$MOSAIC_MODEL" \
|
||||
--effort "$MOSAIC_THINKING" \
|
||||
--restricted \
|
||||
|
||||
+4
-14
@@ -8,17 +8,7 @@
|
||||
set -eu
|
||||
|
||||
[ -n "${MOSAIC_SYSTEM_PROMPT_FILE:-}" ] || { echo "pi adapter: MOSAIC_SYSTEM_PROMPT_FILE is required" >&2; exit 2; }
|
||||
# Row 213 (C2-08): pi gets the prompt as a path, so no local user reads it in /proc/<pid>/cmdline.
|
||||
# Pi 0.85.1 reads --system-prompt as a file only when the path exists and reads, and otherwise
|
||||
# uses the path string itself as the prompt, without a warning for a missing file
|
||||
# (dist/core/resource-loader.js resolvePromptInput). So the path must be a regular readable
|
||||
# file here, and is made absolute before the cd below, since pi resolves it from its own cwd.
|
||||
PROMPT_FILE=$MOSAIC_SYSTEM_PROMPT_FILE
|
||||
case "$PROMPT_FILE" in
|
||||
/*) ;;
|
||||
*) PROMPT_FILE="$(pwd)/$PROMPT_FILE" ;;
|
||||
esac
|
||||
[ -f "$PROMPT_FILE" ] && [ -r "$PROMPT_FILE" ] || { echo "pi adapter: system prompt not readable: $MOSAIC_SYSTEM_PROMPT_FILE" >&2; exit 2; }
|
||||
[ -r "$MOSAIC_SYSTEM_PROMPT_FILE" ] || { echo "pi adapter: system prompt not readable: $MOSAIC_SYSTEM_PROMPT_FILE" >&2; exit 2; }
|
||||
# MOSAIC_AGENT_NAME is optional in headless mode (identity section is then
|
||||
# omitted); interactive launches always set it via scripts/agent.sh.
|
||||
|
||||
@@ -104,8 +94,7 @@ fi
|
||||
# All flags documented in the pi package README (CLI Reference):
|
||||
# -p/--print one-shot mode: print the response and exit (omitted in
|
||||
# interactive TUI mode)
|
||||
# --system-prompt replace the default prompt with the generated one, given
|
||||
# as the file's absolute path (checked above), never its text
|
||||
# --system-prompt replace the default prompt with the generated one
|
||||
# --no-* no ambient context/skills/extensions/templates/themes
|
||||
# EXT_FLAGS the explicitly provided extensions only (-e)
|
||||
# SESSION_FLAGS ephemeral | persistent | forked (per env)
|
||||
@@ -114,6 +103,7 @@ fi
|
||||
# --offline no startup network operations (update checks/telemetry)
|
||||
# --no-approve ignore project-local .pi/ files (settings, SYSTEM.md)
|
||||
# whatever trust is saved for the workspace
|
||||
PROMPT_CONTENT="$(cat "$MOSAIC_SYSTEM_PROMPT_FILE")"
|
||||
set -- \
|
||||
--offline \
|
||||
--no-approve \
|
||||
@@ -128,7 +118,7 @@ set -- \
|
||||
--provider "$PI_PROVIDER" \
|
||||
--model "$PI_MODEL" \
|
||||
$THINKING_FLAG \
|
||||
--system-prompt "$PROMPT_FILE"
|
||||
--system-prompt "$PROMPT_CONTENT"
|
||||
# One-shot mode appends -p and the request (both safely quoted);
|
||||
# interactive mode appends nothing - clean TUI.
|
||||
[ "$INTERACTIVE" = "1" ] || set -- "$@" -p "$MOSAIC_REQUEST"
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
# Row 195 build: `scripts/case1-accept.sh`
|
||||
|
||||
Row 195 (#1693), the Case 1 install on 10.1.1.53. Design r7 at 5425ea2f3, approved by Duckworth
|
||||
(duckworth-0087, `agents/duckworth/work/row195/REVIEW-r7.md` at 58d930f89; Gitea 29962). Sage's go to build
|
||||
is sage-1817.
|
||||
|
||||
## What this commit holds
|
||||
|
||||
- `scripts/case1-accept.sh` (new, 100755): section 5's acceptance, F1-F11 and P1-P11.
|
||||
- `packages/cli/tests/case1-accept.test.mjs` (new): section 5's cases.
|
||||
- `docs/TOOLS.md`: the `case1-accept.sh` entry after the hostcheck entry.
|
||||
- This file.
|
||||
- `DESIGN.md`, doc-only fixes Sage named in sage-1817, with no new design round:
|
||||
- Duckworth's N1. Section 1's human-id row cited `broker.mjs:245`; the check is `broker.mjs:321`.
|
||||
- Row 226's state at :21 and :326. It said "unclaimed"; 226 is assigned to Gosalyn, briefed and not
|
||||
started (sage-1814).
|
||||
- :340 said I'd send the section 6 items to Gosalyn once 226 was claimed. I sent them on 2026-10-21
|
||||
and Gosalyn acknowledged (gosalyn-0085), so the line now says that.
|
||||
|
||||
Nothing else changes. No `case2-*.sh`, `stack-upgrade.sh`, `stack-release.sh`, `case1-hostcheck.sh` or run
|
||||
sheet edit, and nothing touches .53 (sage-1809).
|
||||
|
||||
## Deviations from section 5, and choices it left open
|
||||
|
||||
1. P4's mark is the single token `accepted Q182+Q183`. Section 5 lists `accepted Q182` and `accepted
|
||||
Q183` as marks and gives P4 both. One line can carry one mark, and P4 is the only Q182 path, so the
|
||||
count list has `accepted Q182+Q183` in place of `accepted Q182`.
|
||||
2. The test seam replaces `getent`. Under `--root`, the script reads `DIR/etc/passwd` and `DIR/etc/group`
|
||||
with awk. Without it, the same helper calls `getent`. The groups of a user are its primary gid, then
|
||||
each group whose member list names it, which is what `id -G` prints. So there is no fake `id`, and
|
||||
the script never calls `id` for another user.
|
||||
3. P10 reads the port floor from `/proc/sys/net/ipv4/ip_unprivileged_port_start` rather than calling
|
||||
`sysctl`, so the seam covers it the way hostcheck's item 7 is covered. There is no fake `sysctl`.
|
||||
4. There is no fake `bwrap`, `claude`, `node` or `hostcheck.sh` on PATH. The script runs each by the
|
||||
absolute path the args file or the install names, so the test puts stubs at those paths under
|
||||
`--root`, and the fake `sudo` runs the stack's user's commands from the tree.
|
||||
5. The args file must say `--profile factory` and name `--business`. Both are new refusals beyond
|
||||
`stack-upgrade.sh`'s rules. A library file, or one for another business, would make F4 and F7
|
||||
check the wrong thing. After `--`, `--port` and `--tester-port` must be numeric. The args file is the
|
||||
only source of the ports.
|
||||
6. F8, F9 and F11 read file metadata as root: `stat`, `-L` and `find -maxdepth 1 -name '*.json'`. None
|
||||
opens the credential. F9 parses `managed-settings.json` with the pinned node, run by root: that node
|
||||
and that file are both root's own, installed by ops-01.
|
||||
7. F7 reads `launch.by` from `$HOME/.config/mosaic-dev/businesses/<id>.json` as the stack's user. That
|
||||
path is `businessFilePath(id)` under the default config, which is what the unit uses. It doesn't load
|
||||
the copy's `business.mjs` as `stack-release.sh`'s `plugins launchby` does. The user runs the whole
|
||||
check and prints one line, and root accepts only `ok <instance> run <run>` (sage-1653: root doesn't
|
||||
parse the user's output beyond a fixed pattern).
|
||||
8. F5 names a process claude when its argv0's basename or its `comm` starts with `claude`. The window
|
||||
confirms this against a real role session. If the bwrap'd claude shows another name, F5 fails closed
|
||||
and the fix is this match, not the label check.
|
||||
9. F3 and F5 run together. `talk` goes out in the background under `timeout 330`, and the `/proc` scan
|
||||
repeats every half second until it finds a labelled pair or `talk` exits. F3's line prints first, then
|
||||
F4, then F5, so the output keeps id order. F3 passes on exit 0 with the `sent` line and a reply line,
|
||||
both counted on stdout only (`cli.mjs:395` and the `formatMessage` write); talk's error goes to stderr.
|
||||
12. `--claude` must match `^/[A-Za-z0-9/._+@-]+$`. The `@` is for `node_modules/@anthropic-ai/...`;
|
||||
`stack-upgrade.sh` doesn't check `--claude` at all.
|
||||
10. F1 requires all four uids in `/proc/<MainPID>/status` (real, effective, saved, filesystem) to be the
|
||||
user's.
|
||||
11. Evidence text the stack's user controls (talk's last line, the precheck's last line, F6's and F10's
|
||||
`--version`) is cut to printable ASCII, one line, 200 bytes.
|
||||
|
||||
## Tests
|
||||
|
||||
`packages/cli/tests/case1-accept.test.mjs`, 22 tests. Every case builds a scratch host with every F check
|
||||
passing and every P check closed or accepted, then changes one thing:
|
||||
- all pass: exit 0, ids in order, each P mark, the count lines match the check lines, and the stand-in
|
||||
credential's value appears nowhere;
|
||||
- each F check failing alone exits 1 with only its line failing;
|
||||
- F3 on exit 0 with only the `sent` line, and its evidence taking talk's stderr;
|
||||
- F1 on a failed unit and on `User=root`; F2 on healthz failing and on another pid holding the port;
|
||||
- F5 on `unpriv_bwrap (enforce)`, `bwrap//&unpriv_bwrap (complain)`, a trailing space on either label,
|
||||
no bwrap of the user's, and passing on `comm` alone;
|
||||
- F6 on a stub that prints nothing and on a path outside `claude-<pin>`;
|
||||
- F7 on two live PM launches, a live one for another business, and no `launch.by`;
|
||||
- F8 on 0640, on another owner and on a symlink, never printing the credential;
|
||||
- F9 on a group-writable mode, another owner and a number for the flag;
|
||||
- F11 on one `*.json` under `discord/`, and passing on an empty directory;
|
||||
- each P check's unnamed mark, with the line count each fault makes: P6 one line per member, P9 one per
|
||||
missing item; P2, P5, P10 and P11 in more than one way;
|
||||
- every P check unnamed at once still exits 0;
|
||||
- nine bad args files refuse with exit 2 before any command runs, each with its own refusal text;
|
||||
- usage errors, and a user's run without `--root`, exit 2;
|
||||
- every in-instance call goes through `sudo -u mosaic -H env PATH=<node dir>:/usr/local/bin:/usr/bin:/bin`,
|
||||
read from the fake `sudo`'s argv, and root's other `sudo` calls are exactly `-l -U mosaic`,
|
||||
`-l -U localadmin` and the jarvis bwrap probe;
|
||||
- the host check records `--check` and never `--enforce`.
|
||||
|
||||
## Mutants
|
||||
|
||||
Section 5's twelve, each one exact replacement in `scripts/case1-accept.sh`, run by
|
||||
`/mnt/storage/scratch/darkwing-195-out/mutants.py` in Sage's slot (sage-1865). All twelve were killed.
|
||||
After each one the script's bytes were restored, and the final sha256 matched (`d434f15ff638...`). The
|
||||
killers below are the tests that failed in each mutant's saved log.
|
||||
|
||||
| # | Mutant | Killed by |
|
||||
|---|---|---|
|
||||
| 1 | F1 passes on a MainPID owned by root | each F alone |
|
||||
| 2 | F2 accepts a listener on 0.0.0.0 | each F alone |
|
||||
| 3 | F3 passes without a reply | each F alone; F3 exit 0 with no reply line |
|
||||
| 4 | F5 matches a substring | F5 labels (the trailing space) |
|
||||
| 5 | F6 skips the `--version` check | each F alone; F6 stub and path |
|
||||
| 6 | F8 skips the owner check | F8 0640, owner and symlink |
|
||||
| 7 | F11 ignores `discord/` | each F alone; F11 `*.json` |
|
||||
| 8 | P1 closes on any output | P unnamed; every P unnamed |
|
||||
| 9 | P5 maps to `closed` with jarvis in docker | P unnamed; every P unnamed; P2 and P5 names docker |
|
||||
| 10 | P9 drops the jarvis item | P unnamed; P9 per item |
|
||||
| 11 | P11 accepts any `Before=` | P unnamed; every P unnamed |
|
||||
| 12 | a P check's `unnamed` sets the exit to 1 | P unnamed; every P unnamed; P10 and P11; P2 and P5; P9 per item |
|
||||
|
||||
Mutant 1 survived the F1 variants test (a failed unit, `User=root`), because those faults fail F1 on the
|
||||
unit's state and `User=`, not on the uid line. Each F alone covers the uid line.
|
||||
|
||||
## Pre-slot read review
|
||||
|
||||
Since every test run is slot work, a read-only subagent traced each case through the script before the
|
||||
first slot run, executing nothing. It found four defects, all fixed in this commit:
|
||||
- The `--claude` regex had no `@`, so every run refused the args file, the real .53 one included.
|
||||
- The fake `stat` logged the args-file call, so the bad-args test's "no command ran" check would fail.
|
||||
- The P5 and P6 faults each rewrote `etc/group` from the constant, so applying both lost P5's change.
|
||||
- F3 counted stderr into its line count, so a mutant dropping the exit check survived. F3 now counts
|
||||
stdout only, and a `sent`-only case covers the line count.
|
||||
|
||||
## Run environment
|
||||
|
||||
The build commit ddf7dce6c sits on base 4ced5e63d (origin/refactor when it was pushed). It was first built
|
||||
on c515273db as 4a51d392c. Row 238 then changed `docs/TOOLS.md`, so I cherry-picked the three commits onto
|
||||
4ced5e63d as `darkwing/row195-b`. `git range-diff` shows all three identical. node v26.8.1 on dragon-lin,
|
||||
every run behind my busy check and Sage's, chained with `&&`.
|
||||
|
||||
- Step 1, sage-1829 (07:41:54Z to 07:42:05Z), TMPDIR `/tmp/dw195`:
|
||||
`node --test packages/cli/tests/case1-accept.test.mjs`, 22 pass, 0 fail, 11.0 s.
|
||||
- Step 2, sage-1865 (08:34:27Z to 08:36:21Z), TMPDIR `/mnt/storage/scratch/tmp/r195`: the twelve mutants
|
||||
above, all killed.
|
||||
- Step 3, the gate (08:36:21Z to 08:47:06Z), same TMPDIR, `COMPOSE_PROJECT_NAME=darkwing-r195`:
|
||||
|
||||
| Suite | Result |
|
||||
|---|---|
|
||||
| packages/cli (`node --test tests/*.test.mjs`) | 662 pass, 0 fail, 0 skipped |
|
||||
| test-auth.sh | 15 passed, 0 failed |
|
||||
| test-conductor.sh | 17 passed, 0 failed |
|
||||
| test-config.sh | 31 passed, 0 failed |
|
||||
| test-discord.sh | 78 passed, 0 failed |
|
||||
| test-extension-package.sh | 18 passed, 0 failed |
|
||||
| test-foundation.sh | 44 passed, 0 failed |
|
||||
| test-land-work.sh | 86 passed, 0 failed |
|
||||
| test-queue.sh | 156 node pass, 0 fail; 28 passed, 0 failed |
|
||||
| test-release.sh | 14 passed, 0 failed |
|
||||
| test-task.sh | 98 passed, 0 failed |
|
||||
|
||||
Summed: 818 node tests passed with 0 failed, and 429 selftests passed with 0 failed. The compose network
|
||||
was removed afterwards, and the sweep found no process left in the worktree, the output directory or the
|
||||
TMPDIR. This file's results are a doc-only commit on top of the build, so nothing that ran has changed.
|
||||
@@ -1,388 +0,0 @@
|
||||
# Row 195 design: the Case 1 install on 10.1.1.53 (r7)
|
||||
|
||||
Darkwing, 2026-10-21. Brief: `docs/plans/2026-10-20_hub-own-uid.md`, blob 45be7f09afc1, section "Brief: the
|
||||
Case 1 install on 10.1.1.53 (row 195)". Gitea #1693. Reviewer Duckworth, gate owner Sage. Branch
|
||||
`darkwing/row195-r7` on c515273db. r6 (b7239bb66 on `darkwing/row195`, approved duckworth-0055) is the base,
|
||||
carried unchanged as 7398b7dd7. The r6 text is in that commit and in b7239bb66.
|
||||
|
||||
## Changes from r6
|
||||
|
||||
Q187 (mos-1108) made install and upgrade product commands, and mos-1118 split r6 into the installer rows
|
||||
(`docs/plans/2026-10-20_installer-rows.md`). That brief says row 195 "shrinks to the factory profile's
|
||||
values and the Case 1 acceptance". So r7 is mostly a cut. What r6 designed now ships elsewhere:
|
||||
|
||||
| r6 piece | Now | State |
|
||||
|---|---|---|
|
||||
| `stack-release.sh --units external`: `confirm`, `revert`, `gate`, `rollback --to`, external `adopt` and `status`; `stack-copy.sh check --units external` and bundle copies | row 232, I1 | landed |
|
||||
| `case1-repin.sh` (A1-A5, A2f, R1-R4) | `scripts/stack-upgrade.sh`, row 233, I3 | landed |
|
||||
| the host steps 2a, 2a', 2a'' and the window's root steps | `docs/guides/host-run-sheet.md` sections 1-10, row 233 | landed |
|
||||
| `case1-hostcheck.sh`, `case1-pins.sh`, `mosaic-hostcheck.service` (the drift stop, r6 B2) | row 240, I4 | landed c515273db |
|
||||
| the unit render, `--profile factory`, `--pm`, `--claude`, the factory serve flags, the precheck | row 230, C2-13a, I2 | landed |
|
||||
| the install as `mosaic`: bootstrap, business file, copy | row 226, C2-13b, I2, `scripts/case2-install.sh` | assigned to Gosalyn, briefed, not started |
|
||||
| `docs/guides/case1-install.md` | the host run sheet, plus section 6 of this file | |
|
||||
|
||||
Other changes:
|
||||
|
||||
- Claude moves under `/opt` (sage-1522, run sheet section 3). `--claude` is
|
||||
`/opt/mosaic-stack/claude-<pin>/node_modules/@anthropic-ai/claude-code/bin/claude.exe`, root's, and root
|
||||
installs and upgrades it. r6's `/srv/mosaic/.local/bin/claude` is gone. F6 reads the new path.
|
||||
- The args file is `/etc/mosaic-stack/dev.args` (run sheet section 7), not `case1-unit.args`. It holds
|
||||
`--copy` too, and `stack-upgrade.sh` rewrites only that line, after confirm passes.
|
||||
- Both units are `WantedBy=multi-user.target` and start at boot (Q189, mos-1122). r6's "the Console has no
|
||||
`[Install]`, root starts it by hand after a reboot" no longer holds.
|
||||
- The business id is stated, with the DEFERRED 240 N1 reasoning (sage-1809, sage-1813). Section 7.
|
||||
- The window can't run until row 226 lands. Sage added 226 to row 195's after list at rev 2718
|
||||
(sage-1813). Section 6 lists what row 195 needs from 226's install.
|
||||
- The acceptance runs as root through ops-01, not as `localadmin`. `aa-status`, `sudo -l -U`,
|
||||
`systemd-run --uid` and the hostcheck all need root. It gains four functional checks for items the run
|
||||
sheet marks "precheck line missing" (F8-F11) and one host line (P11). Section 5.
|
||||
- The Discord row in section 2 changed. The precheck's "no Discord binding" line is C2-13b's and is
|
||||
library-only, so for the factory it's F11 in the acceptance.
|
||||
|
||||
What row 195 still builds: `scripts/case1-accept.sh` and its test (section 5). The rest of this file is
|
||||
inputs, the window order and the record the reviewer checks.
|
||||
|
||||
## 0. What I checked on the host
|
||||
|
||||
Read only, as `localadmin` over ssh, 2026-10-20 between 20:40Z and 21:51Z. Nothing in r7 touched .53
|
||||
(sage-1809). The window's first step re-reads these, since they can drift in a day: unattended-upgrades
|
||||
runs daily.
|
||||
|
||||
| Item | 10.1.1.53 on 2026-10-20 | Needed |
|
||||
|---|---|---|
|
||||
| OS | Ubuntu 24.04.5, kernel 6.8.0-124, x86_64, 12 cores, 94 GiB, 217 GiB free on `/` | fits |
|
||||
| `mosaic` user, group, `/srv/mosaic` | absent | run sheet section 1 |
|
||||
| node | `/usr/local/bin/node` v22.22.2, root-owned | 24 or later, under `/opt` (run sheet section 2) |
|
||||
| claude | not on localadmin's PATH | under `/opt` (run sheet section 3) |
|
||||
| bwrap | absent; apt candidate `bubblewrap 0.9.0-1ubuntu0.3` | run sheet section 4 |
|
||||
| user namespaces | `kernel.apparmor_restrict_unprivileged_userns = 1`, apparmor 4.0.1, no bwrap profile loaded | run sheet section 4 |
|
||||
| profiles that name bwrap | none (`grep -rlw bwrap /etc/apparmor.d` exits 1) | hostcheck item 3 |
|
||||
| `fs.protected_hardlinks` | 1 | hostcheck item 6 |
|
||||
| `net.ipv4.ip_unprivileged_port_start` | 1024 | run sheet section 5 |
|
||||
| listeners below 1024 | 22 (sshd) and 53 (the resolver); 732 is free | the Console's port |
|
||||
| ports 7330-7333 | free | 7333 is the tester port |
|
||||
| `localadmin` | NOPASSWD sudo (#423 step 1, mos-1066, mos-1077) | ops-01's root path |
|
||||
| `jarvis` | groups sudo, docker, lxd, adm | #423 step 4 removes them (P5) |
|
||||
| unattended-upgrades | on, with the security pocket, which carries bubblewrap | the drift stop (row 240) |
|
||||
| journald | `SplitMode=uid` | the PM check reads `launches list`, not the journal (row 232) |
|
||||
|
||||
## 1. The factory profile's values
|
||||
|
||||
Instance `dev`, row 190's default (mos-1118 choice 4). `~` is `mosaic`'s home.
|
||||
|
||||
| Input | Value | Who gives it |
|
||||
|---|---|---|
|
||||
| user | `mosaic`, primary group `mosaic` with no other member | fixed |
|
||||
| home | `/srv/mosaic`, 0700 | fixed |
|
||||
| config dir | `/srv/mosaic/.config/mosaic-dev` | row 190 |
|
||||
| data root | `/srv/mosaic/.mosaic-dev`, marker `{"instanceVersion":1,"name":"dev"}` | row 190 |
|
||||
| business | `mosaic-stack`, file `<configDir>/businesses/mosaic-stack.json` | fixed (section 7) |
|
||||
| profile | `factory` for `case2-install.sh`, `case2-unit.sh` and `case2-precheck.sh` | fixed |
|
||||
| roles | the factory set from `roles/`, with a chief that has a harness var | the go names the set (section 2) |
|
||||
| human id | Jason's, not `tester` (`broker.mjs:321`) | the go |
|
||||
| model credential | `<configDir>/secrets/claude-session.env`, `mosaic` 0600, one line `CLAUDE_CODE_OAUTH_TOKEN=...` | Jason places it (section 3) |
|
||||
| token slot path | none | section 2 |
|
||||
| node | `/opt/mosaic-stack/node-<v>/bin/node`, `<v>` 24 or later | the go names `<v>` and its sha256 |
|
||||
| claude | `/opt/mosaic-stack/claude-<pin>/node_modules/@anthropic-ai/claude-code/bin/claude.exe`, `<pin>` 2.1.304 unless the go names a newer one | the go |
|
||||
| PM | on (`--pm`) | fixed |
|
||||
| Console | `--port 732` on 127.0.0.1, with the unit's `CAP_NET_BIND_SERVICE` | fixed |
|
||||
| tester | `--tester-port 7333` on 127.0.0.1 (P10) | fixed |
|
||||
| board | none | fixed |
|
||||
| release | a git bundle of `refs/heads/refactor` and the 40-hex commit (run sheet section 6) | the go names both and the bundle's sha256 |
|
||||
|
||||
The args file. `/etc/mosaic-stack/dev.args`, `root:root` 0644, one argument per line (run sheet section 7):
|
||||
|
||||
```
|
||||
--profile
|
||||
factory
|
||||
--user
|
||||
mosaic
|
||||
--home
|
||||
/srv/mosaic
|
||||
--business
|
||||
mosaic-stack
|
||||
--copy
|
||||
<40-hex commit>
|
||||
--node
|
||||
/opt/mosaic-stack/node-<v>/bin/node
|
||||
--claude
|
||||
/opt/mosaic-stack/claude-<pin>/node_modules/@anthropic-ai/claude-code/bin/claude.exe
|
||||
--pm
|
||||
--
|
||||
--port
|
||||
732
|
||||
--business
|
||||
mosaic-stack
|
||||
--tester-port
|
||||
7333
|
||||
```
|
||||
|
||||
`case2-unit.sh` takes exactly these before `--` (`scripts/case2-unit.sh:54`), and `stack-upgrade.sh`
|
||||
refuses `args-unreadable` on anything else (`scripts/stack-upgrade.sh:126-148`). The factory profile
|
||||
refuses the preview trio, `--send` and the proof pair (`case2-unit.sh:169`). .53 has no proxy, and Jason
|
||||
reaches the Console with `ssh -L` (sage-1451 Q3). Changing a serve flag is a re-install with its own go,
|
||||
not an upgrade.
|
||||
|
||||
Why the port is 732 (r6, mos-1101 item 5). Role sessions share the host's network namespace
|
||||
(`packages/seat/src/sandbox.mjs:67`), so while the Console is down a session could bind a port above the
|
||||
floor and answer in its place. Below 1024 only the Console unit can bind, through its capability. The
|
||||
tester port can't go below 1024 (`packages/webui/src/cli.mjs:33`), so P10 records it.
|
||||
|
||||
PATH for `mosaic`'s steps. `sudo -u mosaic -H` resets PATH to sudo's `secure_path`, which finds
|
||||
`/usr/local/bin/node`, v22. So every `mosaic` step runs as
|
||||
`sudo -u mosaic -H env PATH=/opt/mosaic-stack/node-<v>/bin:/usr/local/bin:/usr/bin:/bin ...`, the list
|
||||
`case2-unit.sh` renders as the units' PATH. `stack-upgrade.sh` builds it from the args file's `--node`.
|
||||
|
||||
## 2. Where Case 1 differs from Case 2
|
||||
|
||||
| Case 2 (library) | Case 1 (factory) | Reason |
|
||||
|---|---|---|
|
||||
| business file with the library mapping | `mosaic-stack` with no `library` key. The precheck refuses a library project under `factory` (`profile-library-business`, `case2-precheck.sh:127-128`) | the factory has no books repo |
|
||||
| `bean`, `chet`, persona vars and files, specialists | the factory roles from `roles/`, with a chief that has a harness var | the go names the set. I haven't read Jason's live business file and won't. The acceptance needs only the chief (F3); a chief with no harness var answers `no-route`. The human adds roles later with `instances.set`, no new row |
|
||||
| token slot `library-gitea` | none | the factory's per-agent git identity is row 199's credential store (Megavolt, #1697). Until it lands, git work stays on dragon-lin (Q182) |
|
||||
| `bus.tester` off | on; the precheck refuses it off under `factory` (`case2-precheck.sh:135`) | the acceptance and the Q173 test system need the tester |
|
||||
| persona modes and digests, `library.sync`, `library.status` | skipped | no persona files, no library (C2-13b brief, `factory` profile) |
|
||||
| `ZAI_API_KEY` in `claude-session.env` | not checked; the file holds `CLAUDE_CODE_OAUTH_TOKEN` | no instance has provider `zai` (run sheet section 9) |
|
||||
| no Discord binding (C2-13b, library only) | none either. F11 checks that `<dataRoot>/discord/` holds no binding | the factory's connector stays on dragon-lin. Two connectors on one bot token would split its events |
|
||||
| the claude marker prompt | runs, since the chief's harness is claude-code | |
|
||||
| serve flags: preview trio, `--send`, proof pair | `--port 732`, `--business mosaic-stack`, `--tester-port 7333` | no proxy on .53 |
|
||||
| bus: no `--pm`, no `MOSAIC_CLAUDE_BIN` | `--pm`, and `Environment=MOSAIC_CLAUDE_BIN=<--claude>` | the PM dispatches the factory's work; without the path the bus finds no claude on the unit's PATH |
|
||||
| Console proof file (run sheet section 9, .54) | none | no proof pair |
|
||||
|
||||
All of these are inputs to the landed scripts. Row 230 implemented the four factory items r6 asked for
|
||||
(serve flags, `--pm`, `--claude`, row 190's tokens), and nothing in them hardcodes a Case 1 value.
|
||||
|
||||
## 3. Model access
|
||||
|
||||
Q185: Case 1 uses the account the factory uses today, the Claude subscription behind dragon-lin's
|
||||
`claude-session.env`. No script copies that file and none reads its value. In the window, Jason, or the
|
||||
person he names under the Q173 secrets rule, makes a credential for .53 from that account and writes it
|
||||
to `/srv/mosaic/.config/mosaic-dev/secrets/claude-session.env` as `mosaic`, mode 0600 (run sheet
|
||||
section 9). Nobody prints it. The check is `stat -c '%U %a %F' PATH` only (F8).
|
||||
|
||||
The bus unit reads it through `EnvironmentFile=-` (`case2-unit.sh:243`). The leading `-` means a missing
|
||||
file doesn't stop the bus, so the chief's first launch would fail instead. The window places the file
|
||||
before the units start (section 6, W9), and the precheck's claude marker prompt then proves it works
|
||||
without printing it.
|
||||
|
||||
Quota: the factory on dragon-lin and on .53 share one subscription. Q185's "use existing" accepts that.
|
||||
The pi harness stays off on .53 until P19 #383 settles (mos-0865). The business file names claude only.
|
||||
|
||||
## 4. Upgrade, rollback and backup on .53
|
||||
|
||||
All three are `scripts/stack-upgrade.sh` (row 233), run as root by ops-01 from `/root/mosaic-stack` at the
|
||||
reviewed commit. Usage, exits and the step log are in `docs/TOOLS.md`, "Root's upgrade driver", and run
|
||||
sheet section 6.
|
||||
|
||||
| Action | Command | Who | Go |
|
||||
|---|---|---|---|
|
||||
| upgrade | `stack-upgrade.sh upgrade --instance dev --bundle /srv/mosaic/incoming/<sha>.bundle --sha <sha>` after run sheet section 6's per-upgrade lines | ops-01 | Mos per run; `--migrate` also needs Jason present (decision 96) |
|
||||
| rollback | `stack-upgrade.sh rollback --instance dev --to <copy> [--restore <ACT> [--events N]]` | ops-01 | Mos per run. Mos or Sage picks `<copy>` from `stack-release.sh status mosaic-stack --units external`, read as `mosaic`. The plan refuses unless it is the previous distinct copy |
|
||||
| backup of the store | A3's `backup_store` into `<dataRoot>/backups/stack/<ACT>`, inside every upgrade | the driver | the upgrade's |
|
||||
| rehearsal | `stack-release.sh rehearse` against the log's newest backup, before anything stops, on `--rehearse-port`, default 7339, which section 0 found free | the driver | the upgrade's |
|
||||
| backup of the VM | a PBS backup of VM 1008 before the install window and before any `--migrate` | ops-01 | the window's go (Q182, Q183: agents keep PBS) |
|
||||
|
||||
Three .53 specifics:
|
||||
|
||||
1. The first upgrade after install needs `--no-rehearsal` in its go. The install's adopt takes no backup,
|
||||
so the log records none, the rehearsal exits 3 (`no-backup`), and the driver goes on only with the
|
||||
flag (`stack-upgrade.sh:323-324`). Every later upgrade refuses the flag (`rehearsal-required`).
|
||||
2. Exit 5 (`args-failed`): the new stack is live and confirmed, but `dev.args` still names the old copy.
|
||||
ops-01 moves the file the result line names into place with `mv -f`, and nothing else (run sheet
|
||||
section 6).
|
||||
3. Exit 2 leaves both units stopped and the activation open. ops-01 sends Mos the exit and the last
|
||||
lines of `/var/log/mosaic-stack/upgrade-dev.log`, and Jason or Mos settles it with `confirm` or `revert`
|
||||
as on dragon-lin. A unit that doesn't stop within `--timeout` ends here on purpose (A2f's
|
||||
`stale-start`, duckworth-0055 N1, now in run sheet section 6).
|
||||
|
||||
The store backup doesn't hold the config dir or the credential. PBS backups of VM 1008 hold the whole disk,
|
||||
the credential included (P4). A restore swaps only the store and leaves `claude-session.env` in place.
|
||||
|
||||
Re-install, for a serve flag or role change, is not an upgrade. It needs its own go and runs: stop the
|
||||
Console, then the bus; rewrite `dev.args` with the same `--copy`; `case2-unit.sh` with it; both units start
|
||||
again from the render. Row 230 N1 (webby-0046) holds here: a re-render with the units running leaves each on
|
||||
its old copy, so ops-01 stops both first. `stack-upgrade.sh` already stops both before it renders.
|
||||
|
||||
## 5. Acceptance: `scripts/case1-accept.sh`
|
||||
|
||||
New in this row. ops-01 runs it as root on .53, from `/root/mosaic-stack`:
|
||||
|
||||
```
|
||||
case1-accept.sh --business mosaic-stack --args /etc/mosaic-stack/dev.args --claude-pin <pin> --node-pin <v>
|
||||
```
|
||||
|
||||
It reads the user, home, node, claude and ports from the args file and refuses (exit 2) when that file
|
||||
fails `stack-upgrade.sh`'s rules. Every check inside the instance runs as
|
||||
`sudo -u mosaic -H env PATH=<node dir>:/usr/local/bin:/usr/bin:/bin`. It changes nothing on the host
|
||||
except what F3's message writes to the store. It prints one line per check, `<id> <path> <mark>
|
||||
<evidence>`, then a count of each mark. Marks: `closed`, `accepted Q182`, `accepted Q183`, `accepted
|
||||
mos-1096`, `accepted mos-1101`, and `unnamed`, which means "not named in Q182, Q183 or a Mos ruling".
|
||||
It exits 1 when any F check fails and 0 otherwise. A P check never changes the exit. Each `unnamed`
|
||||
line goes to Mos, who takes it to Jason (R8 N1). Duckworth reads the whole output.
|
||||
|
||||
It prints no value from `claude-session.env` and never opens it.
|
||||
|
||||
Functional checks. Any failure fails the row:
|
||||
|
||||
| Id | Check | How |
|
||||
|---|---|---|
|
||||
| F1 | the units run as `mosaic` | for `[email protected]` and `mosaic-webui.service`: active, `User=mosaic`, and the uid in `/proc/<MainPID>/status` is `mosaic`'s |
|
||||
| F2 | the Console answers on 127.0.0.1:732 only | `curl -fsS http://127.0.0.1:732/healthz` succeeds, and `ss -Hltnp` shows 732 bound to 127.0.0.1 only, by the Console's MainPID. Jason reaches it with `ssh -L 7332:127.0.0.1:732 [email protected]`. A LAN listener waits for Q175 SSO (sage-1451 Q3) |
|
||||
| F3 | one tester message gets a reply | as `mosaic`: `mosaic talk chief <marker> --business mosaic-stack --tester --wait 300`. A stored reply to the marked message passes. The inbox shows decisions only, so it isn't used |
|
||||
| F4 | the precheck passes | `case2-precheck.sh --business mosaic-stack --profile factory` as `mosaic` exits 0 |
|
||||
| F5 | a role session runs under bwrap with the profile | while F3's reply is pending: a `/usr/bin/bwrap` process owned by `mosaic` has a claude child. Its `/proc/<pid>/attr/current` equals `bwrap (enforce)` and the child's equals `bwrap//&unpriv_bwrap (enforce)`, exact strings after the trailing newline is cut |
|
||||
| F6 | claude is the pin | the args file's `--claude` path sits under `/opt/mosaic-stack/claude-<pin>/`, and its `--version` as `mosaic` prints `<pin> (Claude Code)` |
|
||||
| F7 | the PM run is live | `launches list --json` as `mosaic` has exactly one live entry for the PM's instance (`launch.by`), the check `confirm` runs |
|
||||
| F8 | the credential's file | `stat -c '%U %a %F'` on `claude-session.env` reads `mosaic 600 regular file`, and it isn't a symlink. Run sheet section 9 marks this "precheck line missing" |
|
||||
| F9 | the autoupdater is off | `/etc/claude-code/managed-settings.json` is `root:root` 0644 and its `env.DISABLE_AUTOUPDATER` is `"1"`. Run sheet section 3 marks this "precheck line missing" |
|
||||
| F10 | node is the pin | the args file's `--node` is `/opt/mosaic-stack/node-<v>/bin/node` with `<v>` the `--node-pin`, and its `--version` prints `<v>`. Run sheet section 2 marks this "precheck line missing" |
|
||||
| F11 | no Discord binding | `/srv/mosaic/.mosaic-dev/discord/` is absent or holds no `*.json` (section 2) |
|
||||
|
||||
Host paths. These report and never fail the row:
|
||||
|
||||
| Id | Path | Mark | Evidence |
|
||||
|---|---|---|---|
|
||||
| P1 | `mosaic` has sudo | closed only when `sudo -l -U mosaic` prints "is not allowed to run sudo"; any other output is unnamed | the `sudo -l` result |
|
||||
| P2 | `mosaic` has supplementary groups or a key | closed when `id -G mosaic` is one entry and `~mosaic/.ssh/authorized_keys` is absent or empty | `id`, file state |
|
||||
| P3 | `localadmin` NOPASSWD sudo, reached with the dragon-lin key | accepted Q183 | `sudo -l -U localadmin` |
|
||||
| P4 | root on pve over VM 1008, and PBS backups that hold `/srv/mosaic` with the credential | accepted Q182 and Q183 | a fixed line; the script can't see pve |
|
||||
| P5 | `jarvis`, which runs Hermes, reaches `/srv/mosaic` through sudo, docker or lxd | closed when `jarvis` is in none of the three; unnamed otherwise. #423 step 4 removes all four groups before the install (mos-1091 4c) | `id jarvis` |
|
||||
| P6 | other members of sudo, docker, lxd | closed when sudo holds only `localadmin` and docker and lxd are empty; each other member is its own unnamed line | `getent group` lines |
|
||||
| P7 | a file under `/etc/sudoers.d` naming `mosaic` | closed when none | file names |
|
||||
| P8 | the Console or tester reachable from the LAN | closed when 732 and 7333 are bound to 127.0.0.1 only, each by the Console's MainPID, and nothing listens on 7331 | listener table |
|
||||
| P9 | a user namespace through `/usr/bin/bwrap` | accepted mos-1096 only while all eight hold, unnamed otherwise: hostcheck items 1 to 6, read from `/usr/local/lib/mosaic-stack/hostcheck.sh --check`'s own `ok N` lines (item 7 is P10's floor); `sudo -u jarvis /usr/bin/bwrap --version` fails with "Permission denied"; `getent group mosaic` lists no member and no other account has its gid. F5 adds the label of a real role session | the hostcheck lines and each item |
|
||||
| P10 | a session binds the tester port 7333 while the Console is down | accepted mos-1101 while the port floor is above 732 and 7333 is held by the Console's MainPID | the floor, the owner pid |
|
||||
| P11 | the boot check runs before the bus | closed when `mosaic-hostcheck.service` is enabled and `systemctl show -p Before` on it names `mosaic-bus@<business>.service` for the args file's business; unnamed otherwise (section 7) | the `Before=` value |
|
||||
|
||||
P9 reads hostcheck's output, which root's own script prints, by matching `^ok [1-6] ` lines. It runs `--check` only,
|
||||
never `--enforce`, so the acceptance can't close bwrap.
|
||||
|
||||
Tests, in `packages/cli/tests/case1-accept.test.mjs`. The script takes a test seam, `--root DIR`, for
|
||||
`/proc`, `/etc`, `/srv/mosaic` and `getent`, and refuses it when run as root, as the hostcheck does. Fake
|
||||
`systemctl`, `curl`, `ss`, `sudo`, `bwrap`, `sysctl`, `stat`, `claude`, `node` and `hostcheck.sh` on PATH.
|
||||
Nothing reaches .53 or dragon-lin's live state, and no test reads a real credential. Cases:
|
||||
- every check passing exits 0, with the counts matching the lines;
|
||||
- each F check failing alone exits 1 with its line;
|
||||
- F5 fails on `unpriv_bwrap (enforce)`, `bwrap//&unpriv_bwrap (complain)` and a trailing space;
|
||||
- F6 fails on a stub `claude.exe` that prints nothing and on a path outside `claude-<pin>`;
|
||||
- F8 fails on mode 0640, on another owner and on a symlink, and the stand-in credential's value never
|
||||
appears in the output;
|
||||
- F11 fails on one `*.json` under `discord/`;
|
||||
- each P check in each of its marks: P1 with output that grants nothing but lacks the refusal text
|
||||
(unnamed), P9 unnamed once for each item missing, P10 unnamed with the floor at 700 and with 7333 held
|
||||
by another pid, P11 unnamed with `Before=` naming another business;
|
||||
- every P check `unnamed` still exits 0;
|
||||
- a bad args file refuses with exit 2 before any check;
|
||||
- every in-instance call goes through `sudo -u mosaic -H env PATH=<node dir>:...`, read from the fake
|
||||
`sudo`'s recorded argv;
|
||||
- the hostcheck fake records `--check` and never `--enforce`.
|
||||
|
||||
Mutants, each killed by a named case:
|
||||
1. F1 passes on a MainPID owned by root.
|
||||
2. F2 accepts a listener on 0.0.0.0.
|
||||
3. F3 passes without a reply.
|
||||
4. F5 matches a substring.
|
||||
5. F6 skips the `--version` check.
|
||||
6. F8 skips the owner check.
|
||||
7. F11 ignores `discord/`.
|
||||
8. P1 closes on any output.
|
||||
9. P5 maps to `closed` with `jarvis` in docker.
|
||||
10. P9 drops the jarvis item.
|
||||
11. P11 accepts any `Before=`.
|
||||
12. A P check's `unnamed` sets the exit to 1.
|
||||
|
||||
## 6. The .53 window
|
||||
|
||||
Nothing in this row touches .53 (sage-1809). Every root step below is ops-01's, over
|
||||
`ssh [email protected]` with `sudo`, and waits on a Jason decision (mos-1086). The window needs:
|
||||
- row 226 landed;
|
||||
- Jason's or Mos's go naming the commit, the bundle's sha256, the node and claude pins, the role set and
|
||||
Jason's human id;
|
||||
- a backup first;
|
||||
- a STATE report after.
|
||||
|
||||
| # | Step | Runs as | Source |
|
||||
|---|---|---|---|
|
||||
| W0 | re-read section 0's items; stop on any change and report it | `localadmin`, read only | section 0 |
|
||||
| W1 | PBS backup of VM 1008 | ops-01 on pve | section 4 |
|
||||
| W2 | the stack's user and home | root | run sheet 1 |
|
||||
| W3 | node under `/opt` | root | run sheet 2 |
|
||||
| W4 | claude under `/opt`, managed settings | root | run sheet 3 |
|
||||
| W5 | bubblewrap, the profile, the statoverride, the no-new-privs test, the drift stop; `hostcheck.sh --check` exits 0 with item 7 at 1023 | root | run sheet 4 |
|
||||
| W6 | the port floor (read) | root | run sheet 5 |
|
||||
| W7 | the bundle, root's checkout at `<sha>`, `mosaic`'s clone | root, then `sudo -u mosaic -H` | run sheet 6 |
|
||||
| W8 | `case2-install.sh --profile factory` with section 1's inputs: bootstrap, the business file, roles, human id, the copy | `sudo -u mosaic -H env PATH=...` | row 226 |
|
||||
| W9 | place `claude-session.env` | Jason, or who he names | run sheet 9, section 3 |
|
||||
| W10 | write `dev.args` (section 1); `case2-unit.sh` from it, which enables both units and starts the bus, then the Console | root | run sheet 7, 10 |
|
||||
| W11 | `case2-precheck.sh --business mosaic-stack --profile factory` exits 0; `hostcheck.sh --check` exits 0 with item 7 at 732 | `mosaic`; root | row 230, 240 |
|
||||
| W12 | `stack-release.sh adopt mosaic-stack --units external`, unless row 226's install does it | `sudo -u mosaic -H` | row 232 |
|
||||
| W13 | `case1-accept.sh` (section 5); the output to Duckworth, then Mos confirms | root | this row |
|
||||
| W14 | STATE report to Mos | ops-01 | brief |
|
||||
|
||||
Install rollback, any step before W13 passes. Stop and disable both units, remove their files and
|
||||
`dev.args`, then the run sheet's rollbacks for sections 4, 3 and 2 in that order. Removing the user and
|
||||
home (`userdel -r mosaic`) needs its own Mos go, since it deletes the home. W1's backup covers the rest.
|
||||
|
||||
What row 195 needs from row 226. Row 226 is assigned to Gosalyn, briefed and not started, so I'm listing what the window
|
||||
needs from its design, not designing it:
|
||||
|
||||
1. `--profile factory` writes the business file with `bus.tester` on and no `library` key, and the roles
|
||||
the go names.
|
||||
2. It writes no token slot and no persona files (its brief says so).
|
||||
3. It runs before the unit render, since the copy must exist for `case2-unit.sh --copy`, and it starts no
|
||||
unit.
|
||||
4. Who writes `dev.args`. The C2-13b brief says the install doesn't write unit files, and the run sheet
|
||||
says "I2's install writes it". `mosaic` can't write `/etc/mosaic-stack`. So either root's part of I2
|
||||
writes it, or ops-01 writes it from section 1 at W10. Either works for row 195. The file's content is
|
||||
fixed above.
|
||||
5. Whether it runs `adopt`. If it doesn't, W12 does.
|
||||
|
||||
I sent these to Gosalyn on 2026-10-21 (gosalyn-0085 acknowledged), and the run sheet takes whichever answer 226 gives.
|
||||
|
||||
## 7. The business id
|
||||
|
||||
.53's business id is `mosaic-stack` (sage-1813). It appears in:
|
||||
- the args file, twice;
|
||||
- the bus unit `[email protected]`;
|
||||
- the business file name;
|
||||
- `case1-accept.sh --business`.
|
||||
|
||||
The landed boot unit `packages/cli/systemd/mosaic-hostcheck.service` has
|
||||
`[email protected]`. So at boot the drift stop runs before .53's bus, and DEFERRED 240
|
||||
N1 (da3051ccc: `After=mosaic-hostcheck.service` in `mosaic-bus.service.in`) doesn't bind this row.
|
||||
|
||||
If a go ever names another id for .53, the window stops before W8, and the N1 fix lands first as its own
|
||||
reviewed row. P11 is the check on the host. It reads `unnamed` when the boot unit's `Before=` doesn't
|
||||
name the installed bus.
|
||||
|
||||
DEFERRED 240 N2 (the apt hook goes in before the first `--check`) is a run sheet order note. This row
|
||||
doesn't edit the run sheet, so it stays deferred.
|
||||
|
||||
## 8. Rulings this design rests on
|
||||
|
||||
- sage-1451: Q1 system units; Q3 the Console on 127.0.0.1 with `ssh -L`; Q4 a rebase goes to a new branch
|
||||
name (#426(a), mos-1086).
|
||||
- mos-1091, mos-1096, mos-1098, mos-1101: the bwrap path, its profile and P9; the port squat and P10; .53
|
||||
runs the PM. Their r6 sections stand, and rows 232, 233, 240 and 230 implemented them.
|
||||
- mos-1108 (Q187) and mos-1118: the installer rows and the scope cut. mos-1122 (Q189): both units start at
|
||||
boot.
|
||||
- sage-1522: claude under `/opt`, root-owned.
|
||||
- sage-1809: no step on .53, root steps named and left to ops-01, the business id stated.
|
||||
- sage-1813: 226 in the after list (rev 2718); the id is `mosaic-stack` and 240 N1 doesn't apply.
|
||||
- Q185: the factory's model account. Q173: credentials placed by Jason or his named person.
|
||||
|
||||
## 9. Manifest (planned)
|
||||
|
||||
- `scripts/case1-accept.sh` (new), mode 100755.
|
||||
- `packages/cli/tests/case1-accept.test.mjs` (new). Section 5's cases and mutants.
|
||||
- `docs/TOOLS.md`: a `case1-accept.sh` entry with usage, marks and exits, beside the hostcheck entry.
|
||||
- `agents/darkwing/work/queue-195/BUILD.md` (new): run environment, the mutant results, deviations.
|
||||
- No change to `case2-*.sh`, `stack-upgrade.sh`, `stack-release.sh`, `case1-hostcheck.sh` or the run
|
||||
sheet. Two follow-ups stay out of this row:
|
||||
- row 230 r2 N1. The "still on copy" line reads the id from the unit file. On .53 neither the install
|
||||
nor `stack-upgrade.sh` reaches that line, since both start from stopped units.
|
||||
- DEFERRED 240 N2.
|
||||
- No change to `~/.mosaic-dev`, `~/.config/mosaic-dev`, dragon-lin's units or `~/.mosaic`.
|
||||
|
||||
Gate: Duckworth approves this design, then the manifest; the cli suite and every `scripts/test-*.sh`
|
||||
green on Sage's gate; section 5's twelve mutants killed in a slot Sage grants.
|
||||
@@ -1,249 +0,0 @@
|
||||
# Row 233 (I3): root's upgrade driver and the host run sheet
|
||||
|
||||
Brief: `docs/plans/2026-10-20_installer-rows.md` section I3, blob `e61291bcf1c6` (commit a0e3d7cfd), re-pinned
|
||||
by Sage (sage-1685, rev 2631) from `f35e7e57daee` (ad6f0be7a). The later blob only appends I4; the I3 text
|
||||
is the same. Gitea #1735, Vikunja P19
|
||||
#432. Owner Darkwing, reviewer Filbert, gate owner Sage. Design input: row 195 DESIGN r6,
|
||||
`agents/darkwing/work/queue-195/DESIGN.md` at b7239bb66, sections 2, 4 and 7. Where the brief and r6
|
||||
differ, the brief wins. Sage's rulings during the build: sage-1650 and sage-1652 (`--backup last`, the
|
||||
`--no-rehearsal` mapping, `--rehearse-port`, hostcheck), and sage-1653 (`from_log newest`, the two external
|
||||
plan refusals, the `BACKUP_STORE` line).
|
||||
|
||||
## Files
|
||||
|
||||
Base: e65a3ab4d, row 232's landing, on `darkwing/row233-r1`. The build started on ea1e85c7b
|
||||
(`darkwing/row233`, row 232's candidate e6ca230d2 and its BUILD.md) before row 232 landed. The three row 232
|
||||
files this row changes are identical on the two bases, so the uncommitted diff moved across unchanged.
|
||||
|
||||
- `scripts/stack-upgrade.sh` (new): `upgrade` and `rollback`, root's side of r6 A1-A5, A2f and R1-R4.
|
||||
- `packages/cli/tests/stack-upgrade.test.mjs` (new, 20 tests).
|
||||
- `docs/guides/host-run-sheet.md` (new).
|
||||
- `docs/TOOLS.md`: a new subsection "Root's upgrade driver (`scripts/stack-upgrade.sh`, row 233)", plus the
|
||||
row 232 lines below.
|
||||
- Row 232 files, changed on Sage's rulings (the brief's files list doesn't name them):
|
||||
- `scripts/stack-release.sh`:
|
||||
- `rehearse --backup last` takes the newest backup the log records (`from_log newest`) and prints
|
||||
`PASS backup-last`. With none it fails `no-backup`, exits 3 and makes no rehearsal directory.
|
||||
A newest backup that isn't an activation id aborts `backup-unreadable`, exit 1.
|
||||
- The rehearsal prints `BACKUP_STORE <activation id> schema <version>` before its migration step.
|
||||
- `--plan` under `--units external` refuses `open-activation` when any rollback set holds
|
||||
`AWAITING-UNITS`, and `migrate-required` for a migrating target without `--migrate`. Root reads
|
||||
only the plan's exit, so these two have to be refusals there. User mode prints the same bytes.
|
||||
- `packages/cli/tests/stack-release.test.mjs`: three new `row 233:` tests for `--backup last`.
|
||||
- `docs/TOOLS.md`: `--backup ACTIVATION|PATH|last` in the rehearse usage, a paragraph on `last`, and a
|
||||
paragraph on the two external plan refusals.
|
||||
- This file.
|
||||
|
||||
## The brief, item by item
|
||||
|
||||
| Brief item | Where |
|
||||
|---|---|
|
||||
| Root runs from a root-owned checkout, never a copy | `head-mismatch` (A1); TOOLS.md; run sheet section 6 |
|
||||
| I2's render with `/etc/mosaic-stack/<instance>.args`, `--copy` the one changed value | `read_args`, `args_with`; the args test |
|
||||
| The args file changes only after a confirmed run | `prepare_args` before A2, `mv` after A5; sequences 1 and 7, m6 |
|
||||
| `copy --bundle` as the stack's user before A1 | the `fetch`, `ff`, `copy` steps; sequence 1's sudo keys |
|
||||
| A rehearsal before A2, a failed one refuses with nothing stopped | `rehearse`; three rehearsal tests, m4 |
|
||||
| The root lock, held to the end, rollback included | `flock -n 9`; the lock test and sequence 3's probe, m1, m2 |
|
||||
| A1 refuses `open-activation` | stack-release.sh's external plan; the AWAITING-UNITS test, m3 |
|
||||
| `migrate-required` without `--migrate` | stack-release.sh's external plan; its test, m5 |
|
||||
| The step log, 0640, one line per step | `logl`, `step`; every test checks lines against `STEP` |
|
||||
| Exit codes 0-3 | `finish`, `refuse`; exit 4 is usage |
|
||||
| duckworth-0055's notes | the next section |
|
||||
| Root parses no stack user output beyond exits | the step log test; the one exception is sage-1653's `BACKUP_STORE` |
|
||||
| The host run sheet | `docs/guides/host-run-sheet.md` |
|
||||
|
||||
## duckworth-0055's notes on r6 (brief line 169)
|
||||
|
||||
- N1, A2's stop timeout under `gate --since`. Row 232's BUILD.md left two pieces to I3. The run sheet's
|
||||
A2f line is in section 6 ("When a run doesn't exit 0", exit 2). The test is `N1: a bus that outlives
|
||||
A2's timeout keeps its old start`: a bus that ignores `stop` keeps its old `ActiveEnterTimestamp`,
|
||||
`wait-down` logs `rc=1 ... state: active`, A2f restarts and gates, the gate fails `stale-start`, and the
|
||||
driver stops both units and exits 2. Sequence 4 is the other half: an A3 exit 3 goes to A2f and exits
|
||||
1 with the old copy's gate passing.
|
||||
- N2, the claude path under `/opt/mosaic-stack`. Run sheet section 3 installs it there as root with
|
||||
managed settings. The args file's `--claude` carries it, and `case2-unit.sh` already refuses a binary
|
||||
that isn't root's or sits under the home. The driver passes the args file through and adds no claude
|
||||
check of its own. F6 is I2's.
|
||||
|
||||
## Sage's rulings during the build
|
||||
|
||||
- sage-1650 and sage-1652. Root always runs the rehearsal and maps its exit:
|
||||
- 0 goes on, or refuses `rehearsal-required` with `--no-rehearsal`.
|
||||
- 3 refuses `no-backup`, or with `--no-rehearsal` logs `rehearsal-skipped` and goes on.
|
||||
- Anything else refuses `rehearsal-failed`.
|
||||
|
||||
`--rehearse-port N`, default 7339. Hostcheck: a missing file or a nonzero `--check` refuses
|
||||
`profile-drift`.
|
||||
- sage-1653. `from_log newest`, and the external plan refusals `open-activation` and `migrate-required`.
|
||||
Residual: the `BACKUP_STORE` id and schema land in root's step log, but nothing ties that backup to the
|
||||
one the activation's own backup step takes later. A stopped backup before the upgrade would close that
|
||||
gap; it's a later row, not this one.
|
||||
|
||||
## Tests
|
||||
|
||||
`stack-upgrade.test.mjs` runs the driver as the test's user against a scratch root, with the test seams
|
||||
`STACK_UPGRADE_*`. The stand-ins are a fake `sudo` (logs its argv, checks the driver's form, then runs the
|
||||
real command as the test's user, r6's B1 pattern), a fake `case2-unit.sh` render that installs and starts
|
||||
the fixture units, a fake `systemctl` for root's system units, and a shell `hostcheck.sh`. The stack's
|
||||
user's steps run the real `stack-release.sh` and `stack-copy.sh` from a clone made from a real bundle. The
|
||||
units, copies and store are `stack-release-fixture.mjs`'s.
|
||||
|
||||
| Test | Covers |
|
||||
|---|---|
|
||||
| sequence 1 | confirm fails healthz, rollback with `--cause A5`, exit 1; every sudo call in the driver's form |
|
||||
| sequence 2 | `activate --migrate` fails at the wrapper, store restored, `--cause A3`, exit 1 |
|
||||
| sequence 3 | render fails, `--cause A4`; a probe run during `render-old` refuses `upgrade-running` |
|
||||
| sequence 4 | stage exits 3, A2f restarts and gates the old units, exit 1 |
|
||||
| N1 | a unit that won't stop: A2f's gate fails `stale-start`, exit 2, units stopped |
|
||||
| sequence 5 | confirm of the wrong copy refused, `--cause A5`, exit 1 |
|
||||
| sequence 6 | revert fails, exit 2; the next run refuses `interrupted-run` at its plan |
|
||||
| sequence 7 | two upgrades and a `rollback --to` with `--restore`; the args file after each confirm; `to-not-previous` |
|
||||
| sequence 8 | a migration that writes and fails, store back byte for byte, exit 1 |
|
||||
| lock | a second run while the lock is held: one log line, no call |
|
||||
| open-activation | any `AWAITING-UNITS` refuses at A1, nothing stopped |
|
||||
| migrate-required | refused without `--migrate`, no rehearsal, nothing stopped |
|
||||
| rehearsal-failed | the rehearsal's argv, exit 3, nothing stopped |
|
||||
| `BACKUP_STORE` | the line after a match; four malformed lines log `BACKUP_STORE none` |
|
||||
| no-backup | the real rehearsal with no backup refuses; `--no-rehearsal` logs the skip and goes on |
|
||||
| backup-last | the real rehearsal names the newest backup; `--no-rehearsal` with one refuses `rehearsal-required` |
|
||||
| args file | group write, other write, two `--copy`, an unknown flag, a symlink, `args-differ` |
|
||||
| hostcheck | nonzero `--check` and a missing file refuse `profile-drift` before the plan |
|
||||
| head-mismatch | checkout not at `--sha`; a commit the clone can't fast-forward to refuses `fetch-failed` |
|
||||
| usage | twelve bad argvs exit 4 with no log and no lock |
|
||||
|
||||
The step log check (`STEP`) runs in every test that reads the log: each line must be a step line or the
|
||||
result line, and none may hold the stack user's output (`stack-release:`, `PASS `, `FAIL `, `REHEARSAL`,
|
||||
the fake rehearsal's text).
|
||||
|
||||
## Mutants
|
||||
|
||||
`~/darkwing-scratch/r233/mutants.sh`, not committed because it edits the worktree. It has the brief's six
|
||||
mutants and two for sage-1650's mapping. The method is row 232's: a checked backup, exact replacements, a
|
||||
syntax check, the named killers, then the file put back with its sha256 checked. One control runs first:
|
||||
the whole `stack-upgrade.test.mjs` with no change. `DRY=1` matched each replacement once on the candidate
|
||||
(2026-10-21).
|
||||
|
||||
| Mutant | File | Killers |
|
||||
|---|---|---|
|
||||
| m1 drop the flock | stack-upgrade.sh | `a second run while the lock is held`, `sequence 3:` |
|
||||
| m2 release the lock when the rollback starts | stack-upgrade.sh | `sequence 3:` |
|
||||
| m3 skip A1's open-activation check | stack-release.sh | `A1 refuses open-activation` |
|
||||
| m4 skip the rehearsal | stack-upgrade.sh | `the rehearsal runs after the plan`, `sequence 1:` |
|
||||
| m5 accept a migrating target without `--migrate` | stack-release.sh | `migrate-required` |
|
||||
| m6 write the args file before confirm | stack-upgrade.sh | `sequence 7:`, `sequence 1:` |
|
||||
| m7 `--no-rehearsal` accepted with a backup | stack-upgrade.sh | `refuses rehearsal-required` |
|
||||
| m8 drop the `rehearsal-skipped` line | stack-upgrade.sh | `a real rehearsal with no backup` |
|
||||
|
||||
## Deviations
|
||||
|
||||
D1. The brief has A1 refuse `open-activation` for an open `AWAITING-UNITS` or a non-empty `interrupted`
|
||||
set. The interrupted case refuses with row 232's existing code, `interrupted-run`; only `AWAITING-UNITS`
|
||||
gives `open-activation`. Both reach root as `plan-refused`, exit 3 (sequence 6, the open-activation test).
|
||||
|
||||
D2. Root copies one line of the stack user's output into its log, `BACKUP_STORE`, on sage-1653. It
|
||||
matches a fixed pattern first, takes the last match, logs `BACKUP_STORE none` otherwise, and decides
|
||||
nothing on it.
|
||||
|
||||
D3. The stack user's steps carry no `--instance`. The driver takes `--instance dev` only, row 190's default
|
||||
instance, which the stack user's commands select with no flag. A named instance's units are a later row.
|
||||
|
||||
D4. Most tests fake the rehearsal in the fake `sudo`: the fixture's stub copies can't pass a real one. Two
|
||||
tests run the real rehearsal (`faults/real-rehearse`): no-backup and backup-last. `stack-release.test.mjs`
|
||||
covers `--backup last` itself.
|
||||
|
||||
D5. Any nonzero `--plan` exit refuses `plan-refused`, exit 3, whatever the code. The stack user's output
|
||||
above it names the refusal; root doesn't parse it.
|
||||
|
||||
D6. `rollback --restore ACT` is accepted without `--events`, as `stack-release.sh rollback` accepts it.
|
||||
The brief's usage pairs them. `--events` without `--restore` is a usage error.
|
||||
|
||||
D7. The refusal of any `STACK_UPGRADE_*` seam when run as root has no test, because the tests don't run
|
||||
as root. It is three lines at the top of the script.
|
||||
|
||||
D8. The fake `sudo` keeps the test's environment, where real `sudo` resets it. The driver passes
|
||||
everything the stack user needs through `env PATH=...` and `-H`, and the fake checks that form.
|
||||
|
||||
D9. Exit 3 means nothing stopped, not nothing changed. A refusal after `fetch` leaves the stack user's
|
||||
clone fast-forwarded and the new copy made. Both are the user's own state, and the next run reuses them.
|
||||
TOOLS.md and the run sheet say so.
|
||||
|
||||
D10. The brief's usage has neither `--no-rehearsal` nor `--rehearse-port`. Both come from sage-1650 and
|
||||
sage-1652.
|
||||
|
||||
## Decisions
|
||||
|
||||
- `rollback` has no HEAD check. Its target is an older copy than root's checkout, which already exists.
|
||||
It fetches, copies and rehearses nothing (sequence 7).
|
||||
- The new args file is written next to the old one (`.dev.args.XXXXXX`, same mode) before A2, so a full
|
||||
`/etc` refuses before anything stops. It moves into place after A5. A2f and the rollback remove it; a failed move keeps it and names it.
|
||||
- Every stack user step gets `--copies` explicitly, so the copies directory comes from the args file's
|
||||
`--home`, never from the user's environment.
|
||||
- The stack's user does the fetch, the fast-forward and the copy, so root never runs git on a tree that
|
||||
user can write.
|
||||
- A4 is the render, and `case2-unit.sh` starts the bus, then the Console. The forward path has no
|
||||
`systemctl start` of its own; only A2f does.
|
||||
|
||||
## Run environment
|
||||
|
||||
Worktree `/mnt/storage/scratch/darkwing-r233`, `TMPDIR=/mnt/storage/scratch/tmp/r233`, node from PATH. One
|
||||
whole `stack-upgrade.test.mjs` run takes about 56 s.
|
||||
|
||||
## Results
|
||||
|
||||
### Singles, run 1, 2026-10-21, Sage's slot (sage-1689)
|
||||
|
||||
`~/darkwing-scratch/r233/singles.sh` on `darkwing/row233-r1` (base e65a3ab4d, uncommitted tree), 03:48:20Z
|
||||
to 03:59:00Z. These are the test files that read a changed script. `stack-instances.test.mjs` reads
|
||||
`stack-release.sh`, so it joined the three named in the plan.
|
||||
|
||||
| File | Result |
|
||||
|---|---|
|
||||
| `stack-upgrade.test.mjs` | 20 pass, 0 fail |
|
||||
| `stack-release.test.mjs` | 194 pass, 1 fail |
|
||||
| `stack-release-external.test.mjs` | 25 pass, 0 fail |
|
||||
| `stack-instances.test.mjs` | 23 pass, 0 fail |
|
||||
|
||||
The failure was my test, not the script. "row 233: --backup last takes the newest backup..." compares
|
||||
`untouched(e)` before and after the run, and `untouched` includes `existsSync(e.log)`. The test took its
|
||||
before snapshot ahead of `rlog()`, which writes the log, so that flag went from false to true. Every hash in
|
||||
the snapshot matched. The fix takes the snapshot after `rlog()`. No other row 233 test calls `untouched`.
|
||||
|
||||
### Singles, run 2
|
||||
|
||||
`~/darkwing-scratch/r233/rerun.sh` on aacfa2d7a, Sage's slot (sage-1695), 04:13:05Z to 04:21:28Z:
|
||||
`stack-release.test.mjs` whole, 195 pass, 0 fail, 0 skipped. The fixed test passed. The other three files
|
||||
did not change after run 1. The gate and the mutants run next, in Sage's slot.
|
||||
|
||||
### Gate and mutants, 2026-10-21, Sage's slot (sage-1704)
|
||||
|
||||
`~/darkwing-scratch/r233/gate.sh` then `mutants.sh`, chained behind `busy.sh`, on d99166ade (code
|
||||
aacfa2d7a; d99166ade changes only this file). Counts are an awk sum over `gate-r1.out`.
|
||||
|
||||
| Part | Time (UTC) | Result |
|
||||
|---|---|---|
|
||||
| cli suite (`node --test tests/*.test.mjs`) | 04:29:01-04:37:27 | 616 pass, 0 fail, 0 skipped |
|
||||
| the 10 `scripts/test-*.sh` | 04:37:27-04:39:38 | selftests 429 passed, 0 failed; `test-queue`'s node part 156 pass, 0 fail |
|
||||
| gate total | | 1201 pass, 0 fail, 11 suites, `GATE_PASSED` |
|
||||
| c0 control | 04:39:38-04:40:35 | exit 0 |
|
||||
| m1-m8 | 04:40:35-04:41:25 | 8 of 8 killed, every one exit 1 |
|
||||
|
||||
Every restore passed its sha256 check, and `git diff` was clean at d99166ade afterwards. The EXIT trap
|
||||
removed the `darkwing-r233_default` network.
|
||||
|
||||
N1, found in the process sweep after the run: a `sleep 60` was left with its cwd in `packages/cli`.
|
||||
`stack-upgrade.test.mjs:312` spawns `flock LOCK sleep 60`, and its `t.after` SIGKILLs only the flock, so
|
||||
flock's child outlives the test by up to 60 s. It exited on its own. Row 232's T20
|
||||
(`stack-release.test.mjs:370`) spawns its holder `detached` and kills the group with `process.kill(-pid)`.
|
||||
The fix is the same two lines. That test is one of m1's killers.
|
||||
|
||||
Sage ruled it a fix now (sage-1707), and 08db6ac3f makes it, test only. After the gate's d99166ade
|
||||
the only change outside this file is that test:
|
||||
|
||||
```
|
||||
$ git diff --stat d99166ade 08db6ac3f
|
||||
packages/cli/tests/stack-upgrade.test.mjs | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
```
|
||||
|
||||
The gate stands on Sage's ruling. The rerun is the whole `stack-upgrade.test.mjs` singly plus m1, in
|
||||
Sage's slot, with a sweep for a leftover `sleep` afterwards.
|
||||
@@ -1,173 +0,0 @@
|
||||
# Row 240 (I4): root's host check, its pins and the boot unit
|
||||
|
||||
Brief: `docs/plans/2026-10-20_installer-rows.md` section I4, blob `4a5a65020f00` (commit b00d7d94d, rev 2665,
|
||||
the pin row 240 carries; the I3 carry items came in with it). Sage split it out of I3 (sage-1650). Gitea #1746, Vikunja P19 #432. Owner Darkwing, reviewer Filbert, gate owner Sage.
|
||||
Design: row 195 DESIGN r6 B2, `agents/darkwing/work/queue-195/DESIGN.md` at b7239bb66, :262-303 (the script,
|
||||
the three callers) and :839-860 (files, test cases, mutants). Where the brief and r6 differ, the brief wins.
|
||||
|
||||
## Files
|
||||
|
||||
Drafted on `darkwing/row240-r1` from d99166ade (row 233's candidate) while row 233's gate ran, then applied
|
||||
as one patch onto row 233's landing, 57f59e0c3, on `darkwing/row240-r2` (sage-1753). It applied cleanly; between
|
||||
the two bases the only change on this row's paths is 233's N1 test fix in `stack-upgrade.test.mjs`. Row 234
|
||||
then landed as c771a36f4 on 57f59e0c3. Sage preferred that the gate run with it in the tree (sage-1773), so both
|
||||
commits were picked onto c771a36f4 as `darkwing/row240-r3`. That was a clean pick: the 42 paths changed from
|
||||
57f59e0c3 to c771a36f4 share none with this row's 9.
|
||||
|
||||
- `scripts/case1-pins.sh` (new, 0644): `PIN_PROFILES_VERSION`, `PIN_PROFILE_SHA256`, `PIN_BUBBLEWRAP_VERSION`,
|
||||
r6 section 0's values.
|
||||
- `scripts/case1-hostcheck.sh` (new, 0755): the seven items and `--check`, `--enforce`, `--upstream`.
|
||||
- `packages/cli/systemd/mosaic-hostcheck.service` (new): the boot oneshot.
|
||||
- `packages/cli/tests/case1-hostcheck.test.mjs` (new, 16 tests). The cli suite's `tests/*.test.mjs` glob picks
|
||||
it up.
|
||||
- `docs/guides/host-run-sheet.md` section 4: the install lines that replace "Install them from row 240's run
|
||||
sheet lines once it lands", plus rollback, drift recovery and `--upstream` before a re-pin window. Sections
|
||||
3, 6, 8 and 10 for the I3 carry items below.
|
||||
- `scripts/stack-upgrade.sh` and `packages/cli/tests/stack-upgrade.test.mjs`: I3 N1 below.
|
||||
- `docs/TOOLS.md`: a new subsection "Root's host check (`scripts/case1-hostcheck.sh`, row 240)" after the
|
||||
upgrade driver's.
|
||||
|
||||
Brief line 257 said I3's `stack-upgrade.sh` doesn't change. Sage's ruling sage-1727 widened the row to it for
|
||||
N1 alone. Its default `STACK_UPGRADE_HOSTCHECK=/usr/local/lib/mosaic-stack/hostcheck.sh` is where the run
|
||||
sheet installs this script.
|
||||
|
||||
## Carried from I3
|
||||
|
||||
Filbert's row 233 approve (Gitea 29922) left five notes. Sage ruled N1, N4 and N5 into this row and N2 and N3
|
||||
to DEFERRED.md (sage-1727).
|
||||
|
||||
| Note | Change |
|
||||
|---|---|
|
||||
| N1: `stack-upgrade.sh` exits 1 `args-failed` when the args move after A5 fails, but exit 1 means the old copy runs | The move's failure exits 5 `args-failed`. The header, TOOLS.md's step 5 and exit line, and run sheet section 6's exit list name exit 5 and what root does: move the new file the result line names into place. Test `row 240: I3 N1: a failed args move after A5 exits 5 ...` makes `/etc/mosaic-stack` read-only at confirm and checks exit 5, the step names, `args rc=1`, the result line, both units on the new copy, the old args file's bytes and the new file beside it. The step log regex takes `exit=5`. Mutant M8. |
|
||||
| N4: section 3's `npm install` has no npm on root's PATH, and the `--claude` path is unnamed while `node_modules/.bin/claude` is a symlink `case2-unit.sh:140` refuses | The install line runs with section 2's pinned node first on PATH (the postinstall runs `node` too). The `--claude` path is `node_modules/@anthropic-ai/claude-code/bin/claude.exe`, and a `--version` line catches the postinstall's 500-byte stub. |
|
||||
| N5: sections 8 and 10 lack precheck lines | Each gets "Precheck line: none" and its missing line. |
|
||||
|
||||
Exit 5 is new rather than 2 because 2 means both units are stopped, and here both run. Exit 4 stays usage.
|
||||
|
||||
The `claude.exe` path comes from the 2.1.304 package itself: `npm view` gives `bin.claude` as `bin/claude.exe`,
|
||||
and its `install.cjs` hardlinks the platform binary over that placeholder, or copies it across devices, then
|
||||
sets 0755. I downloaded the tarball into `/mnt/storage/scratch/tmp/r240/cc304` and read it; nothing ran. The
|
||||
run sheet says a newer pin needs the same check.
|
||||
|
||||
## The brief, item by item
|
||||
|
||||
| Brief line | Where |
|
||||
|---|---|
|
||||
| 247 `case1-pins.sh` holds the three pins | `scripts/case1-pins.sh`; the pins test checks the values against r6's |
|
||||
| 248-249 seven items, `--check` exits 0 or 1 | `items()` and the final dispatch; the check tests |
|
||||
| 250-251 `--enforce`: `apparmor_parser -R`, `root:root 0700`, `DRIFT`, a log line, exit 0 | `enforce()` and `stop_bwrap()`; the four enforce tests |
|
||||
| 252 `--upstream` compares the current deb to the pin | `upstream()`; the upstream test |
|
||||
| 253 the boot oneshot | `mosaic-hostcheck.service`; the boot unit test |
|
||||
| 254-255 fakes for every host tool, r6's seven case groups, seven mutants | the test file; Tests and Mutants below |
|
||||
| 257 the I3 run sheet item points here | run sheet section 4 |
|
||||
|
||||
## Tests
|
||||
|
||||
Fakes on PATH, each logging its argv to `$HC/calls.log`: `aa-status`, `dpkg`, `dpkg-statoverride`,
|
||||
`apparmor_parser`, `systemd-run`, `stat`, `chown`, `chmod`, `apt-get`, `dpkg-deb`. `host(t)` builds a scratch
|
||||
root (`/etc`, `/proc/sys`, `/usr/bin/bwrap`, `/var/log`) and a lib dir with a copy of the script and fixture
|
||||
pins that hold the fixture profile's sha256. Every run passes `--root`.
|
||||
|
||||
r6's case groups (:843-856) against the tests:
|
||||
|
||||
| r6 case | Tests |
|
||||
|---|---|
|
||||
| `--check` exits 0 with all seven, 1 with each failing alone, its line naming it | `check: exits 0 ...`, `check: exits 1 with each item failing alone ...`, plus one test per item for the item's edge cases |
|
||||
| item 3: a second file naming `bwrap` as a word, `/{usr/,}bin/bwrap` included; passes with the profile alone | `check: item 3 ...` |
|
||||
| item 4: `unpriv_bwrap (enforce)` or a trailing space fails; the argv carries `-p NoNewPrivileges=yes` and the 2a' properties | `check: item 4 ...` checks the whole argv |
|
||||
| item 7: the floor at 732 fails | `check: item 6 ...; item 7 ...` (733 passes as the control) |
|
||||
| `--enforce` exits 0 on a pass and every failure; unload, close, `DRIFT`, one log line; `DRIFT` present with every item passing still closes | `enforce: a pass ...`, `enforce: each failure ...`, `enforce: with DRIFT present ...` |
|
||||
| `--enforce` never calls `dpkg-statoverride` with `--update`, `--add` or `--remove` | `enforce: no unload ...; never writes the statoverride` (every call is `--list /usr/bin/bwrap`) |
|
||||
| a bubblewrap version other than the pin is a line, not a failure | `check: a bubblewrap version other than the install pin ...` |
|
||||
| `--upstream` against a differing deb prints the difference, exits 0 | `upstream: ...` (also: a match, a deb with no profile, a failed download) |
|
||||
| the unit: `Type=oneshot`, `After=apparmor.service`, `[email protected]`, runs `--enforce` | `boot unit: ...` |
|
||||
|
||||
The last test also checks that the repo script reads `scripts/case1-pins.sh` beside it, that bad usage exits
|
||||
2, and that a non-root run without `--root` refuses.
|
||||
|
||||
Singles are the two files that run a changed script: `case1-hostcheck.test.mjs` and `stack-upgrade.test.mjs`.
|
||||
Sage asked (sage-1759) whether `stack-release.test.mjs` or `stack-release-external.test.mjs`, which share
|
||||
`stack-release-fixture.mjs`, run `stack-upgrade.sh` or `case1-pins.sh`. They don't. `grep -cF` for
|
||||
`stack-upgrade`, `case1-pins`, `case1-hostcheck` and `hostcheck` gives 0 in all three files; the control
|
||||
`stack-release.sh` gives 2 in the fixture and 8 in `stack-release.test.mjs`. `scripts/stack-release.sh` names
|
||||
`stack-upgrade.sh` once, in a comment (:2061). The gate's cli suite runs both files anyway.
|
||||
|
||||
## Mutants
|
||||
|
||||
r6's seven (:858-860) and one for I3 N1, scripted in `~/darkwing-scratch/r240/mutants.sh` with r233's method: a checked backup,
|
||||
an exact replacement that must match once, `bash -n`, the named killer by `--test-name-pattern`, the restore
|
||||
and a sha256 check. A dry run matched all eight once each. Results below.
|
||||
|
||||
| Mutant | Change | Killer |
|
||||
|---|---|---|
|
||||
| M1 | `--enforce` exits 1 after the stop | `enforce: each failure exits 0 ...` |
|
||||
| M2 | `[ ! -e "$DRIFT" ] \|\| had=1` becomes `true \|\| had=1` | `enforce: with DRIFT present ...` |
|
||||
| M3 | item 1's `dpkg -S` becomes `owner=""; rc=1` | `check: item 1 fails when a package owns ...` |
|
||||
| M4 | item 3's `grep -rlw bwrap` becomes `grep -rlF /usr/bin/bwrap` | `check: item 3 ...` |
|
||||
| M5 | item 4's `[ "$label" = "$LABEL" ]` becomes a substring match | `check: item 4 ...` |
|
||||
| M6 | item 4 drops `-p NoNewPrivileges=yes` | `check: item 4 ...` (argv) |
|
||||
| M7 | item 7's `-gt` becomes `-ge` | `check: item 6 ...; item 7 fails with the floor at 732 ...` |
|
||||
| M8 | `stack-upgrade.sh`'s `finish 5 args-failed` becomes `finish 1 args-failed` (I3 N1) | `row 240: I3 N1: a failed args move ...` |
|
||||
|
||||
## Deviations
|
||||
|
||||
- Repo name `scripts/case1-hostcheck.sh` (r6), installed as `/usr/local/lib/mosaic-stack/hostcheck.sh`, the
|
||||
name in brief line 239 and I3's `stack-upgrade.sh` default. r6's apt hook line says `case1-hostcheck.sh`;
|
||||
the run sheet's hook uses the installed name.
|
||||
- `stat` is a fake too. r6 lists seven fakes; a test can't make a root-owned file, so item 5's `stat` reads a
|
||||
fixture.
|
||||
- Item 7 with no Console unit installed reads the port as 1023 and says so ("1023, because no Console unit
|
||||
is installed"). Until I2 installs the unit the floor must be above 1023. A unit with no `--port` fails.
|
||||
- Item 4 runs under `timeout 60`. A hung `systemd-run` would otherwise hang the apt hook and the boot unit.
|
||||
|
||||
## Decisions
|
||||
|
||||
- Fail closed where r6 is silent:
|
||||
- pins with no 64-hex sha fail item 1;
|
||||
- `dpkg -S` exit 1 (no owner) passes, exit 0 fails with the owner, any other exit fails with the code;
|
||||
- a failed `aa-status` fails item 2 and counts as loaded, so `--enforce` tries the unload.
|
||||
- `--root DIR` is the test seam (r6 :840). Root refuses it; a non-root user needs it. Both exit 2. Root runs
|
||||
with `PATH=/usr/sbin:/usr/bin:/sbin:/bin`.
|
||||
- `DRIFT` is append-only (`<stamp> <failed line>`), and `--enforce` never removes it. The log line is written
|
||||
only when the stop runs: `<stamp> enforce stop items=<ids or none> drift-before=<0|1> unload=<rc=N|no-file|skipped> chown=N chmod=N`.
|
||||
- `--upstream` exits 1 when the download or the unpack fails, since it then compared nothing. A deb without
|
||||
the profile file is a difference (exit 0), per r6 :302-303.
|
||||
- The bubblewrap note reads the version from `dpkg -s bubblewrap`.
|
||||
- The run sheet's recovery steps (`chown root:mosaic`, `chmod 0750`, `apparmor_parser -r`, then `--check`
|
||||
before root removes `DRIFT`) are mine. r6 says only that root removes `DRIFT` in a reviewed step.
|
||||
|
||||
## Run environment
|
||||
|
||||
Worktree `/mnt/storage/scratch/darkwing-r240b`, branch `darkwing/row240-r3` on c771a36f4, with `node_modules`
|
||||
linked to the canonical checkout's. Node v26.8.1, kernel 7.2.2-1-cachyos, 16 CPUs, TMPDIR
|
||||
`/mnt/storage/scratch/tmp/r240`, compose project `darkwing-r240b`. Sage's slot (sage-1773, 06:16Z). Each run is
|
||||
one chain behind `busy.sh`, launched from `/`: `~/darkwing-scratch/r240/run-all.sh` checks the HEAD pin and a
|
||||
clean tree, runs the singles, then the mutants (8 killed, none surviving, the tree clean after), then the gate
|
||||
(the cli suite and every `scripts/test-*.sh`), each stopping the chain on failure, then sweeps `/proc` cwd links
|
||||
for anything left in the r240 trees.
|
||||
|
||||
## Results
|
||||
|
||||
Run r1, 06:17:10Z on 47ec9fe2f, failed at the singles. `case1-hostcheck.test.mjs` passed 16/0/0, and
|
||||
`stack-upgrade.test.mjs` went 20 pass, 1 fail. The failure was the N1 test's own `t.after` hook, which ran
|
||||
`chmodSync(e.etc, 0o755)` after the fixture's cleanup had already removed the scratch root, so it threw ENOENT.
|
||||
Every assertion in the test body had passed, exit 5 included. The fixture's cleanup runs `chmod -R u+w` on the
|
||||
root before `rmSync`, so the 0555 dir never needed the hook. b45852daa drops it and changes nothing else. The
|
||||
mutants and the gate didn't run. The sweep found nothing left. Sage counted r1 as this slot's one failure
|
||||
(sage-1788).
|
||||
|
||||
Run r2, 06:20:41Z to 06:33:28Z on b45852daa, passed. The counts come from awk over the .out files
|
||||
(`~/darkwing-scratch/r233/sum.sh`):
|
||||
|
||||
| Step | Result |
|
||||
|---|---|
|
||||
| `case1-hostcheck.test.mjs` | 16/0/0 |
|
||||
| `stack-upgrade.test.mjs` | 21/0/0 |
|
||||
| c0 control | exit 0 |
|
||||
| M1-M8 | 8/8 killed, none survived, every restore's sha256 matched, tree clean after |
|
||||
| `packages/cli` suite | 639/0/0 |
|
||||
| `scripts/test-*.sh` | auth 15, conductor 17, config 31, discord 78, extension-package 18, foundation 44, land-work 86, queue 156 node + 28 selftest, release 14, task 98; 585 pass, 0 fail |
|
||||
| Gate total | 11 suites, 1224 pass, 0 fail |
|
||||
| Sweep | nothing left in the r240 trees; the compose network was removed |
|
||||
|
||||
This commit adds only these BUILD.md lines. No test reads BUILD.md.
|
||||
@@ -1,310 +0,0 @@
|
||||
# Row 234 (#436a row a, Gitea #1740): host enrollment, store records and bus schema 3i to 3j
|
||||
|
||||
Gizmoduck, 2026-10-21. Reviewer Duckworth, gate owner Sage. Lands by 10-25, before the .53 and .54 installs
|
||||
(mos-1134).
|
||||
|
||||
- Brief: `docs/plans/2026-10-20_host-credentials.md`, section "Machine grant row a: enrollment, store records
|
||||
and migration 3i-3j", blob 64451be5 (queue rev 2617).
|
||||
- Design: `agents/gizmoduck/work/machine-grant/DESIGN.md` r6, f9039682e on `gizmoduck/machine-grant-design`,
|
||||
approved by Duckworth (duckworth-0064, REVIEW-r6.md at 8ea792256). Not reopened here. Cites "r6:" are lines
|
||||
of that file.
|
||||
- Grant event rule: #436b section 7, fa5658941 on `megavolt/row199`,
|
||||
`agents/megavolt/work/436b/DESIGN.md:431-490`, file sha256
|
||||
96510b83778e79a71b33d0d5f6fd0c806dfe74f6de315ff4a9f1fbe5620f6c69, approved by Duckworth (duckworth-0067).
|
||||
- Base: origin/refactor 8fede5fc6, with rows 199 (cb5fdb064) and 210 (f5753c0e8) landed. Branch
|
||||
`gizmoduck/row234`. Code cites are `path:line` at 8fede5fc6 unless they say otherwise.
|
||||
|
||||
## Names: r6 against section 7
|
||||
|
||||
r6's `grant.*` and `host.enroll.*` names are `body.action` values on `action.allowed` events, not event
|
||||
kinds. The `events` kind CHECK isn't rebuilt. Four r6 names move under `grant.`:
|
||||
|
||||
| r6 | This row |
|
||||
|---|---|
|
||||
| `host.enroll.step` | `grant.host.enroll.step` |
|
||||
| `host.enrolled` | `grant.host.enrolled` |
|
||||
| `host.checked` | `grant.host.checked` |
|
||||
| `host.removed` | `grant.host.removed` |
|
||||
|
||||
Only the consume record carries `decision`: `{operation: 'grant.host-enroll', decision}`. Every other
|
||||
guarded body names the decision `grantDecision`, so r6's `decision` field in step, enrolled and failed bodies
|
||||
is `grantDecision` here. The actor of every guarded event is `actor_role` NULL with `actor_run` 'grant',
|
||||
and `body.by` names the caller the broker checked.
|
||||
|
||||
## Split (r6 section 12 Q-S4)
|
||||
|
||||
Row a builds:
|
||||
|
||||
1. **Schema 3i to 3j.** `migrations/3i-3j.sql` adds `hosts` and `host_grants` (r6 S1, primary keys
|
||||
(business, host) and (business, agent, host)) and the guard trigger: an `action.allowed` whose
|
||||
`body.action` or `body.operation` GLOBs `'grant.*'` aborts unless the actor is (NULL, 'grant').
|
||||
`SCHEMA_VERSION` 3j, a migration test with a step that fails partway.
|
||||
2. **Grant event writer.** A private session-less broker writer for guarded events. `#event` doesn't change.
|
||||
`recordEvent` refuses `reserved-event` for the guarded namespace.
|
||||
3. **The `grant` raise frame.** `decision.raise` takes `grant` only with `credential.mint`, only from the chief
|
||||
(`grant-chief-only`), and in row a only with `method: 'host-enroll'`. Any other method refuses
|
||||
`invalid-request` until row b adds `host`. E1's checks, the `ssh-keyscan` set compare before the raise
|
||||
transaction, and the rendered block.
|
||||
4. **Enrollment executor.** `#consumeGrant`, the start on the human's cli yes (X1), E2 steps 1 to 4, the
|
||||
installer key at `<configDir>/secrets/hosts/<business>/<hostId>/installer`, the failure cleanup, and the
|
||||
start reconcile for enrollments: the `registry` step undo, and a resolved-yes unspent enrollment ending
|
||||
`grant.failed interrupted` (X3).
|
||||
5. **`hosts.check` and `hosts.remove`** (E4), with `mosaic hosts status|check|remove`.
|
||||
6. **`tools/host/`**: `mosaic-keys`, `mosaic-keys-write`, `mosaic-keys.sudoers`, `mosaic-keys.sshd.conf` (E3).
|
||||
7. **`host.run` on the store** (X4 first and third bullets): it reads the `hosts` and `host_grants` records
|
||||
and the Approve record check, and at start the runtime gives `Credentials` a reference per `host_grants`
|
||||
record. The loader refuses `hosts` at the top level and in a role (S1). Row 210's tests move to store
|
||||
fixtures.
|
||||
8. **Reader filter** (duckworth-0067 N1): every grant-evidence reader in this row (status, the start
|
||||
reconcile, `openGrantDecisions`) filters `kind = 'action.allowed' AND actor_role IS NULL AND actor_run =
|
||||
'grant'`, with a test that an `action.refused` look-alike and a session-written one are ignored.
|
||||
`hosts.remove`'s `hostLineLeft` reader is one of them (duckworth-0079 M4).
|
||||
|
||||
Row b keeps the `host` method's raise binding (R4), the grant executor (X2), the grant rows of X3, X5,
|
||||
`Credentials.register`/`claim`/`abortClaim`, revoke (section 6) and `sweep`. So row a has no way to make a
|
||||
`host_grants` record outside a test fixture, and from its landing to row b's no agent holds a host grant
|
||||
(r6 N9, the run sheet strips row 210's keys).
|
||||
|
||||
Tests in row a (r6 section 10): G1 and G5 for the `host-enroll` raise, G6 and G10 for the enrollment
|
||||
executor, G11's enrollment cases, G14, G15, G16, G17, G18, G20, G21 (its `host-line-left` case reads an
|
||||
event fixture until row b writes `hostLineLeft`), G25, the migration test, the trigger cases, the reader
|
||||
filter test, and row 210's T-tests on store fixtures. Row b: G2 to G4, G7 to G9, G11's grant cases, G12,
|
||||
G13, G19, G22 to G24, G26 to G28.
|
||||
|
||||
## Early check items (duckworth-0079, REVIEW-build-split.md 10672772e on `duckworth/reviews`)
|
||||
|
||||
Moves into row a:
|
||||
- M1. G4 for the `host-enroll` block (r6:240-242): a question can't forge the block, and the 4096-character
|
||||
limit holds with the block appended. G4 for the `host` block stays in row b.
|
||||
- M2. The tag function (r6:265-266), because E2 step 2 tags the installer line. G24's first sentence moves
|
||||
here: names of 64 characters with `.` and `_` give distinct tags of the fixed length. The `sweep` half
|
||||
stays in row b.
|
||||
- M3. A store-fixture test that `host.run` refuses `host-not-granted` for no record, an unresolved decision,
|
||||
a decision resolved by an arbiter, the tester or an agent or not via cli, a consume record with operation
|
||||
`grant.host-enroll` in place of `grant.host`, and an unspent decision (X4 first bullet, r6:593-596). A
|
||||
restart test that a `host_grants` fixture gives `Credentials` a reference (X4 third bullet).
|
||||
|
||||
G21's `host-line-left` case:
|
||||
- F1. The fixture goes through this row's private grant writer in the real shape: `action.allowed`, actor
|
||||
(NULL, 'grant'), `body.action` 'grant.failed', `body.host`, `body.hostLineLeft`. No raw SQL around the
|
||||
trigger.
|
||||
- F2. `hosts.remove` reads `body.hostLineLeft` from any guarded body, not only `grant.failed`.
|
||||
- F3. Decided: a guarded body that carries `hostLineLeft` also carries `host`. Row b adds `host` to
|
||||
`grant.revoke.closed`, so its body is `{tag, host, hostLineLeft}` (r6:716 has `{tag, hostLineLeft}`).
|
||||
The reader matches on `body.host`, and doesn't map tags back to hosts through `grant.step`. A direct
|
||||
field is one equality in SQL, and a tag lookup would add a second reader that the N1 filter also has to
|
||||
cover.
|
||||
- F4. Row b carry: "no later `sweep` cleared it" (r6:403) needs `grant.sweep`, which only row b writes. Row
|
||||
b adds the sweep clear to `hosts.remove` with a G21 case, and its G8 or G13 shows `hosts.remove`
|
||||
refusing after a real `hostLineLeft` write, not only after the fixture. Until then row a's check is "any
|
||||
guarded `hostLineLeft` for this host refuses".
|
||||
|
||||
## Mutants (r6:838-883, numbered here)
|
||||
|
||||
Row a, killed on this row's tree:
|
||||
|
||||
| # | Mutant |
|
||||
|---|---|
|
||||
| A1 | drop the chief check |
|
||||
| A2 | start the executor on a `credential.mint` with no `grant` |
|
||||
| A3 | start it on an arbiter resolve |
|
||||
| A3b | start it on a `cli` yes by someone other than the human (duckworth-0083 N8) |
|
||||
| A4 | start it on `no` |
|
||||
| A5 | skip the keyscan compare |
|
||||
| A6 | compare only one key |
|
||||
| A7 | write the private key into the event body |
|
||||
| A8 | drop the "not yet enrolled" check in E2 step 1 |
|
||||
| A9 | drop the `hosts` primary key |
|
||||
| A10 | skip the start check for a resolved, unspent enrollment decision |
|
||||
| A11 | `host.run` reads the business file instead of the grant record |
|
||||
| A12 | build the tag without the business |
|
||||
| A13 | drop `from=` in the writer |
|
||||
| A14 | let the writer touch a line outside the tag pattern |
|
||||
| A15 | drop `O_NOFOLLOW` on the user file |
|
||||
| A16 | drop one group from the writer's refused list |
|
||||
| A17 | drop the user pattern check before the path use |
|
||||
| A18 | treat a `privileged` entry as enough without `users` |
|
||||
| A19 | let the writer accept a sudo user not in `privileged` |
|
||||
| A20 | trigger: drop the `body.operation` arm, so the consume record passes from a session |
|
||||
| A21 | trigger: accept actor_role NULL with any actor_run |
|
||||
| A22 | a grant reader drops the `kind = 'action.allowed'` or actor filter. The runner splits it: A22a drops the kind, and G21's `action.refused` look-alikes kill it. A22b drops the actor, which the trigger can't stand in for, because 3i-3j adds the trigger without checking old rows. Its killer is the grant-migration test "A22b, sage-1703": a session-written `grant.host.removed` with `hostLineLeft` and a `grant.host-enroll` row from 3i, migrated to 3j, where `hosts.remove` still removes the host and `reconcileGrants` ends nothing |
|
||||
| A23 | `host.run` skips the Approve record check (any `host_grants` record is enough) |
|
||||
|
||||
Row b keeps the rest of r6's list: the `ready` check, the three hash compares, the definition check, the
|
||||
install and record order, `remove` on a verify failure, both start sweeps, the reconcile's remote `remove`,
|
||||
the `grant.step` before install, revoke leaving the record, `register` before `issue`, the abort check and
|
||||
the `await` before `issue`, revoke and an unreferenced claim, `sweep` and any `mosaic-` line, revoke's host
|
||||
step order, claim before consume, the resolved unspent grant decision, an async `commit`, `hosts.revoke`
|
||||
through `credential-verbs.mjs`, the revoke marker reconcile, the upsert, the undo past `grant.revoked`, the
|
||||
abort after step 5 and a missing `bus.tester` as dev.
|
||||
|
||||
## Broker functions this row touches (sage-1677)
|
||||
|
||||
For row 236 (Megavolt), which rebuilds on this landing. Old lines are `packages/bus/src/broker.mjs` at
|
||||
8fede5fc6, new lines are at the last commit that changed this file (they moved by 10 after `runEnrollment`
|
||||
went in). The planned list is kept in this file's history (827b89ea6).
|
||||
|
||||
Changed:
|
||||
- `constructor` (:279): one more option, `hostGrant`, the object `host-grant.mjs` builds.
|
||||
- `recordEvent` (old :1243-1251, new :1606): one more refusal. An `action.allowed` whose `body.action` or
|
||||
`body.operation` is a `grant.*` name refuses `reserved-event`.
|
||||
- `request()` (old :1362, new :1726): two routes ahead of the sync path, a `decision.raise` with `grant` to
|
||||
`#raiseGrant` and the `hosts.*` verbs to `#requestHosts`. Both are async.
|
||||
- `requestHost` (old :1712-1795, new :2079): the business-file lookups (old :1730-1736) become one
|
||||
`#hostAccess` call, in the same transaction as `#agent`. `commands` and `entry` come from it.
|
||||
- `#dispatch` (old :1796, new :2160) gets a fifth parameter, `enroll`, which only `#raiseGrant` passes.
|
||||
- `decision.raise` (new :2244): `grant` joins the allowed keys, and `grant` without `enroll` (or the
|
||||
reverse) refuses `invalid-request`. The `host.sudo` block reads `#hostAccess` in place of `b.hosts`
|
||||
and the role's `hosts`, and an undefined `target` still refuses `host-unknown`. `validArgv` and
|
||||
`validStdin` now run after the access check, so a malformed argv for an ungranted host refuses
|
||||
`host-not-granted` first. The enrollment block is appended to the question before `string(question)`,
|
||||
so the 4096 cap counts it (M1). The decision's raise body carries `grant: enroll`.
|
||||
- `decision.resolve` (new :2409): when `op` is `resolved`, `#approvedGrant` reads the decision, and a
|
||||
`host-enroll` grant starts `#runEnrollment` from `setImmediate`, after the transaction commits. The
|
||||
result adds `grant: 'started'`.
|
||||
|
||||
New, all private but two:
|
||||
- `#grantEvent` (:657), the writer of guarded events. It runs the secret check, then `writeGrantEvent`.
|
||||
- `#approvedGrant` (:667), `#consumeGrant` (:678). `#consumeGrant` sits after `#approvedGrant`, not next
|
||||
to `#consumeAuthority` as planned.
|
||||
- `#hostRecord` (:685), `#hostAccess` (:692), `#grantNotice` (:708), `#enrollFailed` (:736),
|
||||
`#runEnrollment` (:750), `#openGrantDecisions` (:823).
|
||||
- `runEnrollment` (:745), public, a trusted entry to `#runEnrollment` for G10. No verb reaches it.
|
||||
- `reconcileGrants` (:833), public, which `runtime.mjs` calls once at start.
|
||||
- `#raiseGrant` (:866), `#hostsCaller` (:886), `#requestHosts` (:900), `#hostLinesLeft` (:964).
|
||||
|
||||
Module level, new (:184-230): `GRANT_RUN`, `grantName`, `GRANT_EVIDENCE` (the N1 filter as SQL),
|
||||
`registrySha256`, `writeGrantEvent` (exported, the one writer of guarded events, which test fixtures use
|
||||
for F1), `HOSTS_VERBS`, `fingerprintOf`, `INSTALLER_COMMENT`.
|
||||
|
||||
Unchanged: `#event`, `#spent`, `#consumeAuthority`.
|
||||
|
||||
Other `src` files:
|
||||
- `bus/src/host-grant.mjs`, new: the keyscan, the installer key pair, and `hosts.check`'s `list`.
|
||||
- `bus/src/runtime.mjs`: builds `hostGrant`, calls `reconcileGrants` before the server starts, and adds
|
||||
the `host_grants` references before `new Credentials` (X4 third bullet).
|
||||
- `bus/src/host-run.mjs`: `runHost` takes `command`, sent as is in place of the sudo argv, for the
|
||||
installer's `list`.
|
||||
- `bus/src/server.mjs`: the `hosts.*` verbs and a raise with `grant` go down the async path.
|
||||
- `bus/src/store.mjs`: the 3i-3j step, `SCHEMA_VERSION` 3j. `bus/src/credentials.mjs` exports
|
||||
`privateDir`.
|
||||
- `business/src/business.mjs` and `business/src/hosts.mjs`: the loader refuses `hosts` (S1).
|
||||
`checkHosts` and `checkHostGrants` are gone.
|
||||
- `cli/src/hosts.mjs`, new, routed from `cli.mjs` and `scripts/mosaic`.
|
||||
|
||||
## Decisions taken in the build
|
||||
|
||||
- **`#hostAccess` binds the agent and the host.** X4 says the Approve record check passes when the
|
||||
decision is an approved `host` grant with a `grant.host` consume. The check also requires the grant's
|
||||
`agent` to equal the session's role and its `host` to equal the requested host. Without that, an
|
||||
approved grant for one agent and host would vouch for any `host_grants` row that names its decision.
|
||||
Cost: none for row b, whose executor writes the row from the same grant.
|
||||
- **Store fixtures are written the real way.** `bus/tests/host-fixtures.mjs` inserts the decision rows by
|
||||
SQL, but every guarded event goes through `writeGrantEvent`, so the trigger sees it (F1). An enrollment
|
||||
fixture writes `grant.host.enrolled`, or the start reconcile reads it as interrupted.
|
||||
- **The resolver test for host kinds is gone.** `business/tests/hosts.test.mjs` lost its D5 case, because
|
||||
the loader now refuses `host.<id>` credential refs. The `isHostKind` filter in `business/src/resolve.mjs`
|
||||
can't be reached now. I left it in, since row b may want it back, and it's one line.
|
||||
- **Store before Credentials.** The runtime already opened the store before `Credentials`. The
|
||||
`host_grants` references depend on that order, and the comment there says so.
|
||||
- **CLI.** `mosaic hosts` prints tab lines, and `--json` prints the bus rows. Usage errors exit 4 and bus
|
||||
refusals exit 2, as `mosaic credentials` does. There is no enroll command: enrollment is the chief's raise.
|
||||
- **Host tools tests live in the bus suite.** `bus/tests/host-tools.test.mjs` loads the writer by path
|
||||
through a Python harness under `python3 -B -I`. The harness passes its own key dir, config dir, owner
|
||||
uid and user, group and sudo lookups, and runs `mosaic-keys` from a copy with stub `sudo` and `logger`.
|
||||
The gate runs the bus suite, so G16 and G25 run there. The real `pwd`, `grp` and `sudo -l` paths are
|
||||
checked on the #433 VM, not here. The test also runs `visudo -c` on the sudoers file and `sshd -T` on
|
||||
the drop-in.
|
||||
- **Writer details the design left open.** The `from` file must hold exactly one value matching
|
||||
`[0-9A-Za-z.:/*?!_-]+(,[0-9A-Za-z.:/*?!_-]+)*`, so it can't close the quote. `users`, `privileged` and `from` must be
|
||||
regular, owned by the owner uid and not group or world writable, and are opened without following a
|
||||
symlink. Lines starting with `#` are comments. A refusal exits 1 with its code on stderr and in syslog.
|
||||
`add` of a tag that is already there exits 0 and writes nothing.
|
||||
- **`runEnrollment` is public for G10 (duckworth-0081 B1).** G10 needs a second start for a spent
|
||||
decision, and the resolve path can't give one: a second resolve refuses `decision-closed`
|
||||
(broker.mjs:2416) before the executor runs. So
|
||||
`#runEnrollment` returns its code (`enrolled`, `host-enrolled` or the refusal), and a public
|
||||
`runEnrollment` calls it, as `reconcileGrants` is public. The test checks a spent
|
||||
decision gives `decision-consumed`, and an open or agent-resolved one gives `not-authorized`, with
|
||||
nothing written. That second case also reaches the `via` and `by` checks in `#approvedGrant`, so A3 is
|
||||
no longer vacuous (N1).
|
||||
Who can call it (sage-1692): only code holding the `Broker` object, which is the bus process and the
|
||||
tests. The one `new Broker` in `src` is `runtime.mjs:126`, and no `src` file calls `runEnrollment`;
|
||||
the resolve path calls the private `#runEnrollment` from `setImmediate` (broker.mjs:2445). A seat
|
||||
holds no `Broker`. It reaches the bus only over `broker.sock`, where `server.mjs` calls a fixed set of
|
||||
methods by name (`request` at :134 and :140, `identity`, `disconnect`). `request()` routes on the verb
|
||||
through the `#dispatch` switch, and neither file looks a method up by name (no `this[` in either), so no
|
||||
verb string can reach `runEnrollment`.
|
||||
- **A `sudo -l` that times out refuses `user-sudo` (N2).** `_sudo` returns an empty answer on
|
||||
`TimeoutExpired`, which isn't the expected line, so `main` logs the refusal and exits 1.
|
||||
- **Keyscan comment (N3).** A scan that can't start refuses `host-failed`. One that runs and finds no key
|
||||
returns no lines, and the raise refuses `host-key-mismatch`. The comment in `host-grant.mjs` now says so.
|
||||
- **No tag on in-run `grant.failed` (N4).** r6:578 tags only the `interrupted` one, so the code follows it.
|
||||
- **Run sheet (N5).** The writer refuses `config-privileged` when the file is missing, so each host needs an
|
||||
empty, root-owned `/etc/mosaic-keys/privileged` (0644) before the first enrollment.
|
||||
|
||||
## Mutant results (Sage's slot, 2026-10-21)
|
||||
|
||||
All 25 killed: A1 to A23, with A3b added for duckworth-0083 N8 and A22 split into A22a and A22b. The
|
||||
runner is `mutants.py` outside the repo. Each mutant gets its own session, a 420 s limit with a group kill,
|
||||
and a byte restore checked against git status. None hung. Run 1 (04:24Z, on 95f966b1c) killed A1 to A22a
|
||||
and stopped at A22b, which survived. Run 2 (04:43Z, on 097892741) killed A22b and A23.
|
||||
|
||||
- Each kill comes from a named assertion in the mutant's own test files, except A9. Dropping the `hosts`
|
||||
primary key leaves `host_grants`' foreign key with no parent key, so the store refuses to open
|
||||
("foreign key mismatch") and 28 of 29 tests fail at setup. That's a structural kill, not the S1 test.
|
||||
The schema can't exist without the key (sage-1709).
|
||||
- A22b drops the actor filter from `GRANT_EVIDENCE`. The trigger can't stand in for it, because a 3i store
|
||||
can hold a session-written grant row that the 3i-3j step keeps. The grant-migration test "A22b,
|
||||
sage-1703" kills it (see the A22 row above).
|
||||
|
||||
Follow-up, not in row a: G18's control calls `runHost` directly, so nothing runs `hg.check` end to end
|
||||
with a good pin (duckworth-0083 N9). The #433 VM run covers it.
|
||||
|
||||
## Status at 097892741
|
||||
|
||||
Done: every Split item, 1 to 8, duckworth-0081 B1 to B3, duckworth-0083 N8, and all 25 mutants killed.
|
||||
|
||||
Single files in the slot, all exit 0, 178 pass and 0 fail by an awk sum over 23 logs: bus grant-enroll
|
||||
24, host-run 24, grant-migration 6, host-tools 6, account-migration 3, chief-of-staff 18,
|
||||
comment-migration 5, hard-waits 13, name-migration 1, project-runtime 3, spec-migration 1,
|
||||
thread-migration 3, usage-migration 1, project-files 8, spec-socket 6, spec-review 12, land 17, spec 4;
|
||||
harness spec-tools 2, raise-domain 2; business hosts 4; cli hosts 5; seat sandbox 10.
|
||||
|
||||
Left: Sage runs the whole bus, business and cli suites and every `scripts/test-*.sh` at the landing gate,
|
||||
after Duckworth approves.
|
||||
|
||||
## Round 3 (sage-1742): two tests that count the schema
|
||||
|
||||
The landing gate failed `packages/bus/tests/schema.test.mjs:522`. It counts the tables and triggers that
|
||||
`schema.sql` creates, and row a adds two tables and a trigger, so the counts go from 16 to 18 tables and
|
||||
from 70 to 71 triggers. My singles didn't run it because I took it for a test of other rows' tables.
|
||||
|
||||
I grepped `packages/*/tests/*` for `sqlite_master` and `schema.sql`, with `schema.test.mjs:517` as the
|
||||
positive control. That turned up one more test that would fail: T46 in
|
||||
`packages/cli/tests/stack-release.test.mjs:910`. It puts every schema table in exactly one of four lists, and
|
||||
hosts and host_grants were in none. I'd left the stack-release tests out of the r2 singles on the claim that
|
||||
they don't load the bus, but T46 reads `schema.sql`. Both tables go in its untimed list (Sage's ruling,
|
||||
sage-1745: the message_threads pattern). Neither has an `at` column. Row a writes hosts at five lines,
|
||||
and each runs in one store transaction with a `grant.*` events row, which the restore guard counts.
|
||||
`#grantEvent` (broker.mjs:657) writes that row through `writeGrantEvent` (:201, INSERT INTO events at
|
||||
:212).
|
||||
|
||||
- :737 DELETE, in `#enrollFailed`, with grant.failed at :738. Both callers wrap it in a transaction,
|
||||
:816 and :849.
|
||||
- :763 INSERT, in the step 1 transaction (:754), with grant.host.enroll.step at :761.
|
||||
- :783 UPDATE installer_fingerprint, in the step 4 transaction (:780), with grant.host.enrolled at :784.
|
||||
- :932 DELETE, in the hosts.remove transaction (:927), with grant.host.removed at :933.
|
||||
- :950 UPDATE state ready, in the hosts.check transaction (:944), with grant.host.checked at :951.
|
||||
|
||||
Row a writes no host_grants rows. It only reads them (broker.mjs:695, :930, runtime.mjs:103). Row b adds
|
||||
the writes, and each must share a transaction with a `grant.*` event the same way. That goes on row
|
||||
235's carry list. The other hits pin an older schema
|
||||
(account, comment, name, spec, thread and usage migrations, chief-of-staff 3c) or count only their own
|
||||
tables (state.test.mjs:106 reads every table but pins no list, threads.test.mjs:129).
|
||||
|
||||
hosts and host_grants are mutable by design, so the refused-labels loop above `schema.test.mjs:517` gets no
|
||||
entry for them. hosts.check updates a host to ready. hosts.remove and a failed enrollment delete the
|
||||
record. Row b updates and deletes grant records. Neither table has append-only triggers. The one new
|
||||
trigger, events_grant_actor, guards events. grant-migration.test.mjs tests it, and it killed mutants
|
||||
A20 and A21.
|
||||
@@ -1,598 +0,0 @@
|
||||
# Row 235 build: machine grant row b (#436, Gitea #1741)
|
||||
|
||||
Brief: `docs/plans/2026-10-20_host-credentials.md`, "Machine grant row b: raise binding, executor,
|
||||
reconcile and revoke". Design r6 f9039682e. Built on row 234's landing c771a36f4 (sage-1775), branch
|
||||
gizmoduck/row235-b. Line numbers below were read on b0320d395, whose src files are byte-identical to the landing's.
|
||||
|
||||
## Squash onto 4ced5e63d (sage-1812, sage-1831)
|
||||
|
||||
Steps 1-6 were six local commits on c771a36f4 (gizmoduck/row235-b, tip f9fff4300). Sage named
|
||||
4ced5e63d as the base, so this branch, gizmoduck/row235-c, holds one commit on it: the diff
|
||||
c771a36f4..f9fff4300 applied with `git apply --index`. N10 is in that commit. N12 needs no change,
|
||||
because row b doesn't touch schema.sql.
|
||||
|
||||
Rows 240, 228 and 238 landed between c771a36f4 and 4ced5e63d and changed 18 paths. One of them is
|
||||
also mine:
|
||||
|
||||
- `packages/cli/README.md`. Row 228 (86249ac55) changed the session credential paragraphs at about
|
||||
lines 432 and 706. My hunk adds three lines on `hosts revoke` and `hosts sweep` at about line 1052.
|
||||
The two don't overlap, so the blob here is row 228's blob plus my three lines, with no landed line
|
||||
reverted. cli tests/host.test.mjs:855 reads this README, and run 1's cli suite covers it.
|
||||
|
||||
The other 12 paths are byte-identical to f9fff4300. The line numbers in the step notes below were read
|
||||
on the old base.
|
||||
|
||||
## Run 1 (sage-1831, sage-1833, sage-1838)
|
||||
|
||||
Run 1 on 4d4bb4af6, 07:45-07:54Z, failed: 1351 tests, 1285 pass, 66 fail. The 66 are 33 tests counted
|
||||
twice, once in the files run and once in the bus suite. The cli suite, the cli hosts test, seat
|
||||
sandbox.test and bus project-runtime.test passed. Two defects, both mine:
|
||||
|
||||
- grant-executor.test.mjs, 32 tests. setup() never made `dir/data`, and `new Store` lstats its root
|
||||
(store.mjs:137), so every test stopped at setup with ENOENT. setup() now makes it, mode 0700.
|
||||
- credential-claim.test.mjs:76 (X4), 1 test. A register after a revoke left the key in `#revoked`, so
|
||||
status() said `revoked` for a new grant's reference that has no token yet. register now clears
|
||||
`#revoked`, as unregister does. `#revoked` feeds only status(), and issue clears it as well.
|
||||
|
||||
Both fixes are amended into the one commit. The rerun covers the five bus files, the bus suite, and
|
||||
cli credentials.test.mjs and verbs.test.mjs, which read credential state strings.
|
||||
|
||||
## Run 1 rerun (sage-1842, sage-1843)
|
||||
|
||||
The rerun on ac7c45975, 08:06-08:07Z, failed: 701 tests, 695 pass, 6 fail, which are 3 grant-executor
|
||||
tests counted in both the files run and the bus suite. All three were test defects that run 1's setup
|
||||
failure had hidden. No src file changed for them:
|
||||
|
||||
- G10. The two fixture decisions were built after `before`, and grantDecision (host-fixtures.mjs)
|
||||
INSERTs one events row each, so the count read 13 for 11. The test now builds them first, asserts
|
||||
they added exactly 2 rows, and then pins the executor's 0 against that count.
|
||||
- G27. setup's t.after removes the scratch dir before a hook the test adds later runs, so the test's
|
||||
chmod hook hit ENOENT after the body had passed. The body now restores the mode in a try/finally.
|
||||
- G22. The slow run's promise had no handler until `refusesWith`, four lines on. The revoke rejected it
|
||||
first, and node failed the test on the unhandled rejection. The handler now goes on at creation.
|
||||
|
||||
The fix is one more amend of the single commit. The rerun is grant-executor.test.mjs whole plus the bus
|
||||
suite.
|
||||
|
||||
Rerun 1c on 5df4b52c5, 08:15Z, was green: 623 of 623, grant-executor 34 of 34 and the bus suite 589 of 589.
|
||||
|
||||
## Mutants B1-B37 (sage-1894, sage-1899, sage-1904)
|
||||
|
||||
Three chunks ran on 5df4b52c5, 09:22-09:37Z. Restores matched HEAD after each. 33 were killed and four
|
||||
survived. Two of the misses were mine, in the file lists:
|
||||
|
||||
- B2 and B23 listed only grant-executor, and that file never makes the raise either mutant changes.
|
||||
grant-enroll.test.mjs:227 (A2, A4) resolves a plain `credential.mint` yes and a host grant no, and
|
||||
asserts no grant events for either. mutants.py now lists grant-enroll and grant-executor for both.
|
||||
B2 then ran alone and A2 killed it. B23 runs again with this round's tests.
|
||||
|
||||
The other two survivors needed tests, and Sage ruled on all four (sage-1904):
|
||||
|
||||
- B16 drops the abort check after `verify`. The check after `step('commit')` still ends the grant
|
||||
revoked, so G23 X5's asserts held. The run then logs a commit step for a grant that never committed.
|
||||
G23 X5 now asserts that its only `grant.step` is `install`.
|
||||
- B17 adds `await null` after the commit check. Sage accepted it as equivalent. `await null` yields
|
||||
only to microtasks. Every revoke starts in a macrotask of its own (a socket request, or a test's
|
||||
call), so none can land in that gap. There is no test for it.
|
||||
- B27 makes issue's commit callback async. issue() doesn't await it, so the executor returns `applied`
|
||||
before the INSERT runs. The two differ only when the commit transaction throws, and a real store can
|
||||
throw there with a full disk, an I/O error or a busy timeout. Under the mutant that throw becomes an
|
||||
unhandled rejection after the key file is written, and the catch's undo never runs. The new G8 test
|
||||
makes the store's `run` throw SQLITE_FULL once on the host_grants INSERT. It asserts host-failed, no
|
||||
record, key file, reference or line, and the steps install, commit, failed. The store object comes
|
||||
from the test's setup, so src gains no seam.
|
||||
|
||||
These two test changes went in as a new commit on gizmoduck/row235-d (8b13d0ca0). That branch then
|
||||
moved onto row 213's landing as gizmoduck/row235-e, below. B16, B23 and B27 run there, after the touched
|
||||
test files run whole.
|
||||
|
||||
## Rebase onto 62ddc96cc (sage-1922)
|
||||
|
||||
Row 213 landed as 361ba2387, and refactor's tip is 62ddc96cc, with only docs past it. gizmoduck/row235-e
|
||||
starts at 62ddc96cc and cherry-picks 8b13d0ca0's one commit. The patch-id is unchanged (c062b73fa9f1).
|
||||
row235-c and row235-d stay as they were.
|
||||
|
||||
Between 4ced5e63d and 62ddc96cc, 361ba2387 is the only commit that touches a file of mine. The one
|
||||
drifted path is `packages/bus/src/broker.mjs`:
|
||||
|
||||
- 213 adds `CREATIVE_DEFINITIONS` to the vocabulary import at :6, and refuses `decision.raise` from a
|
||||
creative role with `decision-not-allowed` at :2176. Both hunks stay as landed.
|
||||
- My 31 removed broker lines read the same before and after the cherry-pick, so no landed line is
|
||||
reverted.
|
||||
|
||||
`packages/cli/README.md` isn't in 361ba2387. Every other path of mine is byte-identical to 8b13d0ca0.
|
||||
Line numbers in the section below were read on the row235-e working tree; earlier sections keep theirs.
|
||||
|
||||
## Creative roles get no host grant (mos-1163, sage-1905, sage-1908, sage-1916)
|
||||
|
||||
Brief blob b16e236188f6 (4364dddb0, rev 2784) requires two refusals: the writer, at the raise and at the
|
||||
step 1 recheck, and host.run at spend time, with the record kept. Webby's N2 on row 213 r4 asks whether
|
||||
a creative role can spend a decision another role raised.
|
||||
|
||||
The spend answer. Mos confirmed it read-only (mos-1164, sage-1916) on 8b13d0ca0 and 01e1fe512; the
|
||||
row235-e line follows each:
|
||||
|
||||
- Only the chief raises a host grant. `#raiseGrant` refuses `grant-chief-only` for any other
|
||||
definition: :1232 on 8b13d0ca0, :870 on 01e1fe512, :1238 here. The hosts verbs check the same at
|
||||
:1307 on 8b13d0ca0, :896 on 01e1fe512, :1313 here. `chief-of-staff` isn't in `CREATIVE_DEFINITIONS`.
|
||||
- No agent spends one. `#consumeGrant` (:697) is called for a host grant only from `#runHostGrant`
|
||||
(:902) and from the restart reconcile (:1106), which ends it interrupted. `#runHostGrant` starts from
|
||||
the resolve hook (:2881) only when `#approvedGrant` returns a grant, and that needs a close by the
|
||||
business's human, via cli, with the raise's approval choice (:691). An agent's resolve records via
|
||||
`broker`, so it starts nothing (grant-enroll A3). The public `runHostGrant` (:891) is a trusted API
|
||||
that no verb reaches.
|
||||
|
||||
So a creative role can't raise, approve or spend a host grant. The gap was a different one: the chief
|
||||
could raise a grant whose `agent` is a creative role, and the human could approve it. The only check on
|
||||
that agent was `#hostDefinition`, which refuses `host-not-declared` (:864) unless the definition's
|
||||
`credentials` names `host`. Row 213's `checkCreative` (business/src/role.mjs:143) limits a creative
|
||||
role's tools, authority and messaging, not its `credentials`, so a creative role file naming `host`
|
||||
passed both the raise and the step 1 recheck.
|
||||
|
||||
As built:
|
||||
|
||||
- Writer. `#hostDefinition` refuses `host-creative-role` (:862) before the `host-not-declared` check.
|
||||
The raise binding (:1266) and the step 1 recheck (:879) both call it, so a grant raised before its
|
||||
agent's instance moved to a creative definition ends at step 1, spent, with no remote step.
|
||||
- Spend. `#hostAccess` refuses `host-creative-role` (:714) when the agent's current definition is
|
||||
creative, before it reads the record. Both callers go through it: host.run (:2543) and the host.sudo
|
||||
raise (:2778). The record stays, because revoke still owns the cleanup (sage-1908). This goes past
|
||||
the brief's writer line in the same direction; Sage tells Mos.
|
||||
|
||||
Tests:
|
||||
|
||||
- grant-host.test.mjs:115. A `muse` role on a `research` definition that declares host. The raise
|
||||
refuses `host-creative-role` and adds no decision.
|
||||
- grant-executor.test.mjs:947. The restart moves `ops` to a creative definition that declares host,
|
||||
then a fixture grant runs. It ends `host-creative-role` at step 1, the decision is spent, and there is
|
||||
no remote request and no record. The fixture comes after the restart, because the restart's reconcile
|
||||
ends any resolved, unspent host grant as interrupted.
|
||||
- grant-executor.test.mjs:958. An applied grant, then a restart with `ops` creative, then host.run
|
||||
refuses `host-creative-role`. No remote request is added, sudo.log has no `systemctl`, and the record
|
||||
is still there.
|
||||
|
||||
The broker clones `businesses` when it's built, so a definition change needs a new Broker. The test's
|
||||
`restart()` gains a `business` parameter, default unchanged, for that.
|
||||
|
||||
Mutants: B38 removes the `#hostDefinition` line, run against grant-host and grant-executor. B39 removes
|
||||
the `#hostAccess` line, run against grant-executor.
|
||||
|
||||
## Run 2 (sage-1928)
|
||||
|
||||
Run 2 on 534f2254a, 10:12:52-10:14:51Z, was green. grant-host.test.mjs 9 of 9, grant-executor.test.mjs
|
||||
37 of 37 and grant-enroll.test.mjs 24 of 24, each run whole. grant-enroll is unchanged, but it drives the
|
||||
broker, and broker.mjs changed. Then the five mutants, all killed, with the restore matching HEAD:
|
||||
|
||||
| Id | Killed by |
|
||||
|---|---|
|
||||
| B16 | G23 (X5), the revoke as verify returns |
|
||||
| B23 | A2, A4 |
|
||||
| B27 | G8, the store fault in the commit transaction |
|
||||
| B38 | both mos-1163 tests |
|
||||
| B39 | the sage-1908 test |
|
||||
|
||||
## Mutant results, B1-B39
|
||||
|
||||
| Run | Head | Killed | Survived |
|
||||
|---|---|---|---|
|
||||
| B1-B13, 09:22Z | 5df4b52c5 | 12 | B2 (file list) |
|
||||
| B2 alone, B14-B37, 09:28-09:37Z | 5df4b52c5 | 21 | B16, B17, B23, B27 |
|
||||
| B16 B23 B27 B38 B39, 10:13Z | 534f2254a | 5 | none |
|
||||
|
||||
38 of 39 are killed. B17 is equivalent (sage-1904), for the macrotask reason in the B1-B37 section.
|
||||
B1-B37 ran on 5df4b52c5, before the move onto row 213's landing, and weren't rerun on 534f2254a.
|
||||
`--check` matches all 39 anchors once on 534f2254a.
|
||||
|
||||
## Carry list
|
||||
|
||||
- N10 (duckworth-0084, row 234 r1): `cli/src/hosts.mjs:30-31` reads `shape[verb]` off a plain object,
|
||||
so `mosaic hosts constructor` passes usage and the bus refuses it with exit 2 instead of 4. Row b adds
|
||||
`hosts revoke` and `hosts sweep` to the same table (design r6 :562, :680), so the fix goes in with
|
||||
them: `Object.hasOwn(shape, verb)` and a usage test for an `Object.prototype` name (sage-1726).
|
||||
- Untimed tables (sage-1745, row 234 r3): stack-release T46 lists hosts and host_grants as untimed
|
||||
because every write to them shares one store transaction with a `grant.*` events row. Row a writes only
|
||||
hosts. Every host_grants INSERT, UPDATE and DELETE row b adds must do the same, and BUILD.md lists each
|
||||
with its event line. A write without one is a stop to raise with Sage.
|
||||
- N12 (duckworth-0086, row 234 r3, doc-only): row 234's round 3 list of other schema hits leaves out
|
||||
`packages/cli/tests/stack-release-fixture.mjs:214` and `scripts/test-land-work.sh:254`. Both look up
|
||||
one table by name and need no change. If row b changes the schema, its grep list names them.
|
||||
|
||||
## What row a already gives row b (b0320d395)
|
||||
|
||||
- `#approvedGrant`, `#consumeGrant(business, decision, method)` and `GRANT_EVIDENCE` (broker.mjs:667-690).
|
||||
Row b calls `#consumeGrant` with `'host'`.
|
||||
- `#openGrantDecisions(business, method)` and `reconcileGrants()` (broker.mjs:823-860), which today handle
|
||||
`host-enroll` only. Row b adds the `host` method, the `grant.step` undo table (r6 X3) and the
|
||||
revoke-marker reconcile (r6 section 6, N4).
|
||||
- The resolve hook at broker.mjs:2444-2445 starts `#runEnrollment` for `host-enroll`. Row b adds the same
|
||||
start for `host`, under the same human, via cli and choice checks.
|
||||
- `host.run` already reads the store grant record and checks the Approve record (broker.mjs:691-703).
|
||||
- The raise check `grant-chief-only` (broker.mjs:870, :896). `host-grant.mjs:55` refuses every method but
|
||||
`host-enroll`, and row b opens it to `host`.
|
||||
- `Credentials` has `#inflight` with the `host-busy` claim inside `runHost` (credentials.mjs:118, :355).
|
||||
It has no `claim`, `abortClaim`, `register` or `unregister`. Row b adds those (r6 X4, X5).
|
||||
|
||||
## Plan, in build order
|
||||
|
||||
1. Raise binding (r6 R1-R4): the `grant` argument for `method: 'host'`, `host-not-declared`,
|
||||
`host-not-ready`, the 210 D6 argv rules, `rotateBy`, the rendered block and the 4096 cap, and the raise
|
||||
body hashes. Tests G1-G5, G19.
|
||||
2. `Credentials.claim`, `release`, `abortClaim`, `register`, `unregister`, with the shared reference check.
|
||||
3. The executor in `bus/src/host-grants.mjs`, steps 1-6 (r6 X2), with failure undo (X3) and the abort rule
|
||||
(X5, C1). Tests G7-G10, G15, G23, G24.
|
||||
4. Restart reconcile for `grant.step`, unspent `host` decisions, and the start sweep of `host.<id>` key
|
||||
files with no record (r6 X3, N1). Tests G11, G27, G28.
|
||||
5. `hosts.revoke` and `hosts.sweep` verbs, plus the CLI `revoke` and `sweep` with N10. Tests G12, G13,
|
||||
G26, G27.
|
||||
6. G22 end to end on one bus. Then the mutant list from r6 section 10 for row b, numbered B1 onward in
|
||||
this file, with the upsert mutant and the abort-after-commit mutant included.
|
||||
|
||||
There is no schema step. If one turns out to be needed, I stop and ask Sage to re-brief first.
|
||||
|
||||
## Step 1 notes (raise binding, read on b0320d395)
|
||||
|
||||
Where the code goes:
|
||||
|
||||
- `#raiseGrant` (broker.mjs:866-885) runs the checks and keyscan for `host-enroll` today, and every raise
|
||||
with `grant` reaches it (:1738-1739). Row b branches on `a.grant?.method`. `host` takes no keyscan, so
|
||||
its checks can all run inside the one raise transaction, as R4 asks.
|
||||
- `enrollCheck` (host-grant.mjs:50-69) refuses every method but `host-enroll` (:55). Row b adds a sibling
|
||||
`hostGrantCheck` for the R4 shape `{method, agent, host, commands, rotateBy}` and keeps `enrollCheck`
|
||||
as it is, so the 234 tests don't move.
|
||||
- The raise body is at broker.mjs:2270, :2345-2353 and :2391. `enroll` becomes a generic `grant`
|
||||
binding. The question block for `host` follows the `host.sudo` block (:2337-2341): agent, host id,
|
||||
address, user, sudo, each prefix JSON-quoted, rotate date, and new key or changed commands. The
|
||||
4096 cap comes from `string(question)` (:2354).
|
||||
- The argv rules come from `checkCommands` (business/src/hosts.mjs:67-87): no wildcard, no empty prefix,
|
||||
no glob characters, a bare name or an absolute path, and `refusedCommand` for shells and runners. It
|
||||
throws `refuse(...)` with a message, so the bus maps any throw to `invalid-request`, as `enrollCheck`
|
||||
maps `checkAddress` (host-grant.mjs:57-61).
|
||||
- `host-not-declared`: the agent's definition must list `{"service": "host"}`. business.mjs:126-129 reads
|
||||
`definition.credentials` and filters out `HOST_SERVICE` (vocabulary.mjs:113). The bus needs the
|
||||
definition's service list. Read how the running business exposes the definition before choosing.
|
||||
- Both lookups are answered. `loadBusiness` returns `definitions`, each role file's validated document
|
||||
(business/src/business.mjs:114-124, :159, returned at :267). `busBusiness` clones the whole business
|
||||
(bus/src/business.mjs:7), so the broker has `b.definitions`. `#definitions` already reads it
|
||||
(broker.mjs:1027-1029), and the comment there says the broker doesn't read `roles/` (sage-0590).
|
||||
- `host-not-declared` checks `b.definitions[b.roles[agent].definition].credentials` for
|
||||
`{service: 'host'}`. role.mjs:118 normalizes a host entry to exactly that.
|
||||
- Deviation from R4: `definitionSha256` is sha256 over `canonicalJson` of that validated definition,
|
||||
not over the file's bytes. The broker doesn't read `roles/`. A whitespace-only edit to the file no
|
||||
longer voids an approval, but any change to a field the loader keeps still does. The bus sees a
|
||||
definition change only after a business reload or restart, the same as every other role field.
|
||||
This goes in the round 1 note.
|
||||
|
||||
Assumption, accepted for round 1 by Sage (sage-1782), for Duckworth to check in review: design R4 says `rotateBy` is "a date inside 210's rotation window", but 210
|
||||
defines no window in code. It checks only that the value is a real calendar day (bus
|
||||
credentials.mjs:16-20, issue at :245). The business load calls a past `rotateBy` a problem
|
||||
(business/src/credentials.mjs:114). So the raise takes a real day strictly after today, UTC, and refuses
|
||||
`invalid-request` otherwise. There is no upper bound, because no requirement states one and 210
|
||||
checks none.
|
||||
|
||||
## Step 1 as built (not run yet; no slot)
|
||||
|
||||
- `hostGrantCheck(grant, today)` in host-grant.mjs takes exactly `method`, `agent`, `host`, `commands` and
|
||||
`rotateBy`. `agent` must match ID_PATTERN and `host` HOST_ID. `commands` goes through `checkCommands`,
|
||||
and any throw becomes `invalid-request`. `rotateBy` must pass 210's `day` (now exported from bus
|
||||
credentials.mjs) and be later than the bus clock's UTC day.
|
||||
- `#raiseGrant` branches on `a.grant?.method === 'host'` after the chief check and before `enrollCheck`.
|
||||
So a host-enroll shape with `method: 'host'` still refuses `invalid-request`, and the 234 G1 list holds.
|
||||
- `#hostGrantBinding` runs inside the raise transaction. It refuses `unknown-role` for an agent that
|
||||
isn't a role instance (the code bindLaunch uses, broker.mjs:522). It refuses `host-not-declared`, and
|
||||
`host-unknown` for a host with no record, as `#hostAccess` does. A record in `pending-install` refuses
|
||||
`host-not-ready`. R4 names only `host-not-ready`. I picked `host-unknown` for a missing record so
|
||||
"not enrolled" and "enrolled but not checked" stay apart.
|
||||
- `commandsSha256` is sha256 over `JSON.stringify(commands)`. For arrays of strings this equals
|
||||
canonicalJson, and step 3's executor recomputes it the same way.
|
||||
- `#dispatch` takes `binding = {body, block}` in place of `enroll`. The enrollment block moved into
|
||||
`enrollBinding` at module level with its text unchanged, so the 234 G4 test reads the same question.
|
||||
- No new import in broker.mjs, so RUNNER_FILES doesn't change. host-grant.mjs now imports
|
||||
business/src/util.mjs for canonicalJson. Nothing in the sandbox loads host-grant.mjs. Before in-review
|
||||
I still run seat sandbox.test.mjs and bus project-runtime.test.mjs whole.
|
||||
- The new-key line reads host_grants (a SELECT). Step 1 writes no host_grants row.
|
||||
- Tests: bus/tests/grant-host.test.mjs, G1 (host), G2, G3, rotateBy, G19, R4/G5 body hashes, G4 block.
|
||||
The G5 tester-thread case: a thread run is always THREAD_DEFINITION, never chief-of-staff, so
|
||||
`grant-chief-only` refuses it first. The test covers the tester's own cap (`tester-refused`).
|
||||
|
||||
## Step 2 as built (not run yet)
|
||||
|
||||
- The constructor's per-reference checks moved into `#checkRef`, in the same order, and `register` calls
|
||||
it (r6 X4). `register` reads no file. A key file that a failed revoke unlink left at the path stays
|
||||
unused until the start sweep (step 4) removes it. `register` refuses `credential-reference` while the
|
||||
entry holds a live token. An entry with no token, revoked or never issued, is replaced, so a new grant
|
||||
after a revoke registers again.
|
||||
- `unregister` drops an entry with no token and clears its revoked mark. A live token refuses.
|
||||
- `claim` refuses `host-busy` when the slot is held, by a claim or a `host.run`, and returns the signal.
|
||||
It needs no reference, because the executor claims at step 1 and registers at step 5.
|
||||
`release(instance, service, signal)` frees the slot only for its own signal. I added the signal
|
||||
argument so a late release can't free a later claim.
|
||||
- `abortClaim` aborts whatever holds the slot and returns `{pending}`. An aborted claim keeps the slot
|
||||
until the executor releases it in its `finally` (X2).
|
||||
- Tests: bus/tests/credential-claim.test.mjs. The D5 `use(` allowlist is unchanged.
|
||||
|
||||
## Step 3 as built (not run yet)
|
||||
|
||||
Where the code goes. The remote steps are in host-grant.mjs (`grantKey`, `install`, `verify`, `remove`)
|
||||
and the orchestration is `#runHostGrant` in broker.mjs, next to `#runEnrollment`. BUILD.md's plan said a
|
||||
new `bus/src/host-grants.mjs`. I kept row 234's split instead: the broker holds every store write and
|
||||
host-grant.mjs holds the network and key files. A new broker import would also change what the sandbox
|
||||
must mount (RUNNER_FILES), and this way broker.mjs gains none.
|
||||
|
||||
The broker gets `hostKeys`, made by `grantKeys({credentials, storeRoot})` in host-grant.mjs. It wraps
|
||||
only `claim`, `release`, `abortClaim`, `register`, `unregister`, `issue` and `revoke`, keyed by
|
||||
(business, agent, hostId). The broker still never gets `use()`. runtime.mjs builds it and passes it in.
|
||||
`hostReference` gives the store reference, and the runtime's start load uses the same function.
|
||||
|
||||
Every host_grants write in step 3, with its event (sage-1745):
|
||||
|
||||
| Write | Where | Event in the same transaction |
|
||||
|---|---|---|
|
||||
| INSERT, a new key | the `commit` callback that `issue` calls | `grant.applied` |
|
||||
| UPDATE commands and decision, a commands change | step 5's transaction | `grant.applied` |
|
||||
|
||||
No other step 3 code writes host_grants.
|
||||
|
||||
Deviations from r6, for the round 1 note:
|
||||
|
||||
- `grant.applied` commits with the record, inside `commit`, not after `issue` at step 6. The untimed-table
|
||||
rule needs an event in the record's transaction. `grant.step commit` can't be that event, because X2
|
||||
writes it before the key file. So X3's "5 after commit" row has nothing to undo in the executor: once the
|
||||
record commits, `grant.applied` has too. What's left in `issue` after `commit` is the memory fill, which
|
||||
writes no file and no store row. The executor sets `committed` after the transaction returns and from
|
||||
then ignores an abort (C1). The restart reconcile (step 4) keeps the commit row, because a crash can fall
|
||||
between the key file write and `commit`.
|
||||
- Event bodies name the decision as `grantDecision`, as row 234's enrollment events do. The consume record
|
||||
is the only grant body with `decision`, so `#spent` counts it and nothing else.
|
||||
- For a commands change, `grant.applied` has `fingerprint: null`. The executor holds no key on that path.
|
||||
The record's `rotate_by` stays. X2 names only commands and the decision id.
|
||||
- The keygen dir goes as soon as `grantKey` has read the key back into memory, not in step 5's `finally`.
|
||||
- Step 4 runs `true` as the remote command as is, not through the sudo argv, since a user with no sudo
|
||||
must pass it too.
|
||||
- `hostGrant()` takes `installerUser`, `mosaic-installer` by default. Only the tests change it, because
|
||||
the scratch sshd logs in only as the test's own user.
|
||||
- A commands-change UPDATE that changes no row ends `host-changed`. Only a revoke deletes a live record,
|
||||
and a revoke aborts the claim first, so this is a guard.
|
||||
|
||||
Step 1 codes, after the spend and in its transaction: `host-not-configured`, `unknown-role`,
|
||||
`host-not-declared`, `decision-mismatch` (definition, registry or commands hash), `host-unknown`,
|
||||
`host-not-ready`, `revoked` (a `grant.revoked` of the agent and host after the raise). The definition
|
||||
check moved into `#hostDefinition`, which the raise binding uses too.
|
||||
|
||||
Tests: bus/tests/grant-executor.test.mjs, a scratch sshd on 127.0.0.1 with stub `list`, `add` and
|
||||
`remove` that edit a second authorized-keys file. G7 (new key, and a commands change), G8 (install, verify,
|
||||
a failed remove, step 5 before commit, a failed step 1 check), G9, G10, G15, G23 (a revoke during install
|
||||
through `abortClaim`, a `grant.revoked` before start, and a held slot), G24's tag part. G23's held slot
|
||||
uses `claim` in place of a running `host.run`. Both hold the same `#inflight` entry. The `revoke` verb
|
||||
comes in step 5, so G23 here writes `grant.revoked` through the fixture writer and aborts through
|
||||
`abortClaim`. Step 5 adds the verb's own path.
|
||||
|
||||
## Step 4 as built (not run yet)
|
||||
|
||||
The restart reconcile has three parts, in start order:
|
||||
|
||||
1. `sweepHostKeys` (host-grant.mjs), in runtime.mjs right before `Credentials` loads. In each loaded
|
||||
business's agent store it unlinks every `host.<id>` file that has no `host_grants` record, and logs
|
||||
one `hosts: {"event":"host-key-swept",...}` line per file to stderr. A store dir that isn't private
|
||||
refuses `credential-file`, and so does the start. A name that isn't `host.` plus a valid host id
|
||||
stays, so ssh-keygen's `.pub` stays too. A business the bus didn't load is left alone.
|
||||
2. `reconcileGrants`, where row 234 already calls it, after `Credentials` loads and before the socket
|
||||
opens. For a `host` grant it ends a spent decision that has no `grant.applied` and no `grant.failed`.
|
||||
It also spends and ends an unspent one the human resolved yes. Each ends `grant.failed interrupted`,
|
||||
with the tag and a notice. When the last step is `install`, or `commit` with `previous: null`, a line
|
||||
may be left. For those, it claims the (agent, `host.<id>`) slot and queues the decision for part 3.
|
||||
3. `reconcileHosts`, which runtime.mjs calls once `serve` returns, with no await, so a start doesn't
|
||||
wait on the network. Each queued decision runs `remove <user> <tag>` through the installer, as the
|
||||
step's `user`. Then it ends `grant.failed interrupted`, with `hostLineLeft` if the remove failed or
|
||||
there's no host record, and releases the claim. The claim makes a new grant for the same agent and
|
||||
host refuse `host-busy` while the remove runs. Otherwise its new line, with the same tag, could be
|
||||
removed.
|
||||
|
||||
Deviations from r6's restart table, for the round 1 note:
|
||||
|
||||
- No record write on restart. Step 3 commits the record with `grant.applied` in one transaction. So a
|
||||
decision with no `grant.applied` has no record. For a new key, the record undo has nothing to delete.
|
||||
For a commands change, the "back to `previous`" undo has nothing to put back. What's left of the
|
||||
`commit, new key` row is the key file, written before `commit`, and the start sweep unlinks it.
|
||||
The `commit, commands change` row ends interrupted with nothing undone. G28's "a revoke before
|
||||
`grant.applied`" can't happen, because they commit together. Step 5 tests G28 as a change, then a
|
||||
revoke, then a restart.
|
||||
- The local undo of row 234's enrollments stays after `Credentials` loads, where row 234 put it. That
|
||||
undo touches only the installer key and the host record, and `Credentials` reads neither.
|
||||
- The host grant part writes no `host_grants` row, so the untimed-table rule (sage-1745) adds nothing
|
||||
here.
|
||||
|
||||
Fixture change: `hostGrantRecord` (tests/host-fixtures.mjs) writes `grant.applied` after a `grant.host`
|
||||
spend, as the executor always does. Without it, a start over a fixture record ends that record's
|
||||
decision `interrupted`. Row 234's M3 start test (host-run.test.mjs:602) does that start. No test counts
|
||||
the fixture's grant events (checked by grep across the bus tests).
|
||||
|
||||
Tests in grant-executor.test.mjs, through a `restart` helper that follows runtime.mjs's order on the
|
||||
same store:
|
||||
|
||||
- G11 after `install`: the line goes, the slot is held between the two parts, and the grant ends
|
||||
interrupted. A second start adds nothing, and `runHostGrant` refuses `decision-consumed`.
|
||||
- G11 after a new key's `commit` with the key file written: no key file, record, reference or line.
|
||||
- G11 after a change's `commit`: the record, key and line are unchanged, and the host gets no request.
|
||||
- G11 (B2) before step 1, spent and unspent: each ends interrupted with a notice, and the unspent one
|
||||
is spent exactly once.
|
||||
- A failed remote undo, and a missing host record: each ends with `hostLineLeft` and the sweep hint.
|
||||
- A finished grant: the reconcile adds nothing.
|
||||
- N1 (G27's sweep part): only files with no record in loaded businesses go, and a dir that isn't private
|
||||
refuses.
|
||||
|
||||
The revoke-marker part of the reconcile (section 6, N4) comes with the revoke verb in step 5.
|
||||
|
||||
## Step 5 as built (not run yet)
|
||||
|
||||
Two new bus verbs, `hosts.revoke` and `hosts.sweep`, join `HOSTS_VERBS`. The CLI gets
|
||||
`mosaic hosts revoke AGENT HOST --reason R` and `mosaic hosts sweep HOST`.
|
||||
|
||||
`hosts.revoke {agent, host, reason}` follows r6 section 6:
|
||||
|
||||
1. One transaction deletes the `host_grants` record and writes `grant.revoked` with a new `revoke` id
|
||||
(a UUID), the computed tag, `hostLine: "pending"`, `granted`, `reason` and `by`. With no record it
|
||||
still writes the marker, with `granted: false`, so a stale line can be named (N4). A host with no
|
||||
record refuses `host-unknown` and writes nothing.
|
||||
2. With no await between, `Credentials.revoke` drops the key from memory, aborts a `host.run` in flight
|
||||
and unlinks the file. With no reference (`credential-unknown`), an executor holds only a claim, so
|
||||
`abortClaim` stops it. Any other throw, such as an unlink that fails, comes back as `keyFile: "left"`.
|
||||
The record is already gone, so the next start's sweep unlinks that file.
|
||||
3. `remove <user> <tag>` through the installer, as the host record's user (the executor's user too).
|
||||
Then `grant.revoke.closed` with the same `revoke` id and `hostLine: "removed"`, or `hostLineLeft`.
|
||||
|
||||
Callers (G26): the human, and the assistant of the session's business, checked with `#threaded`. The
|
||||
tester can call it when `bus.tester` is exactly `true`, read again at the call. Any other agent gets
|
||||
`revoke-refused`, a code new in this row. A tester session can't hold a business whose `bus.tester`
|
||||
isn't `true`, since `bindTester` refuses `tester-off`, and the broker's businesses don't change while
|
||||
it runs. So `tester-dev-only` can't be reached from a test. The check stays for N8, in case a later
|
||||
row reloads businesses.
|
||||
|
||||
`hosts.sweep {host}` is the human's or the tester's; an agent gets `human-required`. It runs
|
||||
`list <user>`, then removes each listed tag that this business recorded for the host in a `grant.step`
|
||||
or `grant.revoked` and that no live grant holds. Another business's line and an unrecorded `mosaic-`
|
||||
line stay (G24's sweep part). It writes `grant.host.swept {host, removed, left, by}`, where `left` is
|
||||
each earlier left tag still listed and not removed. `#hostLinesLeft` now starts from the last
|
||||
`grant.host.swept` and adds only later `hostLineLeft` bodies (F4).
|
||||
|
||||
The restart reconcile adds the marker part: `reconcileGrants` collects each `grant.revoked` with
|
||||
`hostLine: "pending"`, a text `revoke` id and no `grant.revoke.closed` of that id. `reconcileHosts`
|
||||
runs step 3 for each. A `grant.revoked` with no `revoke` id, as G23's fixtures write, isn't reopened.
|
||||
`hosts.status` adds `revoking`, the tags of the open markers on the host.
|
||||
|
||||
Other changes:
|
||||
|
||||
- N10: the CLI checks the verb with `Object.hasOwn`, so `constructor`, `toString` or `__proto__` is a
|
||||
usage error.
|
||||
- `--reason` is required with `revoke` and refused with any other verb.
|
||||
- The reason goes through the broker's `string(x, 500)`, as `credentials.revoke`'s does, so a reason of
|
||||
only spaces is accepted there too.
|
||||
- Correction to step 4: the first G11 test expected `list` then `remove`. `reconcileHosts` sends only
|
||||
`remove`, so the test now expects that.
|
||||
|
||||
Residuals for the round 1 note:
|
||||
|
||||
- A new grant whose line goes in while a revoke's step 3 or a sweep runs can lose that line, if it has
|
||||
the revoked tag. Revoke holds no claim during step 3. If the remove lands after the new grant's
|
||||
verify, the grant is recorded but its line is gone, so its logins fail. I didn't add a claim, because
|
||||
a revoke must not wait on a slot.
|
||||
- The enrollment's installer tag is never in the sweep's set, so a `hostLineLeft` naming it stays
|
||||
until the human removes it by hand.
|
||||
|
||||
Tests in grant-executor.test.mjs:
|
||||
|
||||
- G12: the human's revoke of a live grant, and the bodies of both markers. A restart adds nothing.
|
||||
- G12 (N4): a revoke with no record removes the computed tag's line. Bad args refuse
|
||||
`invalid-request` and an unknown host `host-unknown`.
|
||||
- G13: a revoke during `install` aborts the executor, which ends `revoked`. A raise before a revoke
|
||||
and started after it ends `revoked` at step 1.
|
||||
- G26: who may revoke and who may sweep.
|
||||
- G27: a restart after step 1 (the sweep takes the key file, then step 3 runs), after step 2 with the
|
||||
host down (`hostLineLeft`, then a sweep clears it), and a file a revoke couldn't unlink.
|
||||
- G28: a commands change, then a revoke, then a restart.
|
||||
- G24 (B4): the sweep's tag set, a failing `list`, and the left list it records.
|
||||
|
||||
The CLI tests in packages/cli/tests/hosts.test.mjs cover revoke and sweep, the N10 usage cases and the
|
||||
`revoking` field in a status line.
|
||||
|
||||
## Step 6 as built (not run yet)
|
||||
|
||||
New tests in grant-executor.test.mjs:
|
||||
|
||||
- G22 (B1), one bus with no restart. The chief enrolls web1, the human approves, and `hosts.check`
|
||||
marks it ready. A grant of `echo` follows, then a `host.run` of `echo hi` that prints `hi`. A
|
||||
`sleep` raise refuses `command-not-granted`, and after a commands change to `echo` and `sleep` the
|
||||
next `host.run` of `sleep 30` starts. A revoke kills that run with `credential-unavailable`. The next
|
||||
call refuses `host-not-granted`.
|
||||
- G12: the local steps finish before the host step. With the host's `remove` held, the record and key
|
||||
file are already gone and `hosts.status` shows the tag under `revoking`.
|
||||
- G13: a revoke whose host `remove` fails returns `hostLineLeft`, drops the record and key, and closes
|
||||
the marker, so a restart adds nothing.
|
||||
- G23 (X5): a revoke right after the executor's spend reaches its claim and the grant ends `revoked`.
|
||||
- G23 (X5): a revoke that lands as `verify` returns ends `revoked` with no record, key file or line.
|
||||
Only the abort check after `verify` catches it.
|
||||
|
||||
The fixture gains a `sudo` stub (logs to sudo.log, then runs the command as the test's user), a
|
||||
`hold-remove` flag, `opts.enroll` (no host record and no installer key) and `opts.wrap` (changes the
|
||||
host API the broker gets). `hostGrant` gets a fake `scan` that returns the scratch sshd's host key.
|
||||
|
||||
G22 deviations, for the round 1 note:
|
||||
|
||||
- `checkAddress` (business/src/hosts.mjs:62) refuses this machine's address, so the test enrolls
|
||||
192.0.2.10 with the fake keyscan. It then points the record at the scratch sshd with an SQL update
|
||||
and adds the enrolled installer key to the sshd's authorized keys. Enrollment, check, grant, run and
|
||||
revoke all go through the real code after that.
|
||||
- r6 B1 says the next `host.run` after a revoke refuses `credential-unavailable`. Here it refuses
|
||||
`host-not-granted`, because step 1 deletes the record and `requestHost` checks the record
|
||||
(`#hostAccess`) before it reaches the key. The call in flight does refuse `credential-unavailable`.
|
||||
|
||||
### Mutants
|
||||
|
||||
`/mnt/storage/scratch/gizmo-235-out/mutants.py` holds each mutant as anchored edits. `--check` applies
|
||||
them in memory and runs no test. All 39 anchors match once. Each mutant runs its named test files.
|
||||
|
||||
From r6 section 10, as they apply to row b:
|
||||
|
||||
| Id | Mutant | Test file |
|
||||
|---|---|---|
|
||||
| B1 | drop the chief check on a host grant raise | grant-host (G1) |
|
||||
| B2 | start the executor on a `credential.mint` with no `grant` | grant-enroll (A2), grant-executor |
|
||||
| B3 | skip the `ready` check at the raise | grant-host (G19) |
|
||||
| B4 | skip the `ready` check at step 1 | grant-executor |
|
||||
| B5 | skip the definition hash compare | grant-executor (G9) |
|
||||
| B6 | drop the definition check (`host-not-declared`) | grant-host (G2), grant-executor (G9) |
|
||||
| B7 | skip the commands hash compare | grant-executor (G9) |
|
||||
| B8 | skip the host record hash compare | grant-executor (G9) |
|
||||
| B9 | write the grant record before install | grant-executor (G8) |
|
||||
| B10 | skip `remove` on a verify failure | grant-executor (G8) |
|
||||
| B11 | skip the start sweep of key files with no record | grant-executor (N1, G27) |
|
||||
| B12 | skip the reconcile's remote `remove` | grant-executor (G11) |
|
||||
| B13 | skip the `grant.step` before install | grant-executor (G11) |
|
||||
| B14 | revoke leaves the grant record | grant-executor (G12) |
|
||||
| B15 | skip `register` before `issue` | grant-executor (G7) |
|
||||
| B16 | drop the abort check after `verify`, the last one before `issue` | grant-executor (G23 X5) |
|
||||
| B17 | add an `await` between the abort check and `issue` | grant-executor |
|
||||
| B18 | revoke ignores a claim with no reference | grant-executor (G13, G23 X5) |
|
||||
| B19 | build the tag without the business | grant-executor (G24) |
|
||||
| B20 | `sweep` removes any `mosaic-` line | grant-executor (G24 B4) |
|
||||
| B21 | run revoke's host step before the local steps | grant-executor (G12) |
|
||||
| B22 | start the executor on an arbiter resolve | grant-executor (G10) |
|
||||
| B23 | start it on `no` | grant-enroll (A2, A4), grant-executor |
|
||||
| B24 | write the private key into the event body | grant-executor (G15) |
|
||||
| B25 | put an `await` between the spend and the claim | grant-executor (G23 X5) |
|
||||
| B26 | skip the start check for a resolved, unspent grant decision | grant-executor (G11 B2) |
|
||||
| B27 | make `commit` async | grant-executor (G8) |
|
||||
| B28 | route `hosts.revoke` to `Credentials.revoke` alone, as `credential-verbs.mjs` would | grant-executor (G12, G27) |
|
||||
| B29 | skip the revoke marker reconcile | grant-executor (G27) |
|
||||
|
||||
Row 235's own:
|
||||
|
||||
| Id | Mutant | Test file |
|
||||
|---|---|---|
|
||||
| B30 | skip the `grant.revoked` check at step 1 | grant-executor (G13, G23) |
|
||||
| B31 | the sweep set keeps a live grant's tag | grant-executor (G24 B4) |
|
||||
| B32 | reopen a `grant.revoked` with no revoke id | grant-executor (G27) |
|
||||
| B33 | step 3 reports `removed` when the host remove fails | grant-executor (G13, G27) |
|
||||
| B34 | any agent revokes, not just the assistant | grant-executor (G26) |
|
||||
| B35 | `hostLineLeft` ignores the last sweep | grant-executor (G24 B4, G27) |
|
||||
| B36 | a stale `release` frees a later claim | credential-claim (X5), grant-executor |
|
||||
| B37 | `register` replaces an entry with a live token | credential-claim (X4) |
|
||||
| B38 | drop the creative check in `#hostDefinition` | grant-host (mos-1163), grant-executor (mos-1163) |
|
||||
| B39 | drop the creative check in `#hostAccess` | grant-executor (sage-1908) |
|
||||
|
||||
B17 may survive. `await null` yields only to microtasks, and every revoke starts in a macrotask of its
|
||||
own (a socket request, or a test's call), so none can land in that gap. If it survives I'll report it
|
||||
as equivalent under this build, not add a test that fakes a microtask revoke.
|
||||
|
||||
Section 10 items not run as row b mutants, and why:
|
||||
|
||||
- The upsert mutant ("let the undo to `previous` insert a record") and "run past a newer
|
||||
`grant.revoked`". Row 235 has no undo to `previous`. A commands change commits the UPDATE and
|
||||
`grant.applied` in one transaction (sage-1745), so a restart after it leaves the record as it is
|
||||
(G11). The UPDATE can't meet a missing record either: step 1 reads the live record, and nothing
|
||||
awaits between there and the UPDATE. An upsert there would be equivalent.
|
||||
- "let the executor act on an abort after step 5 commits". The record and `grant.applied` commit
|
||||
together, and no abort check follows the commit, so no code path reaches the `if (committed)` guard
|
||||
with an abort. Removing the guard is equivalent. C1's case is covered by G28 with a later revoke.
|
||||
- "treat a missing `bus.tester` as dev". The tester check can't be reached from a test (step 5 notes).
|
||||
- Row a's: the keyscan compare, the writer items, the "not yet enrolled" check, the `hosts` primary key
|
||||
and `host.run` reading the business file. Row 234 ran those as A5, A6, A8, A9, A11 and A13-A19.
|
||||
@@ -1,53 +0,0 @@
|
||||
# Row 212 build notes, C2-01 packages/library (#1713, Vikunja #416)
|
||||
|
||||
## Rounds
|
||||
|
||||
- Round 1: bdf18272a on gosalyn/c2-01, base 32b54ac3b. Webby approved it in Gitea comment 29704.
|
||||
- Round 2: d3c7bbf839d9c3bf50f154b18e7e4472fbd005ed on gosalyn/c2-01-r2, rebased onto 9b5362018 after row 232 drifted three paths (sage-1714). Webby approved it at merge scope, rev 2666 against comment 29921 (webby-0052).
|
||||
- Round 3: this commit on gosalyn/c2-01-r3, one commit on the row 234 landing c771a36f4 (sage-1736, sage-1779, mos-1160). Row 234 changed scripts/mosaic, so round 3 review covers that one file.
|
||||
|
||||
## Round 2 merge
|
||||
|
||||
range-diff 32b54ac3b..bdf18272a against 9b5362018..d3c7bbf83 shows one change, the context line where upstream added `credentials` to the scripts/mosaic case line. Patch-id moved from 8f80dfa3 to 175f45c6 for that reason only. All three drifted hunks keep both sides:
|
||||
|
||||
- scripts/stack-copy.sh COPY_PATHS reads `packages/queue/src packages/library/src`. Row 232's bundle, --create, --units and instance code is unchanged.
|
||||
- scripts/mosaic runs the `library survey` exec block before the case line, and the case line keeps `credentials`.
|
||||
- packages/cli/tests/stack-copy.test.mjs adds `packages/library/src/index.mjs` to the copy file list.
|
||||
|
||||
## Round 2 singles, evidence for the 19 paths other than scripts/mosaic
|
||||
|
||||
Run on d3c7bbf83 in Sage's slot (sage-1723) from 2026-10-21T05:00:09Z to 05:11:29Z. The HEAD and a clean tree were checked first. The counts are an awk sum over the 23 logs: 481 passed, 0 failed, 0 skipped, 0 cancelled, and every file exited rc=0.
|
||||
|
||||
| Package | File | Pass |
|
||||
|---|---|---|
|
||||
| library | links | 6 |
|
||||
| library | mapping | 7 |
|
||||
| library | reader | 11 |
|
||||
| library | render | 11 |
|
||||
| library | survey | 4 |
|
||||
| cli | app | 30 |
|
||||
| cli | case2-unit | 30 |
|
||||
| cli | credentials | 5 |
|
||||
| cli | host | 42 |
|
||||
| cli | instances | 5 |
|
||||
| cli | project | 4 |
|
||||
| cli | stack-copy | 16 |
|
||||
| cli | stack-instances | 23 |
|
||||
| cli | stack-release-external | 25 |
|
||||
| cli | stack-release | 192 |
|
||||
| cli | tester-reads | 6 |
|
||||
| cli | tester-threads | 5 |
|
||||
| cli | usage | 2 |
|
||||
| queue | dispatch | 4 |
|
||||
| runs | task-cli | 9 |
|
||||
| webui | pinned-copy | 10 |
|
||||
| webui | service | 31 |
|
||||
| webui | views | 3 |
|
||||
|
||||
The file list comes from the library tests plus every test that names scripts/mosaic or stack-copy.sh, by basename and by join() path. No 64-hex pin in the tests names a merged path.
|
||||
|
||||
## Round 3 scripts/mosaic
|
||||
|
||||
The only path both row 234 and this row change is scripts/mosaic. Row 234 added `hosts` to the cli case line and changed nothing else in the file. Round 3 takes the landed blob cce1fdee4 and adds this row's six-line `library survey` block before the case line by hand, so `hosts` stays. The mode stays 100755. The other 19 paths are byte-identical to d3c7bbf83. Against d3c7bbf83 the only difference is the `hosts` context line.
|
||||
|
||||
Round 3 runs only the tests that read scripts/mosaic, in Sage's slot. Their counts go to Sage in T3 and onto #1713, since this file can't hold them and stay one commit. Those tests are library survey, cli app, case2-unit, credentials, hosts, host, instances, project, stack-copy, stack-release, stack-release-external, stack-upgrade, tester-reads, tester-threads and usage, queue dispatch, runs task-cli, webui pinned-copy, service and views, plus scripts/test-queue.sh. hosts.test.mjs is new with row 234.
|
||||
@@ -1,158 +0,0 @@
|
||||
# Row 221 build notes, C2-20 Bean and Chet persona import (#1722, Vikunja #416)
|
||||
|
||||
Brief: docs/plans/2026-10-20_case2-rows.md "C2-20", blob 16847e94ae17 (sage-1834). Claimed rev 2736.
|
||||
Rulings: sage-1836 (fence, pairing) and sage-1840 (YAML parser, handoff).
|
||||
|
||||
## Base
|
||||
|
||||
Built on Morgana's row 213 r4 tip 2b3e67e36 (origin/morgana/row213-r4), since the brief says "After:
|
||||
C2-08" and 221 exports 213's fence check. Before review it goes onto 213's landing under a new branch
|
||||
name, and its tests run again there.
|
||||
|
||||
## What changed
|
||||
|
||||
- `scripts/case2-persona-import.mjs`, new. Verbs `stage` and `install`, usage in its header.
|
||||
- `packages/cli/tests/case2-persona-import.test.mjs`, new, and `packages/cli/tests/fixtures/case2-persona-import/`,
|
||||
a fixture Hermes home plus `trace.mjs`, the read trace.
|
||||
- `packages/harness/src/bundle.mjs`: the three text rules in `readPersona` move into an exported
|
||||
`personaTextFault(text)`, which returns null or the reason, and `readPersona` calls it. Nothing it
|
||||
checks changes and the messages are byte for byte the same, so 213's creative tests hold. There is
|
||||
one copy of the rules and the import calls it (sage-1836).
|
||||
- `package.json` and `package-lock.json`: `yaml` 2.9.0 becomes an exact direct dependency (sage-1840 Q3).
|
||||
|
||||
## Rulings recorded
|
||||
|
||||
Profile to name (sage-1836, answers DESIGN.md:1322 as an implementation ruling, not a PRD change).
|
||||
Hermes at df5700ebe has no field holding a profile's own name. `profile.yaml` has only `description`
|
||||
and `description_auto` (hermes_cli/profiles.py:798-850), and `agent_name` at cli.py:3494 is skin
|
||||
branding with the default "Hermes Agent". So the human passes the pairing as `--pair default=Bean
|
||||
--pair chet=Chet`. The script checks both profile directories exist, each name is exactly Bean or Chet
|
||||
and the two differ, then prints the pairing with each SOUL.md's byte count and sha256 before it writes.
|
||||
The brief's "confirm profile to name" is met by the human supplying and confirming the pairing.
|
||||
|
||||
The persona is `<profile dir>/SOUL.md`, where Hermes loads it (agent/prompt_builder.py:1829-1855).
|
||||
The default profile's directory is the Hermes root, and others are `profiles/<name>`, with names
|
||||
checked against hermes_cli/profiles.py:37. A missing or blank SOUL.md is "no persona", as in Hermes.
|
||||
The file is staged byte for byte. Hermes strips it and runs its own scan before use, but this import
|
||||
copies her text unchanged.
|
||||
|
||||
Handoff between the steps (sage-1840 Q4). `stage` writes 0600 files owned by whoever ran it. `install`
|
||||
runs as `<user>` and refuses a staging file that isn't its own or has a group or other bit. The script
|
||||
changes no owner. It prints the root step, `chown -R <user>: <staging>`, as an instruction. **Item for
|
||||
Jason's go:** who runs stage on `<host>`, and the root chown between the two steps.
|
||||
|
||||
## Word list
|
||||
|
||||
69 tool names: every literal `name="..."` in a `registry.register(` call under hermes-agent's
|
||||
`tools/*.py` at df5700ebe, plus Hermes and Discord. Two more registrations, in tools/mcp_tool.py:4997
|
||||
and :5034, and plugin tools (hermes_cli/plugins.py:430) get their names at run time, so a fixed list
|
||||
can't hold them. Matching is whole word, any case. `memory`, `terminal`, `todo`, `process`, `patch` and
|
||||
`clarify` are ordinary words, so a persona line using them in prose counts, and the count leans high.
|
||||
It is a hint for Jason and changes nothing in the import.
|
||||
|
||||
## Channel prompts
|
||||
|
||||
Hermes takes a platform's block from `<platform>` at the top level of config.yaml, else from
|
||||
`platforms.<platform>` or `gateway.platforms.<platform>` (gateway/config.py:1159-1178), and its
|
||||
prompts from `channel_prompts` (:1233). The script lists all three by platform, channel id and byte
|
||||
count, and says "not text" for a value that isn't a string. The dry run doesn't read config.yaml.
|
||||
|
||||
yaml parses with `intAsBigInt`, so an unquoted 18 or 19 digit Discord id prints exactly instead of
|
||||
rounding as a double, and with `uniqueKeys: false`, so a repeated key keeps the last value as Python's
|
||||
`safe_load` does. `logLevel: "silent"` stops yaml's warnings, which quote config text. yaml reads YAML
|
||||
1.2 and Hermes's PyYAML reads 1.1. They differ on scalars such as `yes` and `0123`, but neither
|
||||
changes a channel prompt's key or its byte count for a quoted or decimal id.
|
||||
|
||||
## yaml dependency (sage-1840 Q3)
|
||||
|
||||
Made with `npm install --save-exact [email protected] --package-lock-only --ignore-scripts` at the worktree
|
||||
root. `git config core.hooksPath` was unset before and after. npm moved nothing else:
|
||||
|
||||
```
|
||||
package-lock.json | 3 ++-
|
||||
package.json | 3 ++-
|
||||
2 files changed, 4 insertions(+), 2 deletions(-)
|
||||
```
|
||||
|
||||
```
|
||||
@@ -10,7 +10,8 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-coding-agent": "0.85.1",
|
||||
- "oauth4webapi": "3.8.8"
|
||||
+ "oauth4webapi": "3.8.8",
|
||||
+ "yaml": "2.9.0"
|
||||
}
|
||||
},
|
||||
```
|
||||
|
||||
node_modules/yaml is 2.9.0, from the pinned pi packages (package-lock.json:502 and :556).
|
||||
|
||||
Where it runs. `scripts/case2-persona-import.mjs` isn't in stack-copy's COPY_PATHS, and a copy carries
|
||||
no node_modules of its own beyond its `npm ci`. So the script runs from a checkout at the reviewed
|
||||
commit after `npm ci`, where `import "yaml"` resolves through the root package.json and
|
||||
`../packages/harness/src/bundle.mjs` is beside it. Whoever runs `stage` needs read access to that
|
||||
checkout and to her Hermes home, which is part of the item for Jason's go above.
|
||||
|
||||
## Tests
|
||||
|
||||
Round 1, on 213 r4 2b3e67e36, slot grants sage-1851 and sage-1863. One `node --test` per file.
|
||||
|
||||
Run 1 started at 08:19:44Z. A 600 s tool timeout on my wrapper killed it at about 08:29:45Z, inside
|
||||
stack-release-external, after stack-release took 494 s. One test in this row's file failed in run 1.
|
||||
Its filter `includes("per-channel prompt")` also matched the "profile chet: no per-channel prompts"
|
||||
line that the next assert checks on its own. That was a test defect, and the script's output was
|
||||
right. The filter is now `includes(": per-channel prompt ")`. The kill orphaned one fixture
|
||||
holder.cjs, which I killed, and I removed its tmp dirs. Sage counts this as one failure under mos-0823.
|
||||
|
||||
The rerun, 08:31:11Z to 08:33:31Z, covered this row's file, stack-release-external, stack-upgrade
|
||||
and the fixture dry run. The 15 files that run 1 finished green stand on code the fix didn't touch. Their counts come from run 1.
|
||||
|
||||
| File | pass | fail |
|
||||
|---|---|---|
|
||||
| packages/business/tests/launch-settings.test.mjs | 16 | 0 |
|
||||
| packages/cli/tests/stack-copy.test.mjs | 16 | 0 |
|
||||
| packages/cli/tests/stack-release.test.mjs | 195 | 0 |
|
||||
| packages/conversation/tests/cohort.test.mjs | 37 | 0 |
|
||||
| packages/harness/tests/bundle.test.mjs | 22 | 0 |
|
||||
| packages/harness/tests/claude-gate.test.mjs | 3 | 0 |
|
||||
| packages/harness/tests/claude-session.test.mjs | 8 | 0 |
|
||||
| packages/harness/tests/creative.test.mjs | 7 | 0 |
|
||||
| packages/harness/tests/mcp-server.test.mjs | 5 | 0 |
|
||||
| packages/harness/tests/pi-session.test.mjs | 8 | 0 |
|
||||
| packages/harness/tests/skills.test.mjs | 10 | 0 |
|
||||
| packages/plugins/tests/harness.test.mjs | 9 | 0 |
|
||||
| packages/seat/tests/sandbox.test.mjs | 10 | 0 |
|
||||
| packages/webui/tests/editor.test.mjs | 5 | 0 |
|
||||
| packages/webui/tests/pinned-copy.test.mjs | 10 | 0 |
|
||||
| packages/cli/tests/case2-persona-import.test.mjs | 11 | 0 |
|
||||
| packages/cli/tests/stack-release-external.test.mjs | 25 | 0 |
|
||||
| packages/cli/tests/stack-upgrade.test.mjs | 20 | 0 |
|
||||
|
||||
Total over the 18 files: 417 pass, 0 fail, 0 cancelled, summed by awk.
|
||||
|
||||
The dry run on the fixture, `stage --hermes-root packages/cli/tests/fixtures/case2-persona-import/hermes
|
||||
--pair default=Bean --pair chet=Chet --dry-run`, exited 0 and printed:
|
||||
|
||||
```
|
||||
files 2
|
||||
profile default: lines 3, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0
|
||||
profile chet: lines 2, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0
|
||||
```
|
||||
|
||||
## Rebase onto 213's landing (sage-1925)
|
||||
|
||||
213 landed as 361ba2387, with the same `git patch-id --stable` as r4 2b3e67e36, f313e69b6f7e. The
|
||||
refactor tip was 62ddc96cc. I cherry-picked 2d7a99aee onto it under the new branch gosalyn/c2-20-r2 as
|
||||
48f044ccc. The patch-id is eb094ae783e9 before and after. None of the 22 paths changed between 2b3e67e36
|
||||
and 62ddc96cc. The fence export from sage-1836 Q1 was already in the commit: `personaTextFault` from
|
||||
packages/harness/src/bundle.mjs, called by the script. I checked the test list again on the new base by
|
||||
grepping tests and scripts/test-*.sh for each non-test path's basename. The new hits name other packages'
|
||||
package.json files or write lockfiles in temp dirs, so the 18 files stand. 231 landed after that as
|
||||
29ce1e360. It touches only packages/library and the queue-231 packet, none of these 22 paths.
|
||||
|
||||
Rerun on 48f044ccc, slot grant sage-1932, 10:18:09Z to 10:30:14Z, after a busy check. All 18 files ran
|
||||
whole, one `node --test` each, every rc 0: 419 pass, 0 fail, 0 cancelled, summed by awk. That's two more
|
||||
than the 417 above, both from the base. stack-release went from 195 to 196 and stack-upgrade from 20 to 21,
|
||||
and rows 238 and 240 changed those test files. Every other file has the count in the table above. The dry
|
||||
run printed the same three lines, rc 0.
|
||||
@@ -1,96 +0,0 @@
|
||||
# Row 231 build notes, C2-01b survey escapes, list item lines and attachment embeds (#1733)
|
||||
|
||||
Brief: docs/plans/2026-10-20_case2-rows.md "C2-01b survey escapes, list item lines and attachment embeds",
|
||||
blob 16847e94ae17. These are Webby's row 212 notes N1 to N3 (webby-0041), split out by sage-1517.
|
||||
|
||||
## Base
|
||||
|
||||
First built as 777f7358a on 212's first round bdf18272a. 212 landed as ee7b2f137 (sage-1886), so the
|
||||
commit was cherry-picked onto refactor fefd54e13 under the new branch gosalyn/c2-01b-r2 as 3647a5a93.
|
||||
`git patch-id --stable` is 45911915a9ee before and after. packages/library is the same in bdf18272a
|
||||
and in 212's landed round a2c72ac95, so nothing the commit touches moved under it.
|
||||
|
||||
## What changed
|
||||
|
||||
- N1, `packages/library/src/survey.mjs`: JSON strings escape C0 controls but leave DEL, C1 and bidi
|
||||
controls raw. The new `quote()` escapes those too, and folder names print through it.
|
||||
- N2, `packages/library/src/reader.mjs`: front matter parsing records each block list item's line, and
|
||||
a link in a block list carries its item's line instead of its key's.
|
||||
- N3, `links.mjs` exports `isAttachment` through `index.mjs`. A wikilink or embed whose target's last
|
||||
segment ends in an extension other than `.md` is an attachment. The reader neither resolves nor
|
||||
indexes it, and it raises no problem. The survey prints a count of body links to attachments.
|
||||
- `packages/library/README.md` describes all three, and the links, reader and survey tests cover them.
|
||||
|
||||
## Outside readers
|
||||
|
||||
`packages/cli/tests/stack-copy.test.mjs:38` checks only that `packages/library/src/index.mjs` exists, and
|
||||
`scripts/mosaic:41` execs `survey.mjs`. No test pins a hash of a library file.
|
||||
|
||||
## Tests
|
||||
|
||||
On 3647a5a93, slot grant sage-1889, 09:20:01Z to 09:20:14Z, after a busy check. One `node --test` per
|
||||
file, every rc 0.
|
||||
|
||||
| File | pass | fail |
|
||||
|---|---|---|
|
||||
| packages/library/tests/links.test.mjs | 7 | 0 |
|
||||
| packages/library/tests/mapping.test.mjs | 7 | 0 |
|
||||
| packages/library/tests/reader.test.mjs | 13 | 0 |
|
||||
| packages/library/tests/render.test.mjs | 11 | 0 |
|
||||
| packages/library/tests/survey.test.mjs | 6 | 0 |
|
||||
| packages/cli/tests/stack-copy.test.mjs | 16 | 0 |
|
||||
|
||||
Total: 60 pass, 0 fail, 0 cancelled, summed by awk.
|
||||
|
||||
## Round 2, after webby-0070 (CHANGES) and sage-1900
|
||||
|
||||
Webby's round 1 review is agents/webby/work/queue-231/REVIEW-r1.md at 387f04dfd, rev 2774.
|
||||
|
||||
Ruling sage-1900, recorded here as asked. B2: the brief stays as approved (sage-1517, case2-rows.md
|
||||
C2-01b N3). Only a `![[x.ext]]` embed can be an attachment. Plain wikilinks and front matter values keep
|
||||
resolving, and an unresolved one is R4. README's line "A link to a `.canvas` file or an attachment is
|
||||
R4" is back as it was at fefd54e13. B1: resolve first. An embed is an attachment only when it resolves
|
||||
to nothing and its target has an extension other than `.md`. So `![[Dr.Quinn]]` with Dr.Quinn.md
|
||||
indexed resolves, `![[cover.png]]` gives no problem, `![[missing-note]]` is R4 and `![[note.md]]`
|
||||
resolves. My own design ruling after r11 (28213ac27) also made plain links attachments. The brief
|
||||
narrowed that, and the brief governs this row.
|
||||
|
||||
Changes:
|
||||
|
||||
- `links.mjs`: `isAttachment` is true only for a body embed, `link.embed === true && !link.field`,
|
||||
with the extension test as before. Its comment says it goes by name, so the reader asks it only
|
||||
after resolving.
|
||||
- `reader.mjs`: every link resolves first. An unresolved one is R4 unless `isAttachment` holds.
|
||||
- `survey.mjs`: `quote()` also escapes U+061C (Webby N1). The attachment count now covers body embeds
|
||||
only, since it uses `isAttachment`.
|
||||
- Webby N2, my choice of Sage's two options: the survey keeps a count by name and the README says so,
|
||||
"the count of body embeds whose target has an extension other than `.md`", and that `![[Dr.Quinn]]`
|
||||
counts there even when Dr.Quinn.md exists. Checking against the survey's path list would mean a second
|
||||
resolver in the survey, for a count that only guides the mapping.
|
||||
- Tests. links: embeds only, with `[[cover.png]]`, `[[Board.canvas]]`, `[[Dr.Quinn]]`, a front matter
|
||||
value and a markdown link all false, and `![[Dr.Quinn]]` true by name. reader: the Shore case now
|
||||
gives R4 for the front matter `"![[portrait.JPG]]"` (line 3), for `[[Board.canvas]]` (line 5) and for
|
||||
`![[missing-note]]` (line 6). The new Dr.Quinn case has Dr.Quinn.md indexed and resolves `[[Dr.Quinn]]` in
|
||||
a block list and in the body, plus `![[Dr.Quinn]]`, with no problem. survey: a U+061C folder name
|
||||
prints escaped, and the attachment count is 1, since `[[map.PDF]]` is a plain link.
|
||||
|
||||
Round 2 tests, one `node --test` per file, each run after a busy check.
|
||||
|
||||
Run 1, slot grant sage-1903, 09:39:32Z to 09:39:46Z: 60 pass, 1 fail. The new Dr.Quinn reader test failed
|
||||
on order alone. All three links resolved to Dr.Quinn.md with the right field, line and embed values, and
|
||||
there was no problem. The reader lists body links before front matter links, and my expected array put
|
||||
the `relationships` link first. I stopped and reported it (gosalyn-0098).
|
||||
|
||||
Run 2, after the test-only fix sage-1907 approved, which moves that entry to the end of the expected array,
|
||||
09:43:42Z to 09:43:56Z. Every rc 0.
|
||||
|
||||
| File | pass | fail |
|
||||
|---|---|---|
|
||||
| packages/library/tests/links.test.mjs | 7 | 0 |
|
||||
| packages/library/tests/mapping.test.mjs | 7 | 0 |
|
||||
| packages/library/tests/reader.test.mjs | 14 | 0 |
|
||||
| packages/library/tests/render.test.mjs | 11 | 0 |
|
||||
| packages/library/tests/survey.test.mjs | 6 | 0 |
|
||||
| packages/cli/tests/stack-copy.test.mjs | 16 | 0 |
|
||||
|
||||
Total: 61 pass, 0 fail, 0 cancelled, summed by awk.
|
||||
@@ -1,252 +0,0 @@
|
||||
# Row 213 (C2-08) build: creative roles, persona file and block, M1, M2, M6, M10, prompt by file
|
||||
|
||||
Morgana (Opus 5.5), 2026-10-20. Queue row 213, Gitea #1714. Brief: `docs/plans/2026-10-20_case2-rows.md`
|
||||
§ C2-08 (on `refactor` from 32b54ac3b). Design: Gosalyn's Case 2 design r10, sections 4 and 5.
|
||||
Reviewer Webby, gate owner Sage. Base: `base.txt` (088087ac9). Manifest: `candidate-manifest.sha256`.
|
||||
D1 and D2 approved as deviations in sage-1492.
|
||||
|
||||
## What it is
|
||||
|
||||
1. **Six creative roles** (`roles/<name>.json` and `.md`, roleVersion 2): companion and research get
|
||||
read and web, with network api-only. ideas, proofreader, fact-checker and continuity get read only, with
|
||||
network none. All six get withinRole `["message.send"]`, no credentials, and messaging that sends to and
|
||||
receives from `human` only. `vocabulary.mjs` names them in `CREATIVE_DEFINITIONS`, plus `CREATIVE_KINDS`,
|
||||
`CREATIVE_TOOLS` and `THREAD_DEFINITIONS`. `END_PROTECTED` becomes `THREAD_DEFINITIONS`.
|
||||
2. **M1** (`role.mjs` `checkCreative`): a creative role file is refused if it names a tool outside
|
||||
`CREATIVE_TOOLS`, holds any authority but withinRole `message.send`, lacks `messaging`, names anyone but
|
||||
`human` in messaging, or is version 1.
|
||||
3. **M2**: since the role files name no write, edit or bash tool, the existing gate refuses write, edit and
|
||||
bash on pi and Write, Edit and Bash on claude-code for each creative role. No gate code changed. The
|
||||
test pins it.
|
||||
4. **M6**: `tools.mjs` leaves `raise_decision` out for a creative definition. `broker.mjs` refuses
|
||||
`decision.raise` from a creative session with `decision-not-allowed`, after `#secretCheck` and before
|
||||
the spec-cited path, so a cited raise is refused too.
|
||||
5. **M10**: a creative instance belongs to the human.
|
||||
- `launch-settings.mjs` `creativeHumanOnly` gives `organization-creative-human-only` to any other actor.
|
||||
It covers: a `models` key that a creative instance's `model` or `fallback.model` var names (changed or
|
||||
removed), `setRoutes` for the instance, and the `instances` key. The `instances` key is refused for
|
||||
every actor with `organization-creative-instance`, because the model changes through `instances.set`
|
||||
or `routes.set`.
|
||||
- `instance-settings.mjs`: add, change and redefine to or from a creative definition are the human's.
|
||||
A creative definition is `END_PROTECTED`, so the new `closed()` lets this writer still add and change
|
||||
one. `accepted` and `protected` use `closed()` too, so the human's Console form offers the creative
|
||||
definitions and marks those instances as editable.
|
||||
6. **Persona** (design 4): vars `persona.name` (one line, max 40) and `persona.sha256` (64 lowercase hex),
|
||||
agent layer. The file lives at `<configDir>/personas/<business>/<instance>.md`.
|
||||
- `bundle.mjs` `readPersona` opens it with O_NOFOLLOW and refuses with `persona-invalid` when the file
|
||||
is missing, a symlink, not a regular file, owned by another uid, carries group or other mode bits, is
|
||||
over 8000 characters, is not UTF-8, or holds `</persona-file>` or a line starting `# ` or `## `.
|
||||
- It refuses with `persona-mismatch` when the bytes don't match the digest.
|
||||
- A file present with no `persona.sha256` var is ignored. A digest with no `personaDir` refuses.
|
||||
- The block sits between the contract and `## This session`, wrapped in
|
||||
`<persona-file instance=... sha256=...>`.
|
||||
7. **Web**: `webPlan` refuses `web-source-not-allowed` when a creative definition is on
|
||||
`harness-builtin`, so every creative fetch goes through the broker.
|
||||
8. **Prompt by file**: claude passes `--system-prompt-file <path>`, and pi passes `--system-prompt <path>`.
|
||||
Both make the path absolute. The prompt text no longer appears in `/proc/<pid>/cmdline`.
|
||||
`adapters/README.md` says so.
|
||||
|
||||
## Refusal codes
|
||||
|
||||
`persona-invalid`, `persona-mismatch`, `web-source-not-allowed`, `organization-creative-human-only` and
|
||||
`organization-creative-instance` are new. `decision-not-allowed` is named in the brief but is also new in
|
||||
code. My morgana-0021 message called it an existing code, which was wrong.
|
||||
|
||||
## Deviations (sage-1492)
|
||||
|
||||
- **D1** `packages/business/src/business.mjs`: `checkPersonaVars`, plus one call line at the end of
|
||||
`checkRoles`'s per-instance block. The persona vars are accepted only on an instance of a creative
|
||||
definition, and only both together. Without D1, any instance's agent layer could carry a persona
|
||||
digest, and the bundle would read a persona file for a pm or chief.
|
||||
Test: `business.test.mjs` "persona vars: agent layer, creative definition only, both or neither". It
|
||||
covers the business layer, pm and chief, one key alone and malformed values. `instance-settings.test.mjs`
|
||||
also covers it: changing a persona-carrying companion to security-reviewer is refused.
|
||||
Mutants: D1a, D1b, D1c.
|
||||
- **D2** `packages/cli/src/launcher.mjs`: one line, `personaDir: join(configDir(env), "personas"),` in the
|
||||
`buildBundle` call. Without it a creative instance with a persona can never launch.
|
||||
Test: `launcher.test.mjs` "row 213 a creative instance's persona is read from <configDir>/personas: off
|
||||
its digest the launch fails with the mismatch as its reason". Mutant: D2.
|
||||
|
||||
- **Adapter tests' file** (webby-0040 N1). Brief line 68 puts the adapter tests in `claude-session.test.mjs`
|
||||
and `pi-session.test.mjs`. They are in `harness/tests/creative.test.mjs` instead, next to the other row 213
|
||||
harness tests, so the row's adapter cases sit in one file and the two session test files stay unchanged.
|
||||
Same cases: argv holds the absolute prompt path and no marker, and pi refuses a missing, unreadable or
|
||||
directory prompt.
|
||||
|
||||
The checkRoles change sits in its own block and the launcher change is one line, so the rebase over rows
|
||||
194 and 199 (both touch `business.mjs`, and 199 touches `launcher.mjs`) stays small.
|
||||
|
||||
## Pinned-test edits and the pi tightening (sage-1492, named here)
|
||||
|
||||
1. `packages/bus/tests/project-runtime.test.mjs:26`: the pinned broker import line gains
|
||||
`CREATIVE_DEFINITIONS` (M6 reads it).
|
||||
2. `packages/harness/tests/skills.test.mjs:170`: the test checked the prompt text in argv after
|
||||
`--system-prompt`. Each adapter now passes a path, so the test looks up the flag for each harness,
|
||||
checks that the next argument is the bundle's prompt file, and reads the MARKED and chief checks from
|
||||
that file.
|
||||
3. `adapters/pi/adapter.sh`: `[ -f "$PROMPT_FILE" ] && [ -r "$PROMPT_FILE" ]`, exit 2 otherwise. Pi 0.85.1
|
||||
uses the path string as the prompt when it can't read the file. Test: `harness/tests/creative.test.mjs`
|
||||
"pi refuses a missing, unreadable or directory prompt" (pi never runs). Mutant: A1.
|
||||
|
||||
One more pinned assertion changed: `business/tests/assistant.test.mjs` REQ-HARN-2 expected only the
|
||||
assistant to hold `web`. Companion and research now hold it too.
|
||||
|
||||
## Files
|
||||
|
||||
Source: `packages/business/src/{vocabulary,role,vars,business,launch-settings,instance-settings}.mjs`,
|
||||
`packages/harness/src/{bundle,tools}.mjs`, `packages/bus/src/broker.mjs`, `packages/cli/src/launcher.mjs`,
|
||||
`adapters/{pi,claude}/adapter.sh`, `adapters/README.md`, `roles/{companion,research,ideas,proofreader,
|
||||
fact-checker,continuity}.{json,md}`.
|
||||
|
||||
Tests changed: `business/tests/{role,business,launch-settings,instance-settings,assistant}.test.mjs`,
|
||||
`harness/tests/skills.test.mjs`, `bus/tests/project-runtime.test.mjs`, `cli/tests/launcher.test.mjs`.
|
||||
New: `harness/tests/creative.test.mjs` (7), `bus/tests/creative.test.mjs` (3).
|
||||
|
||||
I grepped `packages/*/tests` and `scripts/` for each changed source path next to a 64-hex string. The hits
|
||||
are `thread-migration.test.mjs` (a DDL digest, not a pin on `broker.mjs`; 3/3 pass) and discord's own
|
||||
`tools.mjs`. No test pins a changed file.
|
||||
|
||||
## Evidence
|
||||
|
||||
Each file alone from its package with `node --test --test-reporter=tap <file>`, 2026-10-20, all fail 0:
|
||||
|
||||
- Touched: business role 17, business 17, launch-settings 16, instance-settings 12, assistant 11; harness
|
||||
creative 7, skills 10, bundle 22; bus creative 3, project-runtime 3; cli launcher 30. Round 2 reran
|
||||
bus creative, instance-settings, business, launch-settings, role, harness creative and bundle, bus
|
||||
tester-writes 8 and chief-of-staff 18, and the vars readers business vars 7, discord context 7 and git 12.
|
||||
- Other files that read a changed path: business hard-waits, record-grants, token-limit-settings,
|
||||
workflow-roles, chief-of-staff, project-repo, plugin-settings; harness bundle 22, tools 22,
|
||||
claude-session 8, pi-session 8, raise-domain, spec-tools, claude-gate, mcp-server, gate, runner 34,
|
||||
git-tools; bus hard-waits, launch-notice, tester-writes, business, broker 16, workflow-roles, web 19,
|
||||
task-page, thread-migration 3; discord git, web, setspark, engine, tools; plugins harness, loader; seat
|
||||
working, sandbox, session; cli launch-limit-checks, limits, git-socket, launch-account, thread-launch,
|
||||
launch-limits, launch-routes, instances, stack-copy, stack-release 174; webui limits-browser, editor,
|
||||
settings-form, tester-browser.
|
||||
|
||||
Suites, `scripts/test-*.sh` and the mutants are not run yet. They need Sage's slot.
|
||||
|
||||
Drift: `git diff --stat 088087ac9 305857c8f` over the 35 manifest paths is empty (2026-10-20, sage-1501).
|
||||
Row 192's async `scripts/mosaic-config.mjs` and `webui-service.sh` are outside the manifest. The broker's
|
||||
new import comes from `vocabulary.mjs`, which it already imported, so `RUNNER_FILES` doesn't change.
|
||||
|
||||
Mutants: `mutants.py` in this directory, 31 mutants over 11 files. It backs up each file to scratch first,
|
||||
aborts on a bad backup or any anchor count other than one (all 31 checked as unique without editing), runs
|
||||
the named test files per mutant, restores each file after its mutant and again in `finally`. Log:
|
||||
`mutants.log`, written on the run. The brief's `models` mutant is L1.
|
||||
|
||||
| Mutant | File | Tests |
|
||||
|---|---|---|
|
||||
| D1a/b/c persona vars check (D1) | business.mjs | business, instance-settings |
|
||||
| D2 no personaDir (D2) | launcher.mjs | launcher |
|
||||
| L1 models key by anyone (the `models` mutant) | launch-settings.mjs | launch-settings |
|
||||
| L2 fallback.model not checked | launch-settings.mjs | launch-settings |
|
||||
| L3 instances key allowed | launch-settings.mjs | launch-settings |
|
||||
| L4 setRoutes by anyone | launch-settings.mjs | launch-settings |
|
||||
| L5 creativeHumanOnly never refuses | launch-settings.mjs | launch-settings, instance-settings |
|
||||
| I1/I2/I3 add, change, redefine by anyone | instance-settings.mjs | instance-settings |
|
||||
| R1/R2/R3 checkCreative off, wider tools, non-human messaging | role.mjs | role |
|
||||
| B1-B8 mode bits, digest, headings, symlink, char cap, block, no dir, builtin web | bundle.mjs | harness creative |
|
||||
| T1 raise_decision offered | tools.mjs | harness creative |
|
||||
| K1 broker raise check off | broker.mjs | bus creative |
|
||||
| K2/K3 chief or tester session reaches the writer as the human (round 2, B1) | broker.mjs | bus creative |
|
||||
| V1 persona.name line separators accepted (round 2, N3) | vars.mjs | business |
|
||||
| A1 pi without -f; A2/A3 relative path kept | adapters | harness creative, skills |
|
||||
|
||||
## Residuals
|
||||
|
||||
- `ID_PATTERN` allows dots, so a human id could read like `<definition>.<instance>`. That is only cosmetic:
|
||||
`creativeHumanOnly` compares the actor with `document.human`.
|
||||
- TOCTOU between pi's `[ -f ] && [ -r ]` and pi's own read of the bundle's prompt file.
|
||||
- The other-uid owner check in `readPersona` can't be tested without root.
|
||||
- O_NOFOLLOW covers only the last path component, so a symlinked `personas/` or `personas/<business>/` is
|
||||
followed (webby-0040 N2). The digest still refuses any bytes but the pinned ones. A comment in
|
||||
`bundle.mjs` says so.
|
||||
- The claude adapter checks the prompt file with `[ -r ]` only, and pi checks `-f` and `-r`. The brief asks
|
||||
for pi's check (webby-0040 N4).
|
||||
- **Launch-failed mapping.** A BundleError thrown from `buildBundle` inside `start()` becomes the Refusal
|
||||
`launch-failed`, with the code's message in the log's `why`. That holds for the persona codes and for
|
||||
webPlan's `web-source-not-allowed`. By then the run dir `launches/<business>/<run>/` exists with only
|
||||
`session/`, and no bundle is written. Only `check()`'s readSkills preflight surfaces bundle codes. The
|
||||
D2 test pins both facts. I kept the launcher change to one line, as sage-1492 asked.
|
||||
|
||||
## Follow-ups (not in this row)
|
||||
|
||||
- A persona preflight in launcher `check()`, so a bad persona refuses with its own code before a run dir
|
||||
exists. Sage agreed it as a follow-up (sage-1501) and files it after this row lands.
|
||||
- The webui `bus.mjs` code-to-HTTP map lacks the new codes.
|
||||
- webby-0053 N1: `checkCreative` doesn't refuse `credentials`, so a later role-file commit could give a
|
||||
creative instance a gitea credential. All six creative role files have `credentials: []` today. A
|
||||
one-line refusal and a `role.test.mjs` case close it.
|
||||
- The cli `instances.mjs` message wording for the creative refusals.
|
||||
|
||||
## Round 2 (webby-0040, round 1 CHANGES on bb5f4600)
|
||||
|
||||
- **B1**: `bus/tests/creative.test.mjs` adds "M10 through the broker". It runs on a real organization file
|
||||
and writer behind `startBroker`, with a claimed chief session, a bound tester session and the human.
|
||||
- The chief's `organization.set` of bean's `launch.models` key is refused with
|
||||
`organization-creative-human-only`. Its `instances` key is refused with `organization-creative-instance`.
|
||||
- The tester's `organization.set` and `limits.set` are refused `tester-refused` (N5: the broker refuses
|
||||
first). Its `instances.set` (change bean, add an ideas instance) and `routes.set` for bean reach the
|
||||
writer as `tester` and are refused with `organization-creative-human-only`.
|
||||
- The file bytes are unchanged and no committed log entry exists after all of these.
|
||||
- The human's `limits.set` of the same change lands, and the one committed entry names `jason`.
|
||||
- Mutants K2 and K3 change the broker's actor naming for a role or tester session.
|
||||
- **B2**: `instance-settings.test.mjs` asserts the mode of `writer.logFile("acme")` (0600) and that it sits
|
||||
in the history dir. It lives at `.history/acme/changes.jsonl`, so the round 1 loop over that dir already
|
||||
covered it, but no line named it.
|
||||
- **N1**: listed under Deviations. **N2**: comment and residual. **N3**: `persona.name` now refuses U+2028
|
||||
and U+2029, with two values added to the business test and mutant V1. **N4**: noted under residuals.
|
||||
|
||||
- Drift: `git diff --stat 088087ac9 f41729178` over the 35 manifest paths is empty. Round 2 manifest
|
||||
digest b5ff0ac0e754cb1e5891417f4ab1da9597f5cf49fb2fe2d5f0fbf066f821c43a.
|
||||
|
||||
## Round 3 (sage-1715): rebase onto 9b5362018
|
||||
|
||||
Rows 199 (cb5fdb064), 237 (d7d943199) and 210 (f5753c0e8) landed on six manifest paths after the round 2
|
||||
approval. Round 3 rebases the three commits onto origin/refactor 9b5362018 on a new branch,
|
||||
`morgana/row213-r3`. The round 2 branch stays as it was. Nothing else changed.
|
||||
|
||||
- Five files conflicted. Each resolution keeps both sides:
|
||||
- `bus/src/broker.mjs` and `bus/tests/project-runtime.test.mjs`: the vocabulary import keeps rows 199
|
||||
and 210's names (forkProblem, forkUrl, credentialKind, validArgv, commandAllowed) and adds
|
||||
CREATIVE_DEFINITIONS last. The pinned import line in the test carries the same list. RUNNER_FILES
|
||||
is unchanged, since the import is still the vocabulary file only.
|
||||
- `business/src/business.mjs`: one vocabulary import with row 199's names plus CREATIVE_DEFINITIONS.
|
||||
The `checkRoles(roles, file, rolesDir, business, hosts)` signature is row 199's. `checkPersonaVars`
|
||||
runs after row 199's identity and publish checks.
|
||||
- `business/src/role.mjs`: the import keeps row 210's HOST_SERVICE and adds CREATIVE_DEFINITIONS and
|
||||
CREATIVE_TOOLS.
|
||||
- `business/src/vocabulary.mjs`: the creative constants and `END_PROTECTED = THREAD_DEFINITIONS` come
|
||||
before row 199's Gitea URL parse, which is kept whole.
|
||||
- `cli/src/launcher.mjs` merged without a conflict.
|
||||
- `git range-diff 088087ac9..aee32d185 9b5362018..morgana/row213-r3`: commits 2 and 3 are `=`. Commit 1
|
||||
differs only in the conflict hunks above.
|
||||
- None of the new base's added lines name END_PROTECTED, THREAD_DEFINITION, CREATIVE_* or the creative
|
||||
refusal codes, apart from docs. All 31 mutant anchors still count 1. The hash-pin grep finds no
|
||||
64-hex pin on a manifest path.
|
||||
- The manifest is rebuilt from the round 3 tree. It has the same 35 paths, and six digests changed: the
|
||||
six drifted files. `base.txt` is 9b5362018.
|
||||
- Singles of every touched test file, plus the seat sandbox and bus project-runtime tests (RUNNER_FILES
|
||||
rule), wait on Sage's slot. They are recorded here when run.
|
||||
|
||||
## Round 4 (sage-1778, mos-1160): one commit on row 234's landing c771a36f4
|
||||
|
||||
Row 234 landed as c771a36f4 after the round 3 approval (webby-0053). Round 4 is one commit on c771a36f4,
|
||||
on the new branch `morgana/row213-r4`. It is the round 3 change applied onto the landed blobs. The round 3
|
||||
branch stays as it was.
|
||||
|
||||
- Overlap, `git diff --name-only 9b5362018 c771a36f4` against the round 3 paths: `business/src/business.mjs`,
|
||||
`bus/src/broker.mjs` and `bus/tests/project-runtime.test.mjs`. Each starts from the landed blob, and the
|
||||
row 213 edits are merged by hand. No landed hunk is reverted (sage-1760).
|
||||
- `broker.mjs` and the pinned `project-runtime` import line: row 234's list with `HOST_ID`, then
|
||||
`CREATIVE_DEFINITIONS`. The test keeps both rows' comments. The import still names only
|
||||
`vocabulary.mjs`, so RUNNER_FILES is unchanged.
|
||||
- `business.mjs`: row 234's import (no `HOST_PREFIX`, no `hosts.mjs`) plus `CREATIVE_DEFINITIONS`.
|
||||
`checkPersonaVars` sits before row 234's `HOSTS_MOVED` and its four-argument `checkRoles`, and still
|
||||
runs after the identity and publish checks.
|
||||
- Check: the removed and added non-packet lines of `diff c771a36f4..r4` and `diff 9b5362018..2d2ad2760`
|
||||
differ only in those three import lines. All 31 mutant anchors count 1.
|
||||
- Row 234's hosts verbs: `#hostsCaller` admits the human, the tester or the chief definition
|
||||
(`grant-chief-only`), so a creative role can't reach them and M1 stays as narrow.
|
||||
- The manifest has the same 35 paths. The three overlap files changed digest. `base.txt` is c771a36f4.
|
||||
- Singles and the 31 mutants wait on Sage's slot. They are recorded here when run.
|
||||
@@ -1 +0,0 @@
|
||||
c771a36f4bd0b6c359282425c668996a90072f93
|
||||
@@ -1,35 +0,0 @@
|
||||
37cc5d74636465c592c9eb8f3d9b66c2632299be922444737b32d3d3be43c239 adapters/claude/adapter.sh
|
||||
1e0487ab682ff97e974a9fed4765994f70ee362058bd0aa6aee32c2a7891e0d2 adapters/pi/adapter.sh
|
||||
2cb62d90f4f52f17ca606e57d4714b872520d0224cd94fd116308becee864b71 adapters/README.md
|
||||
ee5521840784d9ff3603c22cc6b5f090ac062e8575946a071972fedc089724d1 packages/business/src/business.mjs
|
||||
a93b4efe213750b35730d6391594f3e26ffe667040a5d7baf5262b83341164b1 packages/business/src/instance-settings.mjs
|
||||
3e957579bcfdf5f88e60f7235b7ead4fb27cb455e34b7588f4e22b8ab5542bec packages/business/src/launch-settings.mjs
|
||||
6b84018c202ff08e59b4e946556703d199fe75ef97e9e6ac4a390c89705ac796 packages/business/src/role.mjs
|
||||
f6b15ee8dad2d985c0ae66b1f106ca46cb56ec86ac8cd5dec8a05c887596a421 packages/business/src/vars.mjs
|
||||
814ba93ca7403ad77ea2e7fb7bc21c2b40846bf8a3c2eae53b32446278af061c packages/business/src/vocabulary.mjs
|
||||
b67917c5c7bb270b82f1cbd97071a195b79a57c9a343acbc5feae2a877fb9e8f packages/business/tests/assistant.test.mjs
|
||||
b4606af3288624475e23ca506f7dea084a1e606efce4b1556d132b03230c2be1 packages/business/tests/business.test.mjs
|
||||
2b80070db1e1d72b82a32cec75711c59a9383188b5a659854fd0ba8ae2dc0f5b packages/business/tests/instance-settings.test.mjs
|
||||
647b4835836566070c7b859b2bbcaf3fd748030fe88c8f20e990f5038ec65e88 packages/business/tests/launch-settings.test.mjs
|
||||
0c9f082d8c05582382dc646c74aa60a46b89804717f828db9fadde51f2e258a8 packages/business/tests/role.test.mjs
|
||||
15f530d49eaf25167113f84b743d7057c17a273e56731d8937bad26196325bfc packages/bus/src/broker.mjs
|
||||
21946cdecab263ae65791977eb4599594340c8e049b3c216e3181610638f0952 packages/bus/tests/creative.test.mjs
|
||||
4b1c6688beba124492cf130247a2ff93fdd6d18594990cde84709139964d0b5b packages/bus/tests/project-runtime.test.mjs
|
||||
a968a19d1b32416aecb2488c7fb9768db7d5160374f1b790166380d41acea894 packages/cli/src/launcher.mjs
|
||||
7933f256e5f097999ff36cc7e48b0c417385c6c3727919f38437bd501aecc438 packages/cli/tests/launcher.test.mjs
|
||||
2c1aad8d8be1a03be12eca93b4da36c656236ad38d09bfdc314e42a68240afc3 packages/harness/src/bundle.mjs
|
||||
22f9e3c1dce25e5eb6713306ccdf22dc77a4ccf0c99e9186f2e16602f58aeb49 packages/harness/src/tools.mjs
|
||||
305be35111c432a663d5671a4dac9bfe5bbb1a9b34ace77087e12c6f687602a1 packages/harness/tests/creative.test.mjs
|
||||
3d68294493e41db3b647cd71cd94436c28fc531c64a8b1589be7644c3bf59f94 packages/harness/tests/skills.test.mjs
|
||||
9425a319ec8966712fc38027bc62f7fbf52a216e30b9520cbd877386990c92d6 roles/companion.json
|
||||
2533b3ec4dfa78cd81b254c167865b984a6edf6b00454911363012ab5ac1e4c1 roles/companion.md
|
||||
cb2512590330efe4514c88eb31d09e3e3b159943803e462a224b77010c249de7 roles/continuity.json
|
||||
193c82fa803a85ee4c4b2f946ce2d69e94a192c00c5093d4db91cc274a5d11ed roles/continuity.md
|
||||
7a59218d903b26174c51f0118a347b0b14e187e2d0c229ca43c98dad357f3435 roles/fact-checker.json
|
||||
8895fbe1d7961bbb98b272cd888250d6ef44f74986948032719b44dc3dc56579 roles/fact-checker.md
|
||||
3a932eefe3af967d046d5e241d59f5b2700bd5ad4ef236d6a937011500200b5f roles/ideas.json
|
||||
8ce05e198cefb29f2aea53a25a2cd6599782b34c7a0815a2b6d26272c0fdae50 roles/ideas.md
|
||||
cb117d44e48f288048a4e697ee237b445b8fcea21bb95f9723e91b17ab542a3f roles/proofreader.json
|
||||
a2214ab481ef27d24c20da9e5e7bbc86c6ea769cacc8a163330813e75a20ec15 roles/proofreader.md
|
||||
95f5fc2bd2a0593177c21ca1898317c671ad04334e5c561c29917fe2ceae2c51 roles/research.json
|
||||
7a602b0efe44669028e52fc6aca83f00bd3dd32a105d0729538f2ed357f6ecd3 roles/research.md
|
||||
@@ -1,91 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# Row 213 (C2-08) mutants across the changed sources. Run from the row213 worktree root, in Sage's slot.
|
||||
# Each mutant changes one anchor (count must be 1), runs the named test files alone, then restores.
|
||||
import os, shutil, subprocess, sys
|
||||
BAK = "/mnt/storage/scratch/morgana-r213/mutant-backups" # any scratch path outside the tree
|
||||
BIZ = "packages/business/src/business.mjs"
|
||||
LS = "packages/business/src/launch-settings.mjs"
|
||||
IS = "packages/business/src/instance-settings.mjs"
|
||||
ROLE = "packages/business/src/role.mjs"
|
||||
BUNDLE = "packages/harness/src/bundle.mjs"
|
||||
TOOLS = "packages/harness/src/tools.mjs"
|
||||
BROKER = "packages/bus/src/broker.mjs"
|
||||
LAUNCHER = "packages/cli/src/launcher.mjs"
|
||||
PI = "adapters/pi/adapter.sh"
|
||||
CLAUDE = "adapters/claude/adapter.sh"
|
||||
T_BIZ = [("business", "tests/business.test.mjs")]
|
||||
T_LS = [("business", "tests/launch-settings.test.mjs")]
|
||||
T_IS = [("business", "tests/instance-settings.test.mjs")]
|
||||
T_ROLE = [("business", "tests/role.test.mjs")]
|
||||
T_HC = [("harness", "tests/creative.test.mjs")]
|
||||
T_BUS = [("bus", "tests/creative.test.mjs")]
|
||||
T_LAUNCH = [("cli", "tests/launcher.test.mjs")]
|
||||
T_ADAPT = [("harness", "tests/creative.test.mjs"), ("harness", "tests/skills.test.mjs")]
|
||||
ABS = ' *) PROMPT_FILE="$(pwd)/$PROMPT_FILE" ;;'
|
||||
MUTANTS = [
|
||||
# D1 (deviation): persona vars only on a creative definition, both or neither.
|
||||
("D1a persona vars check not called", BIZ, " checkPersonaVars(out[instance].vars, entry.definition, at);\n", "", T_BIZ + T_IS),
|
||||
("D1b any definition may carry persona vars", BIZ, " if (!CREATIVE_DEFINITIONS.includes(definition)) refuse(", " if (false) refuse(", T_BIZ + T_IS),
|
||||
("D1c one persona var alone accepted", BIZ, " if (set.length === 1) refuse(", " if (false) refuse(", T_BIZ),
|
||||
# D2 (deviation): the launcher hands buildBundle the persona directory.
|
||||
("D2 launcher passes no persona directory", LAUNCHER, ' personaDir: join(configDir(env), "personas"),', " personaDir: null,", T_LAUNCH),
|
||||
# M10: the human's settings.
|
||||
("L1 models-key change by anyone", LS, " if (was !== is) creativeHumanOnly(", " if (false) creativeHumanOnly(", T_LS),
|
||||
("L2 fallback.model key not checked", LS, ' for (const key of [vars.model, vars["fallback.model"]]) {', " for (const key of [vars.model]) {", T_LS),
|
||||
("L3 instances key allowed for a creative instance", LS, " if (CREATIVE_DEFINITIONS.includes(next.roles[instance].definition)) {\n throw new OrganizationError(\"organization-creative-instance\"", " if (false) {\n throw new OrganizationError(\"organization-creative-instance\"", T_LS),
|
||||
("L4 setRoutes by anyone", LS, " creativeHumanOnly(old.document, actor, instance, next.roles[instance].definition);", "", T_LS),
|
||||
("L5 creativeHumanOnly never refuses", LS, " if (CREATIVE_DEFINITIONS.includes(definition) && actor !== document.human) {", " if (false) {", T_LS + T_IS),
|
||||
("I1 add of a creative instance by anyone", IS, " creativeHumanOnly(old, actor, instance, args.definition);\n definitionFor(rolesDir, args.definition);\n next.roles[instance] =", " definitionFor(rolesDir, args.definition);\n next.roles[instance] =", T_IS),
|
||||
("I2 change of a creative instance by anyone", IS, " creativeHumanOnly(old, actor, instance, entry.definition);\n", "", T_IS),
|
||||
("I3 redefine to creative by anyone", IS, " creativeHumanOnly(old, actor, instance, args.definition);\n", "", T_IS),
|
||||
# M1: role files.
|
||||
("R1 checkCreative not called", ROLE, "CREATIVE_DEFINITIONS.includes(role.name) ? checkCreative(role) : role", "role", T_ROLE),
|
||||
("R2 wider tools accepted", ROLE, " if (wider.length > 0) refuse(", " if (false) refuse(", T_ROLE),
|
||||
("R3 non-human messaging accepted", ROLE, ' if (role.messaging[key].some((entry) => entry !== "human")) {', " if (false) {", T_ROLE),
|
||||
# Persona file and block.
|
||||
("B1 group/other mode bits accepted", BUNDLE, " if (stat.mode & 0o077) throw", " if (false) throw", T_HC),
|
||||
("B2 digest not checked", BUNDLE, " if (sha256(data) !== digest) {", " if (false) {", T_HC),
|
||||
("B3 headings and end tag accepted", BUNDLE, " if (text.includes(PERSONA_END) || /^##? /m.test(text)) {", " if (false) {", T_HC),
|
||||
("B4 symlink followed", BUNDLE, "constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK", "constants.O_RDONLY | constants.O_NONBLOCK", T_HC),
|
||||
("B5 character cap off", BUNDLE, " if ([...text].length > PERSONA_CHARS) throw", " if (false) throw", T_HC),
|
||||
("B6 persona block dropped", BUNDLE, " ...personaSection(resolved, persona),\n", "", T_HC),
|
||||
("B7 no personaDir with a digest accepted", BUNDLE, " if (digest === undefined) return null;\n throw new BundleError(", " return null;\n throw new BundleError(", T_HC),
|
||||
("B8 creative role on harness-builtin web", BUNDLE, ' if (granted && source === "harness-builtin" && CREATIVE_DEFINITIONS.includes(resolved.definition)) {', " if (false) {", T_HC),
|
||||
# M6.
|
||||
("T1 raise_decision offered to creative roles", TOOLS, ' if (!CREATIVE_DEFINITIONS.includes(resolved.definition)) add("raise_decision"', ' add("raise_decision"', T_HC),
|
||||
("K1 broker creative raise check off", BROKER, " if (request.verb === 'decision.raise' && !s.human && !s.tester &&\n CREATIVE_DEFINITIONS", " if (false &&\n CREATIVE_DEFINITIONS", T_BUS),
|
||||
# B1 (webby-0040): the broker names the writer's actor from the session.
|
||||
("K2 chief session reaches the writer as the human", BROKER, 'actor = this.#business(s.business).roles[s.role].definition + "." + s.role;', 'actor = "jason";', T_BUS),
|
||||
("K3 tester session reaches the writer as the human", BROKER, 'let actor = s.tester ? "tester" : s.human;', 'let actor = s.tester ? "jason" : s.human;', T_BUS),
|
||||
("V1 persona.name line separators accepted (N3)", "packages/business/src/vars.mjs", "\\u007f\\u2028\\u2029]", "\\u007f]", T_BIZ),
|
||||
# Prompt by file (adapters).
|
||||
("A1 pi prompt check without -f", PI, '[ -f "$PROMPT_FILE" ] && [ -r "$PROMPT_FILE" ] ||', '[ -r "$PROMPT_FILE" ] ||', T_ADAPT),
|
||||
("A2 pi relative prompt path kept", PI, ABS, " *) ;;", T_ADAPT),
|
||||
("A3 claude relative prompt path kept", CLAUDE, ABS, " *) ;;", T_ADAPT),
|
||||
]
|
||||
os.makedirs(BAK, exist_ok=True)
|
||||
files = sorted({m[1] for m in MUTANTS})
|
||||
orig = {}
|
||||
for f in files:
|
||||
bak = os.path.join(BAK, f.replace("/", "__"))
|
||||
shutil.copyfile(f, bak)
|
||||
orig[f] = open(bak).read()
|
||||
if orig[f] != open(f).read(): sys.exit(f"backup mismatch for {f}, abort")
|
||||
for name, f, a, b, _ in MUTANTS:
|
||||
if orig[f].count(a) != 1: sys.exit(f"{name}: anchor count {orig[f].count(a)}, abort")
|
||||
killed = 0
|
||||
try:
|
||||
for name, f, a, b, tests in MUTANTS:
|
||||
open(f, "w").write(orig[f].replace(a, b))
|
||||
failing = []
|
||||
for pkg, t in tests:
|
||||
p = subprocess.run(["node", "--test", "--test-reporter=tap", t], cwd=f"packages/{pkg}", capture_output=True, text=True, timeout=600)
|
||||
failing += [f"{pkg}/{t.split('/')[-1]}: {l[7:]}" for l in p.stdout.splitlines() if l.startswith("not ok")]
|
||||
open(f, "w").write(orig[f])
|
||||
status = "KILLED" if failing else "SURVIVED"
|
||||
killed += bool(failing)
|
||||
print(f"{status} {name}", flush=True)
|
||||
for line in failing: print(f" {line}", flush=True)
|
||||
finally:
|
||||
for f in files: open(f, "w").write(orig[f])
|
||||
print(f"killed {killed}/{len(MUTANTS)}; restored: {all(open(f).read() == orig[f] for f in files)}")
|
||||
@@ -1,149 +0,0 @@
|
||||
# Row 218 draft notes: claims and sources
|
||||
|
||||
Drafts for `docs/case2/SETUP-SHEET.md` and `docs/case2/SURVEY-RUN.md`. Repo base: `refactor` at
|
||||
947101d8a, which holds 29ce1e360 (row 231). "Design" means
|
||||
`git show 75fb3e10e:agents/gosalyn/work/case2/DESIGN.md`, cited as `D:<line>`. "Brief" means
|
||||
`docs/plans/2026-10-20_case2-rows.md`. Code paths are relative to the repo root. Nothing was run
|
||||
except reads, greps and `git merge-base --is-ancestor 29ce1e360 HEAD`.
|
||||
|
||||
## SETUP-SHEET.md
|
||||
|
||||
| Claim | Source |
|
||||
|---|---|
|
||||
| She keeps writing in Obsidian, obsidian-git pushes to git.mosaicstack.dev, nothing changes on her machine, nothing commits to her repo | D:939-940 (7.1) |
|
||||
| Agents read what she pushed; a push reaches them in about a minute | D:1006-1007 (7.5); D:972-973 (60-second sync timer) |
|
||||
| Agents read `.md` notes inside book folders only | D:457-461 (1.2); `packages/library/src/scope.mjs:9-19` |
|
||||
| Not read: top-level notes, `.canvas`, `.base`, attachments, anything outside a book folder | D:461 |
|
||||
| Other repos under `~/src` are not read | D:489 (1.3), D:494-497 (N4) |
|
||||
| Agents can't write to her repo: canon, playground, anything | D:389 (D3); D:1008 |
|
||||
| Folder roles live in the `projects` entry of the business file, hand-edited, agents can't change it | D:409-429, D:443-451 (1.1, M9) |
|
||||
| Jason asks her to confirm the mapping first | D:431; D:1324-1328 (10 step 7) |
|
||||
| A folder named in `playground` is her playground | Brief:22; D:434 |
|
||||
| Each playground prefix sits inside one book folder | D:434-436; `packages/library/src/mapping.mjs:77-80` |
|
||||
| One per book, e.g. `<book>/playground/`; until then everything mapped is canon | D:438-439 |
|
||||
| Agents search canon unless they ask for the playground | D:463 |
|
||||
| Playground may back an idea or question, not a fact, finding or correction; refused before she sees it | D:858 (`playground-cited-as-canon`); D:378-382, D:835-839 (guard runs before store) |
|
||||
| Only the folder decides; a tag or property can't change scope | D:388 (D2); D:440-441; `scope.mjs:1` |
|
||||
| Graph colour group via Groups and a `path:` query, her own vault setting, changes nothing for agents | Brief:23; D:941-943. Obsidian UI steps from the task prompt, not the design |
|
||||
| Path starts with the books repo folder because the vault is `~/src` | D:939 |
|
||||
| N2: moving a note into a book folder makes it canon, agents may cite it as fact | D:944-945; D:259 |
|
||||
| Rough drafts outside the playground are canon | Inference from D:460 (scope rule) |
|
||||
| N4: Obsidian resolves short links across `~/src`, the reader sees one repo, the two can differ, the reader can't tell | D:494-497; D:262-263 |
|
||||
| A name only in another repo leads nowhere for agents | D:489 (R4); `packages/library/src/links.mjs:61-87` |
|
||||
| A full-path link resolves the same in both | D:497-498. Hub side: `links.mjs:77-78` (`vault-prefix` step) |
|
||||
| "New link format: Absolute path in vault" setting | Obsidian UI knowledge. Not in design or code. Reviewer may strike it |
|
||||
| `appears_in` and `relationships` links are read as links | D:489-490; `packages/library/src/reader.mjs:15`, `:153-162` |
|
||||
| Quoted flow list `["[[A]]", "[[B]]"]` parses | `reader.mjs:81-96` (flow), `:66-73` (quoted scalar), `:159` |
|
||||
| Block list with quoted items parses | `reader.mjs:117-122`, `:66-73` |
|
||||
| Unquoted `[[[A]], [[B]]]` is R3 | Brief:28-29; `reader.mjs:87` (bracket inside a flow list stops parsing), `:137` |
|
||||
| R3 effect: whole front matter unread, note still indexed by path, name and body, listed as a problem | D:480; `reader.mjs:103-105`, `:193`; `packages/library/README.md:69` |
|
||||
| Problems show in Mosaic's status | D:473-474; D:999-1000 (7.4 status line) |
|
||||
| A value without `[[ ]]` is a name | D:489-490; `reader.mjs:159` |
|
||||
| Bean and Chet keep names and personalities | D:660-661 (Q180) |
|
||||
| Hermes: free text and story text. Mosaic: short cited items, a prose request gets a question or idea | D:778-781 (design 4) |
|
||||
| Bean and Chet's item kinds: idea, question, finding, fact; web cites allowed | D:649 (`companion`); D:860 (`citation-unfetched`) |
|
||||
| Limits 10 items, 5 ideas of 200, others 300 | D:819 (M5) |
|
||||
| She or Jason can ask for lower limits | D:1329-1330 (10 step 8); D:831 |
|
||||
| "No cited answer" notice | D:870-871, D:996-997 |
|
||||
| One item can't mix two worlds | D:859 (`citation-cross-universe`) |
|
||||
| She talks to them in the Console; Hermes keeps running until she moves over; stopping it is her choice | D:381-382; D:1331 |
|
||||
| Five more helpers; she chooses the start set and can add one later | D:647-654; D:783-784; D:1327-1328 |
|
||||
| What Jason will ask | D:1325-1327 (10 step 7) |
|
||||
|
||||
## SURVEY-RUN.md
|
||||
|
||||
| Claim | Source |
|
||||
|---|---|
|
||||
| Runs on `<host>` 10.1.1.54 under design 10 step 7, after step 4 | D:1324; D:1266 (host) |
|
||||
| Prints names and counts, never note text, property values, file names or link targets | `packages/library/src/survey.mjs:1-6`; README:118-125 |
|
||||
| Sending to Melanie is Jason's call | Brief:36; D:1324-1328 |
|
||||
| Token slot `library-gitea` is step 4 | D:1314-1316 |
|
||||
| Run as `sudo -u mosaic -H` from `localadmin`; `mosaic` has no login shell | D:1195-1197; D:1281-1282 |
|
||||
| Copy at `/srv/mosaic/.local/share/mosaic-stack/copies/<id>`, `<id>` = commit in Jason's go | D:1286-1292 (2c); `docs/TOOLS.md:417`; home `/srv/mosaic` per D:1314-1315 |
|
||||
| The copy carries `packages/library/src` | `scripts/stack-copy.sh:36` |
|
||||
| Row 231 adds the control and bidi escapes | `git log` 29ce1e360; `survey.mjs:78-82`; README:121-122 |
|
||||
| `<node dir>` is the `--node` directory of step 2c; `scripts/mosaic` execs `node` from PATH | D:1290-1291; `scripts/mosaic:41` |
|
||||
| Dispatch: `mosaic library survey` goes to `survey.mjs` with `survey <args>` | `scripts/mosaic:37-41` (one `shift` leaves `survey` as argv[0]); `survey.mjs:102-103` |
|
||||
| Command and flags: `<repo>` plus optional `--mapping <file>` once; anything starting with `-` refuses | `survey.mjs:16`, `:104-110` |
|
||||
| No fetch; reads `HEAD` | `survey.mjs:5-6`, `:27`; `reader.mjs:22-24` |
|
||||
| Top folder only: ceiling is the path's parent | `packages/project/src/git.mjs:12`, `:62` |
|
||||
| Owner must be `mosaic`: git gets no global config | `packages/seat/src/checkout.mjs:79-89` (`GIT_CONFIG_GLOBAL=/dev/null`, `GIT_CONFIG_NOSYSTEM=1`). The dubious-ownership refusal is git's own behaviour |
|
||||
| Bus mirror path `<dataRoot>/projects/<business>/<project>` | Brief:300; `packages/project/src/paths.mjs:34-40` |
|
||||
| C2-04 and C2-03a not landed | `grep` of `packages/*/src` finds no library entry handling or `refs/heads/served`; `docs/guides/host-run-sheet.md:269` says "not landed" |
|
||||
| Served ref `refs/heads/served` | D:963 (7.2); Brief:676 |
|
||||
| Token kept out of URL, config, argv, logs | D:955-956 (7.2) |
|
||||
| Mapping file is the entry alone; `remote`, `branch` required | `survey.mjs:114-116`; `mapping.mjs:38-47` |
|
||||
| Output lines and fields | `survey.mjs:83-97`; data from `:26-76` |
|
||||
| Folder lines list folders that directly hold an entry, full path | `survey.mjs:30-35` |
|
||||
| Key names: short identifiers print, others as `(other key)` | `survey.mjs:17-20`, `:47` |
|
||||
| `unresolved` equals the R4 count | `survey.mjs:72` |
|
||||
| Scope counts cover all tree entries | `survey.mjs:66` |
|
||||
| Refusal exit codes 0, 2, 3, 4 | `survey.mjs:99-124`; README:127-129 |
|
||||
| Mapping checked before repo | `survey.mjs:112-121` |
|
||||
| stderr format `library survey: <message>` | `survey.mjs:101`; `problems.mjs:3-5` |
|
||||
| `(project-git)` suffix on git failures | `reader.mjs:18-20`; `paths.mjs:4-6` |
|
||||
| `library-playground-outside-book` message | `mapping.mjs:79-80` |
|
||||
| 100-second git timeout | `checkout.mjs:49`, `:52`; `git.mjs:68` |
|
||||
| Exit 127 when `node` is missing | `scripts/mosaic:18`, `:41` (bash `exec` failure). Not run |
|
||||
| Other errors rethrow as a stack trace | `survey.mjs:117`, `:123`, `:128-131` |
|
||||
| Don't work around a refusal | AGENTS.md invariant 6 |
|
||||
|
||||
## Code and design disagreements
|
||||
|
||||
1. Design 1.1 shows the mapping nested in `"projects": {"books": {...}}` (D:412-429). The survey's
|
||||
`--mapping` file must be the inner entry alone (`survey.mjs:114-116`). The run sheet follows the code.
|
||||
2. Design 1.3 calls `vaultPrefix` part of the mapping (D:418). The code makes it optional
|
||||
(`mapping.mjs:48`, README:30). Without it, a full vault path link, the N4 advice, resolves to
|
||||
nothing in the hub (`links.mjs:73-87`: `root` fails, `vault-prefix` is skipped, `shortest` refuses a
|
||||
`/`). The setup sheet's full-path advice holds only when Jason sets `vaultPrefix` to her books repo
|
||||
folder name.
|
||||
3. The task prompt calls the unquoted form "refused". R3 is not a refusal. It is a reported problem,
|
||||
and the note stays indexed (D:473, D:480). The sheet says what happens instead.
|
||||
|
||||
## Open questions
|
||||
|
||||
1. Where `<repo>` comes from on .54. The survey reads a local repo's `HEAD` and never fetches. The bus
|
||||
mirror needs C2-04 and C2-03a, neither landed. C2-03a moves `refs/heads/served`, not `HEAD`, so the
|
||||
mirror's `HEAD` may name no commit and the survey would refuse with exit 2. The sync also needs a
|
||||
checked mapping with at least one book (`mapping.mjs:59`, `:70`), and the mapping's values are
|
||||
meant to come from this survey (D:431). Sage needs to rule: a placeholder mapping for the first
|
||||
sync, a `HEAD` the sync sets, a `--commit` flag on the survey, or another source.
|
||||
2. The brief says Obsidian's property editor writes `appears_in: ["[[A]]", "[[B]]"]` (Brief:28-29,
|
||||
webby-0041 N4). I didn't read webby-0041 or check Obsidian's output. Both the flow and the block
|
||||
quoted forms parse, so the sheet shows both and says only that the editor adds the quotes.
|
||||
3. Whether `/srv/mosaic/.npm-global/bin/mosaic` exists on .54. The run sheet uses the copy's
|
||||
`scripts/mosaic` by full path to avoid depending on a wrapper.
|
||||
|
||||
## Sage's rulings on the open questions (2026-10-21)
|
||||
|
||||
1. Survey source: the bus's bare mirror after the first `library.sync`, the only copy on the host
|
||||
(design 2.1). The C2-03a brief now requires the mirror's `HEAD` to be a symbolic ref to
|
||||
`refs/heads/served`, with a test (5c6f73ed7), so the survey reads the served commit with no ref flag.
|
||||
2. Property list forms: the sheet shows both quoted forms, since both parse. Webby checks the claim
|
||||
that Obsidian's property editor writes the quoted form.
|
||||
3. The "New link format: Absolute path in vault" tip stays. It is an Obsidian setting, not a design
|
||||
claim, and Webby may strike it.
|
||||
4. The run sheet calls the copy's `scripts/mosaic` by full path. That holds whether or not a wrapper
|
||||
is on `PATH`.
|
||||
5. `vaultPrefix`: the run sheet's step 4 tells Jason to set it, because the setup sheet's full-path
|
||||
link advice depends on it.
|
||||
|
||||
## Round 2 (2026-10-21), from Webby's round 1 notes (webby-0075, rev 2848)
|
||||
|
||||
- N1, by Mos's ruling mos-1165 (fix before landing): SETUP-SHEET.md now gives the 1,200 character
|
||||
total of item text per reply (design M5, step 8). The word "Today" is gone. No code enforces these
|
||||
caps until C2-06 lands, so my ruling is that the sheet goes to Melanie only after C2-06 lands, and
|
||||
then only on Jason's go (#419). The wording stays as is, because by then it holds.
|
||||
- N2: SURVEY-RUN.md says tab, newline, carriage return, backspace and form feed print as `\t`, `\n`,
|
||||
`\r`, `\b` and `\f`, and other control and bidi characters as `\uXXXX` (survey.mjs quote()).
|
||||
- N3: SURVEY-RUN.md has a refusal row for `library-commit:` (reader.mjs listTree). survey.mjs turns
|
||||
every LibraryError into exit 2 with its message.
|
||||
- N4: SURVEY-RUN.md's new step 2 checks `command -v node` under the same sudo and PATH before the
|
||||
survey runs.
|
||||
|
||||
## Round 3 (2026-10-21), from Webby's round 2 note N5 (webby-0077, rev 2856)
|
||||
|
||||
- N5: the library-commit row no longer says a moved `HEAD` causes it. The survey reads `HEAD` once,
|
||||
and listTree raises library-commit only for an id that isn't 40 hex or an object that isn't a
|
||||
commit (reader.mjs:29, :31). In practice that means a SHA-256 repository, so a rerun doesn't help.
|
||||
The row now says "for example in a SHA-256 repository" and "Report to Sage".
|
||||
@@ -20,12 +20,12 @@ so Mos doesn't check this draft. Draft 1 names NEW and goes to Mos for the P0 ch
|
||||
|
||||
- OLD, live: `4429a104f6d65ccf165f6c83b5d1dce3147dfde0`, schema 3i, pointer `pm: true` (record 99a406ed3).
|
||||
P1 re-reads the activation id and the Console flags from `status`. I don't copy them from the last window.
|
||||
- NEW: `c771a36f4bd0b6c359282425c668996a90072f93`, the row 234 landing (2026-10-21 06:16Z), unless Mos rules a
|
||||
later code landing. 194 is the open candidate. 210, 237, 232, 241, 242, 233 and 234 have landed.
|
||||
- NEW: open. It's the row 234 landing, or a later code landing if Mos rules. Candidates in landing order:
|
||||
194, 234 (210 and 237 have landed).
|
||||
- REPO, `P`, `WIN=agents/sage/work/window-repin-<NEW12>/`, `SNAP`: as in `repin-4429a104f.md`, with the
|
||||
sha checks at P0 and before S1, S2 and any D3.
|
||||
|
||||
## What NEW carries over OLD (refactor c771a36f4)
|
||||
## What NEW carries over OLD (so far, refactor 8fede5fc6)
|
||||
|
||||
`git log --first-parent 4429a104f..HEAD`, path-limited to packages, scripts, roles, contracts, adapters, skills
|
||||
and the package files:
|
||||
@@ -41,11 +41,7 @@ and the package files:
|
||||
| 230 | c8bc5cf4c | Case 2 scripts, tools only. Not run live. |
|
||||
| 210 | f5753c0e8 | Host access. The live business has no `hosts`, so nothing is granted. Bus start runs the host-run sweep (M34d). P3 must show it removes nothing. |
|
||||
| 237 | d7d943199 | Publish busy check (199 N1). |
|
||||
| 232 | e65a3ab4d | Installer I1: `stack-release.sh --units external` and `stack-copy.sh copy --bundle`, `wrapper --create`. Both are opt-in, and this window uses neither. The default units path must render the same units, so the P2 unit diff covers it with row 190. P0 checks that no window command line carries `--units external`. |
|
||||
| 241 | 5d4a61776 | Test only (bus land.test.mjs). No live effect. |
|
||||
| 242 | 5fb736b92 | Bus publish hold: after publish-timeout the bus holds the decision until its push ends, then records a late push. The live business has no publish in flight at W1, and P3 shows none open. Its follow-up fc1cb856b is comments only (git-socket.mjs). |
|
||||
| 233 | 57f59e0c3 | Installer I3: new tool `scripts/stack-upgrade.sh` and a `stack-release.sh` change. This window doesn't run `stack-upgrade.sh`. The P2 unit diff covers the `stack-release.sh` change with rows 190 and 232. |
|
||||
| 234 | c771a36f4 | Machine grant row a and the 3i to 3j schema step (new tables `hosts` and `host_grants`). `--plan` must say `migration: 3i -> 3j`. |
|
||||
| 234 | open | Machine grant row a and the 3i to 3j schema step. `--plan` must say `migration: 3i -> 3j`. |
|
||||
| PRD 1.7+1.8 | 0adf8ddfe | `docs/prd/mosaic-stack.md` and `packages/tasks/requirements.json` move to version 1.8 (mos-1154, mos-1156, DECISIONS Q192). The live pm cites 1.6 until this window. Check after: the pm's requirements read answers version 1.8. |
|
||||
|
||||
Service script drift OLD to HEAD is 415+/91- over the four scripts, mostly row 190. P5 holds them at NEW.
|
||||
@@ -57,14 +53,7 @@ Service script drift OLD to HEAD is 415+/91- over the four scripts, mostly row 1
|
||||
- W0b: the business file copy, as in the last window.
|
||||
- Rollback after a migration isn't the plain rollback. OLD is 3i and the store is 3j, so going back needs
|
||||
`--restore <W5 activation>`, and that loses the events written after W5. The row 181 restore guard counts
|
||||
11 tables, and the untimed ones need the D3 snapshot. Row 234 adds `hosts` and `host_grants` to the untimed
|
||||
list (T46), so at 3j the D3 snapshot covers them too. Draft 1 recounts the list from NEW. Mos decides any restore past W5, as before.
|
||||
- Grant look-alikes (row 234 A22b, gizmoduck-0107). `3i-3j.sql` adds `events_grant_actor` but doesn't check
|
||||
rows already in the store, so after the migration only the actor filter in `GRANT_EVIDENCE` (actor_role NULL,
|
||||
actor_run 'grant') ignores an old session-written row. P3, and again just before `--migrate`: on the
|
||||
backup copy, count the `action.allowed` events whose body.action or body.operation starts with `grant.`, or
|
||||
whose body has `hostLineLeft`. Expect 0, since no grant code has run live. Any nonzero count stops the window
|
||||
until I've read those rows.
|
||||
11 tables, and the untimed ones need the D3 snapshot. Mos decides any restore past W5, as before.
|
||||
- P3 is the rehearsal with `--migrate` on a copy of the live backup. It must show the 3j step and the row
|
||||
counts before and after.
|
||||
|
||||
@@ -76,15 +65,10 @@ history unless the window fails.
|
||||
|
||||
## Open before draft 1
|
||||
|
||||
- Q1, ruled by mos-1161: draft 1 doesn't wait for 194. NEW is the latest code landing when I cut draft 1. If
|
||||
194 has landed with a green full gate (15 packages, ten script suites), NEW is the 194 landing and P3 also runs
|
||||
the lifecycle verbs once on the backup copy and gets one pm reply under the new roles/chief-of-staff files. A
|
||||
P3 failure that traces to 194 drops NEW back to c771a36f4 before anything touches live, and the window goes on.
|
||||
Otherwise NEW is c771a36f4 and 194 rides a later window.
|
||||
- Q1: NEW, once 234 lands. Do 194 and 237 go in if they land first? I recommend yes for 237 (small, bus
|
||||
only) and asking Mos about 194, since 194 changes the lifecycle verbs and roles/chief-of-staff.*.
|
||||
- Q2, settled by mos-1148: phase 2 is its own window on 10-23. Draft 1 takes OLD and the Console flags,
|
||||
`--sso` included, from `status` after that window.
|
||||
- Q3: who operates. If Darkwing is free, Darkwing operates and I check. Otherwise I operate as in the last
|
||||
window.
|
||||
- The P-step evidence list for rows 199 and 210 at bus start. Both have landed (cb5fdb064, f5753c0e8), so
|
||||
it's due in draft 1. I take each log line and exit code from a P3 rehearsal run, not from the code.
|
||||
- Rows 241 and 242 (bus): P3 shows no publish or land decision open before W5.
|
||||
- The P-step evidence list for rows 199 and 210 at bus start, written once both have landed.
|
||||
|
||||
@@ -1395,18 +1395,3 @@ are never rewritten or removed; corrections are new entries.
|
||||
2026-10-21T01:49:55Z | Sage (Opus 5.5, 1ef1e4f8) | row 237 landed d7d943199 (#1743, gate green, M1 killed); PRD 1.7+1.8 landed 0adf8ddfe (Honker 2884ee496, Duckworth approve bf52628f9, tasks 97/0 bus 478/0 on the tip, DECISIONS Q192); rows 239 (#1745) and 240 (#1746) added; 233 briefed; queue revs 2540-2603 committed 584e2bd82 | landed, push next
|
||||
2026-10-21T02:51:46Z | Sage (Opus 5.5, 1ef1e4f8) | row 210 landing (r5 0485384e9, Duckworth r3 29851) | landed f5753c0e8, patch-id 723b1c83 = r5 diff, manifest 688d38b9 OK; gate 2796/0 packages, 429/0 scripts; mutants 52/53 (M22b equivalent); #1707 closed (29853), Vikunja 424 comment 429; queue revs 2604-2617 c084d8d42; row 234 briefed; Megavolt has the slot for 241 (sage-1668)
|
||||
2026-10-21T03:01:43Z | Filbert (Opus 5.5, 048f3c63) | row 232 installer I1 review r2, rebase scope (#1734, manifest 7af3c94308e0, da2da2f6c on 8fede5fc6) | APPROVE, Gitea 29865, queue rev 2622 (left for Sage's queue-commit); README = predicted 3-way blob 89a95b32, 7 blobs same as r1, BUILD.md +31/-0; corrected my r1 reader claim (host.test.mjs:855 reads cli README)
|
||||
2026-10-21T04:14:49Z | Sage (Opus 5.5, 1ef1e4f8) | lead: rows 241 and 242 landed, slot order | row 241 landed 5d4a61776 (#1747 closed 29883, M1-M3 killed, gate 2797/0 + 429/0); row 242 landed 5fb736b92 (#1748 closed 29894, Duckworth approve 29889, gate 2826/0 + 429/0); late-record notice ruled a follow-up (Vikunja 440 c432); row 233 brief re-pinned rev 2631; carry items on #1744 (29885) and #1734 (29886); queue revs 2628-2638 committed 96bac588f
|
||||
2026-10-21T04:50:44Z | Darkwing (Opus 5.5, 7525c8e4) | row 233 I3 gate, mutants and review request (sage-1704, sage-1707, sage-1708) | gate green on d99166ade (1201/0, cli 616/0) and m1-m8 8/8 killed; N1 flock-holder orphan fixed test-only in 08db6ac3f, rerun c0 20/0 + m1 killed, sweep 0 left; in review round 1, manifest 464ce9eb at 1a1dc80ca on darkwing/row233-r1, comment 29901, revs 2644 and 2647 (lock race resolved); Filbert woken
|
||||
2026-10-21T04:58:01Z | Filbert (Opus 5.5, 048f3c63) | row 233 (I3, #1735) review round 1 on manifest 464ce9eb177a (1a1dc80ca) | APPROVE, Gitea 29922, rev 2659 (left for Sage); static, no slot; 5 non-blocking notes N1-N5 (args-failed exit 1, REPO ownership, signals, run sheet npm/claude path, sections 8/10 precheck)
|
||||
2026-10-21T05:47:45Z | Sage (Opus 5.5, 1ef1e4f8) | rows 233+234 landing gate, row 233 landing, 240 brief, drift sweep (sage-1742..1758) | combined gate stopped on two row 234 failures (bus schema.test.mjs:522 counts, cli stack-release T46 restore-guard lists; mos-0823); 233 landed alone 57f59e0c3 (patch-id b16ac924, verify-commit ok, cli 617/0, scripts 585/0), pushed with b00d7d94d, 5465fd52d and riders 642a9b87d, 16019b80e; #1735 closed 29931, done rev 2675, Vikunja 432 comment 436; 240 briefed rev 2676; 234 r3 c783d5e39 rebuilt on the landing in Gizmoduck's slot; 197 and 238 drifted, rebase sent (sage-1754, 1755, 1757 stash fix)
|
||||
2026-10-21T06:20:30Z | Sage (Opus 5.5, 1ef1e4f8) | row 234 r3 landing gate (2890/0 packages, 585/0 scripts) and landing c771a36f4, pushed 06:16Z; #1740 closed 29938, Vikunja 436 c437; 235 briefed rev 2686, rotateBy ruling; 238/228/197 rebuilt on 234, slot order Darkwing 240 then 238, 228, 197; 10-24 draft NEW c771a36f4 (sage-1766..1787) | landed
|
||||
2026-10-21T06:37:41Z | Darkwing (Opus 5.5, 7525c8e4) | row 240 I4 build, slot run and review request (sage-1759, sage-1773, sage-1788, sage-1795) | r1 on 47ec9fe2f stopped at singles (stack-upgrade 20/1: the N1 test's own after hook threw ENOENT once the fixture removed the root), b45852daa drops it; r2 green: singles 37/0, M1-M8 8/8 killed, cli 639/0, scripts 585/0; darkwing/row240-r3 pushed at ad1b23ab2 on c771a36f4, manifest 573ece95 (9 paths), in-review revs 2694 and 2695, request comment 29943 on #1746, Filbert woken | in review
|
||||
2026-10-21T06:41:13Z | Filbert (Opus 5.5, 048f3c63) | row 240 (I4, #1746) round 1 review on manifest 573ece95 (ad1b23ab2) | approve, Gitea 29945, rev 2696; 233 carries N1/N4/N5 present; notes N1 boot unit Before= names one business, N2 doc-only, N3 info
|
||||
2026-10-21T07:15:48Z | Darkwing (Opus 5.5, 7525c8e4) | row 195 (#1693) DESIGN r7, Case 1 install on .53 after the installer split | darkwing/row195-r7 5425ea2f3 pushed (r6 carried as 7398b7dd7 on c515273db), DESIGN.md blob 17dfbad95ba5; business id mosaic-stack named in §7, so DEFERRED 240 N1 doesn't apply (sage-1813); root steps left to ops-01, nothing run on .53 (sage-1809); Duckworth review requested 07:14Z, Gitea 29960; row 226 items (dev.args writer, adopt) sent to Gosalyn and copied to Sage per sage-1814; r7 :21 and :326 still say 226 is unclaimed, to fix next revision
|
||||
2026-10-21T07:29:11Z | Sage (Opus 5.5, 1ef1e4f8) | row 240 landing gate (cli 639/0, scripts 585/0) and landing c515273db with DEFERRED da3051ccc; 238 r3/r4 and 228 r3 requests posted as jarvis; combined 228+238 gate (seat 165/0, cli 640/0, scripts 585/0, 238 mutant killed), landings 86249ac55 and d49b1f2bd, DEFERRED e7078e6a8; #1746, #1729, #1744 closed; 197 r2 request posted (29961), r5 rebuild on 238; 195 after 226, Duckworth r7 note posted (29962); slots Herb 197, Gosalyn 212 (sage-1788..1826) | landed
|
||||
2026-10-21T08:29:39Z | Filbert (Opus 5.5, 048f3c63) | row 215 (C2-04) manifest review, herb/row215 6a508804f | CHANGES REQUESTED, static: B1 cli config.mjs:61 trackerFor projectFilePath skip, B2 refuse publish naming a library entry, B3 sync-to-read window in the shared state contract; N1-N3; sent to Herb and Sage 08:29Z
|
||||
2026-10-21T08:37:47Z | Filbert (Opus 5.5, 048f3c63) | row 215 (C2-04) manifest r2 review, herb/row215 2522025af | APPROVE, static: B1-B3 and N1-N2 resolved per sage-1860/1862; build notes on lock file creation, mirror metadata allowlist and flock dependency; sent to Herb and Sage 08:37Z
|
||||
2026-10-21T08:52:06Z | Darkwing (Opus 5.5, 7525c8e4) | row 195 (#1693) build and manifest round 1 in review (rev 2756, request comment 29985, results 29987) | darkwing/row195-b 37171f65b on 4ced5e63d (ddf7dce6c build: scripts/case1-accept.sh, case1-accept.test.mjs, TOOLS.md entry, DESIGN r7 doc fixes per sage-1817; 37171f65b BUILD.md results); slot: single 22/22 (sage-1829), 12/12 mutants killed and gate cli 662/0 plus scripts 429/0 selftests (sage-1865), green per sage-1870; Duckworth reviews (sage-1872); Gosalyn 0087 Q4/Q5 match W10/W12; flock goes to DEFERRED with 215 (sage-1871); nothing touched .53
|
||||
2026-10-21T09:20:46Z | Sage (Opus 5.5, 1ef1e4f8) | 212+197 combined landing gate (node 981/0, selftests 429/0, 08:51-09:03Z); 197 lane proof stopped after two failures (try 1 lane-image base inspect, N7; try 3 solo-a process.test.mjs:82 under umask 077), recovered cf48efccf083; mos-1162: row 212 landed alone as ee7b2f137 (paths match a2c72ac95, patch-id ea84d3e35470), #1713 closed 29996, revs 2759-2760; DEFERRED N7 plus brief docs/plans/2026-10-21_gate-env-rows.md at fefd54e13, rows 243 (chmod) and 244 (fixture PI_AUTH_FILE) revs 2761-2762; row 66 rebuilt as sage/row66-r4b 49ad61963 on fefd54e13 (manifest 99cab8275af4, not yet requested); slots: Herb 215 focused 26/0, Gosalyn 231 singles 60/0, Herb 197 r6 focused granted; kept root ga-8I3iZc removed (sage-1827..1893) | in progress
|
||||
2026-10-21T10:12:45Z | Darkwing (Opus 5.5, 7525c8e4) | row 245 (#1693) built, slot asked (darkwing-0105) | claim rev 2795; darkwing/row245 0590a29fc pushed, on 62ddc96cc: 5273de0b7 cherry-pick of 1e3c4767c (case1-accept.sh, test, TOOLS.md blobs identical) and 0590a29fc notes to queue-245/BUILD.md (DESIGN.md:336-338 superseded by gosalyn-0087, unedited, sage-1877); slot scripts in /mnt/storage/scratch/darkwing-245-out pinned to 0590a29fc, nothing run; told Sage the untracked queue-195 DESIGN.md was r2 (fcbb4aa9b = 818b79696), nothing lost; flagged 245 and 246 both closing #1693
|
||||
2026-10-21T11:28:49Z | Sage (Opus 5.5, 1ef1e4f8) | 235 landing gate (bus 596/0, business 200/0, cli 666/0, scripts green) and landing b1fece6f0, #1741 closed 30026; 197 r6 D5 proof stopped at solo-a script-release (Compose run has no --no-build, reproduced in lane env), #1695 30031; 221 landed before 197 r7 (sage-1954): gate 11:07-11:19Z (test 11/0, harness 140/0, cli 677/0, scripts green), 300766450, #1722 closed 30033, revs 2812-2813; C2-20b brief and DEFERRED N3 in 335bb3e30, row 247 #1749 briefed; 197 r7 9c3166915 focused run on my slot (red 9/2, green 11/0, mutant killed), request rev 2819 (30036), proof candidates A 2be6d07fa and B cceb258ff ready; slots Herb sage-1956, Darkwing 245 sage-1961 (sage-1894..1962) | in progress
|
||||
|
||||
+3
-150
@@ -599,8 +599,7 @@ error. Before anything stops, a run whose Console flags hold `--sso` refuses
|
||||
`sso-target` for a target Console without it, `sso-config` when the target's own
|
||||
`checkConsole` refuses the config's `console` key (or there is none, in which
|
||||
case, from another copy, it names the first step: activate the target without
|
||||
`--sso`, then write `console.sso`; on a named instance both commands carry
|
||||
`--instance NAME`), and `sso-slot` for each provider's slot file
|
||||
`--sso`, then write `console.sso`), and `sso-slot` for each provider's slot file
|
||||
that is missing, a symlink, not a regular file, not owned by this uid, has group
|
||||
or other bits, resolves inside the repository or the copies, or is empty. It
|
||||
uses `lstat`, `stat` and `realpath` on the slot and never reads it. `--plan`
|
||||
@@ -670,7 +669,7 @@ pinned copy](../packages/cli/README.md#one-pinned-copy-row-85-1579)).
|
||||
#### Rehearsal on a scratch root (D2, row 163)
|
||||
|
||||
```
|
||||
scripts/stack-release.sh rehearse ID BUSINESS --backup ACTIVATION|PATH|last --port N [--timeout S]
|
||||
scripts/stack-release.sh rehearse ID BUSINESS --backup ACTIVATION|PATH --port N [--timeout S]
|
||||
```
|
||||
|
||||
`rehearse` starts the target copy's bus host and Console on a copy of a
|
||||
@@ -681,11 +680,7 @@ runs it against live data. It stops and starts no unit and writes no pointer
|
||||
or log line.
|
||||
|
||||
`--backup` takes an activation id under `<dataRoot>/backups/stack/` or an
|
||||
absolute path. `--backup last` (row 233) takes the newest backup the
|
||||
activation log records and prints `PASS backup-last` naming it. With none in
|
||||
the log it fails `no-backup`, exits 3 and makes no directory. After the
|
||||
backup's checks it prints `BACKUP_STORE <activation id> schema <version>`.
|
||||
`--port` is the scratch Console's loopback port, 1024 to
|
||||
absolute path. `--port` is the scratch Console's loopback port, 1024 to
|
||||
65535. The run refuses `port-reserved` for 7332, 7333 and the pointer's
|
||||
`--port` and `--tester-port`, and `port-in-use` for a port something holds;
|
||||
it never picks another port. `--timeout` (default 60 seconds) bounds the
|
||||
@@ -784,148 +779,6 @@ instance (the business's `launch.by`), for this business, whose run started at
|
||||
or after the floor. `status` adds an
|
||||
`awaiting units:` line for an open activation.
|
||||
|
||||
Under `--units external`, `activate --plan` also refuses `open-activation`
|
||||
while any rollback set holds `AWAITING-UNITS`, and `migrate-required` when
|
||||
the target migrates the store and the run lacks `--migrate` (row 233). Under
|
||||
`--units user` the plan's bytes are unchanged.
|
||||
|
||||
#### Root's upgrade driver (`scripts/stack-upgrade.sh`, row 233)
|
||||
|
||||
```
|
||||
scripts/stack-upgrade.sh upgrade --instance dev --bundle FILE --sha SHA [--migrate] [--no-rehearsal]
|
||||
[--rehearse-port N] [--timeout S]
|
||||
scripts/stack-upgrade.sh rollback --instance dev --to ID [--restore ACT [--events N]] [--timeout S]
|
||||
```
|
||||
|
||||
Root runs it from a root-owned checkout of the reviewed commit, never from a
|
||||
copy, because the stack's user can write the copies. Each run needs Mos's go,
|
||||
and `--migrate` needs Jason present (decision 96). The host must be prepared
|
||||
first (`docs/guides/host-run-sheet.md`). Only the default instance, `dev`, is
|
||||
accepted; a named instance's units are a later row.
|
||||
|
||||
The unit values come from `/etc/mosaic-stack/dev.args`, which I2's install
|
||||
writes: one `case2-unit.sh` argument per line, the serve flags after `--`,
|
||||
owned by root with no group or other write, exactly one `--copy`, and that
|
||||
copy the one both installed units run. Otherwise the run refuses
|
||||
`args-unreadable` or `args-differ`. The driver writes the new copy id into
|
||||
that file only after `confirm` passes.
|
||||
|
||||
`upgrade`, in order. Every stack user step runs as
|
||||
`sudo -u USER -H env PATH=<node dir>:/usr/local/bin:/usr/bin:/bin` from the
|
||||
user's clone `<home>/src/mosaic-stack`:
|
||||
|
||||
1. Takes `flock -n` on `/run/mosaic-stack/upgrade-dev.lock` and holds it to
|
||||
the end, rollback included. A second run refuses `upgrade-running`, and
|
||||
a lock it can't open refuses `lock-failed`.
|
||||
2. Fetches the bundle's `refactor` into the clone and fast-forwards it to
|
||||
SHA (`fetch-failed`), then `stack-copy.sh copy --bundle FILE SHA`
|
||||
(`copy-failed`).
|
||||
3. A1: this checkout's HEAD is SHA (`head-mismatch`), the copy exists
|
||||
(`copy-missing`), `/usr/local/lib/mosaic-stack/hostcheck.sh --check`
|
||||
exits 0 (`profile-drift`, row 240), both units name one copy
|
||||
(`units-unreadable`, `units-disagree`) and it is the args file's
|
||||
(`args-differ`), and
|
||||
`activate SHA BUSINESS --units external --plan --expect-from OLD` exits 0
|
||||
(`plan-refused`, which covers `open-activation`, `migrate-required` and
|
||||
`pointer-differs`).
|
||||
4. The rehearsal, `rehearse SHA BUSINESS --backup last --port 7339`
|
||||
(`--rehearse-port`). Exit 0 goes on. Exit 3 means no backup in the log
|
||||
and goes on only with `--no-rehearsal`, logging `rehearsal-skipped`;
|
||||
without the flag it refuses `no-backup`. Exit 0 with `--no-rehearsal`
|
||||
refuses `rehearsal-required`; any other exit refuses `rehearsal-failed`.
|
||||
5. A2 stops the Console, then the bus, and waits for both to read inactive
|
||||
or failed. A3 is `activate --units external`, A4 the render with the new
|
||||
`--copy` (which also starts the bus, then the Console), A5 `confirm`.
|
||||
The driver writes the new args file beside the old one before A2
|
||||
(`args-failed`, exit 3) and moves it into place after A5. A failed move
|
||||
exits 5 `args-failed`: the new copy is live and confirmed, the args file
|
||||
still names the old one, and root moves the new file (the result line
|
||||
names it) into place by hand.
|
||||
|
||||
A failure in A2 or a stage that exits 3 starts the old units again and gates
|
||||
them (A2f). A later failure stops both units, runs `revert`, renders the old
|
||||
copy and runs `confirm --rollback OLD --cause A3|A4|A5`. `rollback` is the
|
||||
same from A1 on, with `rollback BUSINESS --to ID`, no fetch, no copy and no
|
||||
rehearsal; `--restore` and `--events` pass through.
|
||||
|
||||
Root reads no output the stack user wrote except exit codes and the
|
||||
rehearsal's `BACKUP_STORE` line, which it copies into its log after a match
|
||||
against a fixed pattern (`BACKUP_STORE none` otherwise). The step log
|
||||
`/var/log/mosaic-stack/upgrade-dev.log`, 0640, gets one
|
||||
`<time> <step> rc=N argv: ...` line per step and a last
|
||||
`<time> result exit=N <code> <text>` line.
|
||||
|
||||
Exit 0 ok, 1 failed with the old stack running and gated, 2 rollback-failed
|
||||
with both units stopped, 3 refused with nothing stopped, 4 usage, 5
|
||||
args-failed with the new stack live and confirmed. A refusal
|
||||
after step 2 leaves the user's clone fast-forwarded and the new copy made. After exit
|
||||
2 the activation stays open, so the next run's plan refuses until root
|
||||
finishes it.
|
||||
|
||||
#### Root's host check (`scripts/case1-hostcheck.sh`, row 240)
|
||||
|
||||
```
|
||||
/usr/local/lib/mosaic-stack/hostcheck.sh --check | --enforce | --upstream
|
||||
```
|
||||
|
||||
Installed from `scripts/case1-hostcheck.sh` as `hostcheck.sh`, with
|
||||
`scripts/case1-pins.sh` beside it (`docs/guides/host-run-sheet.md` section 4).
|
||||
The pins are the profile's sha256, the `apparmor-profiles` version it came
|
||||
from and the bubblewrap install pin; changing one is a reviewed commit.
|
||||
Seven items, one `ok N` or `FAIL N` line each: the profile file matches the
|
||||
pin and no package owns it; `aa-status` has `bwrap` and `unpriv_bwrap` in
|
||||
enforce mode and no `mosaic-bwrap`; no other file under `/etc/apparmor.d`
|
||||
names `bwrap`; a bwrap child under the units' no-new-privs reads
|
||||
`bwrap//&unpriv_bwrap (enforce)`; `/usr/bin/bwrap` is `root mosaic 0750` by
|
||||
the statoverride and by `stat`; the user-namespace restriction and
|
||||
`fs.protected_hardlinks` are 1; `net.ipv4.ip_unprivileged_port_start` is
|
||||
above the Console unit's `--port`, or above 1023 with no unit. A `note` line
|
||||
says whether bubblewrap is the install pin and never fails.
|
||||
|
||||
`--check` exits 0 or 1; `stack-upgrade.sh` refuses `profile-drift` on 1.
|
||||
`--enforce` exits 0. On a failure, or while `/etc/mosaic-stack/DRIFT` exists,
|
||||
it unloads the profile if loaded, sets `/usr/bin/bwrap` to `root:root` 0700,
|
||||
appends the failed items to `DRIFT` and one line to
|
||||
`/var/log/mosaic-stack/hostcheck.log`. It never writes the statoverride. The
|
||||
apt hook runs it after every package run, and `mosaic-hostcheck.service`
|
||||
(`packages/cli/systemd/`) at boot before the bus. `--upstream` compares the
|
||||
`apparmor-profiles` candidate's profile to the pin, prints any difference
|
||||
and exits 0, or 1 when the download fails. Exit 2 is usage or a refusal:
|
||||
root takes no `--root` (the test seam), and other users run only with it.
|
||||
|
||||
#### Root's acceptance run (`scripts/case1-accept.sh`, row 195)
|
||||
|
||||
```
|
||||
case1-accept.sh --business ID --args FILE --claude-pin PIN --node-pin vN.N.N
|
||||
```
|
||||
|
||||
Root runs it on the Case 1 host after the install window, from a root-owned
|
||||
checkout. It reads the user, home, copy, node, claude and both ports from the
|
||||
args file (`/etc/mosaic-stack/dev.args` on .53), which must pass
|
||||
`stack-upgrade.sh`'s rules, say `--profile factory` and name `--business`.
|
||||
Every command that runs the stack's code runs as
|
||||
`sudo -u USER -H env PATH=<node dir>:/usr/local/bin:/usr/bin:/bin` from `/`.
|
||||
Root only reads systemd, `ss`, `/proc`, the account database and file
|
||||
metadata. The one write is F3's message and its reply, and it never opens
|
||||
`claude-session.env`.
|
||||
|
||||
It prints one line per check, `<id> <path> <mark> <evidence>`, then
|
||||
`count <mark> N` for each mark and a result line. The functional checks
|
||||
F1-F11 are `pass` or `FAIL`: both units active as the user, the Console on
|
||||
127.0.0.1 only, a tester message to chief answered, `case2-precheck.sh
|
||||
--profile factory`, the bwrap labels of a live role session, the claude and
|
||||
node pins, one live PM launch, the credential file's owner and mode, the
|
||||
autoupdater off, no Discord binding. The host paths P1-P11 are `closed`,
|
||||
`accepted <ruling>` (Q182, Q183, mos-1096, mos-1101) or `unnamed`, which means
|
||||
no ruling names the path; each `unnamed` line goes to Mos. P9 runs
|
||||
`hostcheck.sh --check`, never `--enforce`.
|
||||
|
||||
Exit 0 when every F check passes, 1 when one fails, 2 on usage or a refusal:
|
||||
a bad args file, or `--root` misused. A P check never changes the exit.
|
||||
`--root DIR` is the test seam for `packages/cli/tests/case1-accept.test.mjs`;
|
||||
root takes none, and other users run only with it. Design: row 195 r7
|
||||
section 5 (`agents/darkwing/work/queue-195/DESIGN.md`).
|
||||
|
||||
## Console service (`scripts/webui-service.sh`)
|
||||
|
||||
```bash
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
# Your books in Mosaic: a setup sheet
|
||||
|
||||
This sheet is for you, Melanie. You keep writing in Obsidian the way you do now. Mosaic reads your
|
||||
books repo after obsidian-git pushes it to git.mosaicstack.dev. It changes nothing on your machine and
|
||||
commits nothing to your repo.
|
||||
|
||||
## What the agents read
|
||||
|
||||
The agents read your books repo as you last pushed it. A push reaches them in about a minute.
|
||||
|
||||
They read notes, the `.md` files, inside your book folders. They don't read:
|
||||
- notes at the top of the repo, outside any book folder
|
||||
- `.canvas` and `.base` files, even inside a book folder
|
||||
- images and other attachments
|
||||
- anything in your other repos under `~/src`
|
||||
|
||||
They can't write to your repo at all. That covers canon, the playground and everything else.
|
||||
|
||||
Which folders are book folders, and which hold characters, places, research, your tracker or chapter
|
||||
summaries, is set in one place. It is the `projects` entry of your business file in Mosaic. Jason
|
||||
edits it by hand, and the agents can't change it. He will ask you to confirm it before the agents start.
|
||||
|
||||
## Your playground
|
||||
|
||||
A folder named in the `playground` list of that entry is your playground. Each playground folder sits
|
||||
inside one book folder, so one per book works well, for example `<book>/playground/`. You choose the
|
||||
names and tell Jason. Until you have one, every note in a book folder is canon.
|
||||
|
||||
What the playground means for the agents:
|
||||
- They search canon unless they ask for the playground on purpose.
|
||||
- An agent may quote a playground note in an idea or a question. It may not use one to back a fact,
|
||||
a finding or a correction. Mosaic refuses that reply before you see it.
|
||||
- Only the folder decides. A tag or a property can't make a note playground or canon.
|
||||
|
||||
### Colour the playground in your graph
|
||||
|
||||
This is a setting of your own vault. It changes nothing for the agents.
|
||||
|
||||
1. Open the graph view and open its settings panel.
|
||||
2. Under Groups, choose New group.
|
||||
3. In the query box, type the playground's path with `path:`. Your vault is `~/src`, so the path
|
||||
starts with your books repo folder: `path:"<books repo folder>/<book>/<playground folder>"`.
|
||||
4. Pick a colour.
|
||||
|
||||
Add one group per playground folder.
|
||||
|
||||
## Two things you might not expect
|
||||
|
||||
### Moving a note into a book folder makes it canon
|
||||
|
||||
The folder decides, so a move changes what the agents may do with a note. Once you move a note out of
|
||||
the playground into a book folder and push, it is canon. The agents may then cite it as fact. A note
|
||||
that isn't settled yet belongs in the playground. Any note in a book folder outside the playground is
|
||||
canon, rough drafts included.
|
||||
|
||||
### A short link can point somewhere else for the agents
|
||||
|
||||
Obsidian looks up a short link like `[[Mara]]` across your whole vault, `~/src`. The agents see only
|
||||
your books repo. Say a note called `Mara` exists in your books repo and also in another of your repos.
|
||||
Obsidian and the agents can then open different notes for the same link, and the agents can't tell.
|
||||
If the name exists only in the other repo, the link leads nowhere for the agents.
|
||||
|
||||
A link with the full path from the top of your vault reaches the same note in both:
|
||||
|
||||
```
|
||||
[[<books repo folder>/<book>/<characters folder>/Mara]]
|
||||
```
|
||||
|
||||
Obsidian can write new links this way. In Settings, open Files and links and set New link format to
|
||||
Absolute path in vault.
|
||||
|
||||
## Lists of links in properties
|
||||
|
||||
The agents read the links in two properties, `appears_in` and `relationships`. Put quotes around each
|
||||
link in the list:
|
||||
|
||||
```yaml
|
||||
appears_in: ["[[A]]", "[[B]]"]
|
||||
```
|
||||
|
||||
One link per line works too:
|
||||
|
||||
```yaml
|
||||
appears_in:
|
||||
- "[[A]]"
|
||||
- "[[B]]"
|
||||
```
|
||||
|
||||
Obsidian's property editor adds the quotes for you. If you type the list by hand, don't leave them out:
|
||||
|
||||
```yaml
|
||||
appears_in: [[[A]], [[B]]]
|
||||
```
|
||||
|
||||
The agents' reader can't read that form. It then ignores every property of that note and lists the
|
||||
note as a problem in Mosaic's status. It still finds the note by its path, its name and its text. A
|
||||
value written without `[[ ]]` counts as a plain name, not a link.
|
||||
|
||||
## What changes for Bean and Chet
|
||||
|
||||
They keep their names and personalities. How they answer changes.
|
||||
|
||||
In Hermes they answer in free text and may write story text when you ask. In Mosaic every reply is a
|
||||
short list of items. Each item is an idea, a question, a finding or a fact. Each one quotes a line
|
||||
from your repo or from a web page the agent read for you.
|
||||
|
||||
They don't write passages. If you ask for prose, you get a question or an idea instead.
|
||||
|
||||
A reply holds at most 10 items and at most 1,200 characters of item text in all. It has at most 5
|
||||
ideas of up to 200 characters each. A question, finding or fact runs up to 300 characters. You or
|
||||
Jason can ask for lower limits. When an agent can't back an answer with a quote, you see "No cited
|
||||
answer" instead.
|
||||
|
||||
Each book world stays separate. One item can't mix quotes from two worlds.
|
||||
|
||||
You talk to them in the Console. Hermes keeps running until you have moved over, and stopping it is
|
||||
your choice.
|
||||
|
||||
Five more helpers can join them: ideas, research, proofreader, fact-checker and continuity. You
|
||||
choose which ones to start with, and you can add one later.
|
||||
|
||||
## What Jason will ask you
|
||||
|
||||
He will ask you to confirm your book folders and type folders, which books share a world, the name of
|
||||
each playground folder, and which helpers to start with and when.
|
||||
@@ -1,122 +0,0 @@
|
||||
# Survey run sheet for the library host
|
||||
|
||||
This sheet is for whoever runs `mosaic library survey` on `<host>`, 10.1.1.54, under design 10 step
|
||||
7. The survey reads one commit of a git repo and prints names and counts. It never prints note text,
|
||||
property values, file names or link targets. Jason fills in the mapping for Melanie's books repo
|
||||
from its output and her answers.
|
||||
|
||||
Out of scope: sending anything to Melanie. Design 10 step 7 makes that Jason's call.
|
||||
|
||||
## Before you start
|
||||
|
||||
- Jason's go for step 7. Step 4, the bot token in the `library-gitea` slot, comes first.
|
||||
- You run as `mosaic` with `sudo -u mosaic -H` from `localadmin`. `mosaic` has no login shell.
|
||||
- The stack copy from step 2 is in place at `/srv/mosaic/.local/share/mosaic-stack/copies/<id>`.
|
||||
`<id>` is the full commit id in Jason's go. It must hold row 231, which escapes control and bidi
|
||||
characters in folder names. In a canonical checkout, `git merge-base --is-ancestor 29ce1e360 <id>`
|
||||
exits 0 when it does.
|
||||
- `<node dir>`, the directory that holds `node`. It is the directory of the `--node` path given to
|
||||
`case2-unit.sh` in step 2c. `scripts/mosaic` runs `node` from `PATH`.
|
||||
- `<repo>`, an absolute path. See the next section.
|
||||
|
||||
## The repo to survey
|
||||
|
||||
The survey reads a local repo. It doesn't fetch. `<repo>` must:
|
||||
- be the repo's top folder, or a bare repo's own folder. A folder inside a repo refuses, because the
|
||||
survey stops git from looking above the path's parent.
|
||||
- belong to `mosaic`. The survey gives git no global config, so a `safe.directory` entry can't
|
||||
admit a repo another user owns.
|
||||
- have a `HEAD` that names a commit. The survey reads `HEAD` and has no flag for another ref.
|
||||
|
||||
`<repo>` is the bus's bare mirror at `<dataRoot>/projects/<business>/<project>`, which C2-04 (row 215)
|
||||
creates and C2-03a (row 222) fetches into. It is the only copy of her repo on the host (design 2.1), and
|
||||
`mosaic` owns it. Survey it after the first `library.sync` succeeds. The mirror's `HEAD` points at
|
||||
`refs/heads/served` (C2-03a brief), so the survey reads the commit the agents are served.
|
||||
|
||||
Don't survey anything else. A hand clone with the bot token would put the token where design 7.2 keeps
|
||||
it out, and the mirror's refs belong to the bus. If `HEAD` names no commit, stop and report to Sage.
|
||||
|
||||
## Steps
|
||||
|
||||
1. `ssh [email protected]`.
|
||||
2. Check which `node` runs. `PATH` ends in `/usr/bin:/bin`, so a wrong `<node dir>` would quietly run
|
||||
another `node`:
|
||||
|
||||
```sh
|
||||
cd /
|
||||
sudo -u mosaic -H env PATH="<node dir>:/usr/bin:/bin" sh -c 'command -v node; node --version'
|
||||
```
|
||||
|
||||
The first line must be `<node dir>/node`. If it isn't, fix `<node dir>` before going on.
|
||||
3. Run the survey without a mapping:
|
||||
|
||||
```sh
|
||||
cd /
|
||||
sudo -u mosaic -H env PATH="<node dir>:/usr/bin:/bin" \
|
||||
/srv/mosaic/.local/share/mosaic-stack/copies/<id>/scripts/mosaic library survey <repo>
|
||||
echo "exit $?"
|
||||
```
|
||||
|
||||
4. On exit 0, give the output to Jason. On any other exit, see "Refusals" below.
|
||||
5. When Jason has a draft mapping, run it again with `--mapping`. The file holds the library entry
|
||||
alone, `{"kind": "library", "remote": ..., "branch": ..., ...}`, without the business file or the
|
||||
`"projects"` wrapper around it. `remote` and `branch` are required even though the survey doesn't
|
||||
fetch. `mosaic` must be able to read the file. Set `vaultPrefix` to her books repo's folder name
|
||||
in her vault. Without it, a link with the full path from the top of her vault resolves to nothing,
|
||||
and the setup sheet tells her to write links that way.
|
||||
|
||||
```sh
|
||||
sudo -u mosaic -H env PATH="<node dir>:/usr/bin:/bin" \
|
||||
/srv/mosaic/.local/share/mosaic-stack/copies/<id>/scripts/mosaic library survey <repo> --mapping <file>
|
||||
echo "exit $?"
|
||||
```
|
||||
|
||||
The usage line is `mosaic library survey <repo> [--mapping <file>]`. `--mapping <file>` is the only
|
||||
flag, and it may appear once. `--mapping=<file>` and every other flag refuse.
|
||||
|
||||
## What the output holds
|
||||
|
||||
Plain text on stdout, one line per item:
|
||||
|
||||
| Line | What it holds |
|
||||
|---|---|
|
||||
| `commit <id>` | the 40-hex commit `HEAD` names |
|
||||
| `entries <n>` | every entry in that commit's tree |
|
||||
| `folders (direct children: md canvas base other)` | then one line per folder that holds a file directly: its path as a JSON string and four counts. `(root)` is the repo's top |
|
||||
| `markdown <n> files, <n> read, ...` | `.md` files, how many were read, how many have no front matter, how many have front matter the reader can't fully parse |
|
||||
| `front matter key sets` | then `<count> [<keys>]` per set of property names. A name that isn't a short identifier prints as `(other key)` |
|
||||
| `body links plain .., label .., heading .., embed .., self .., markdown ..; attachment ..` | link forms in note bodies, and embeds of a target with an extension other than `.md` |
|
||||
| `field appears_in wikilink .., name ..` | values written as links and as plain names. A `relationships` line follows |
|
||||
|
||||
With `--mapping` three lines follow:
|
||||
|
||||
| Line | What it holds |
|
||||
|---|---|
|
||||
| `scopes canon .., playground .., unmapped ..; indexed ..` | tree entries per scope, and notes indexed |
|
||||
| `resolved root .., vault-prefix .., relative .., shortest .., unresolved ..` | links per resolver step. `unresolved` is the R4 count |
|
||||
| `problems R1 .., ..., R7 ..` | problems per rule |
|
||||
|
||||
Folder paths and short property names are the only words from her repo in the output. In a folder
|
||||
name, tab, newline, carriage return, backspace and form feed print as `\t`, `\n`, `\r`, `\b` and `\f`.
|
||||
Any other control or bidi character prints as `\uXXXX`.
|
||||
|
||||
## Refusals
|
||||
|
||||
A refusal prints nothing on stdout and one line on stderr. The survey checks the mapping before the
|
||||
repo, so a bad mapping gives exit 3 even when the repo path is wrong too.
|
||||
|
||||
| Exit | stderr | Cause | What to do |
|
||||
|---|---|---|---|
|
||||
| 4 | `library survey: usage: mosaic library survey <repo> [--mapping <file>]` | no repo, two repos, an unknown flag, `--mapping` without a file or twice | Fix the command |
|
||||
| 3 | `library survey: library-mapping-invalid: <file> is not a readable JSON file` | missing, unreadable by `mosaic`, or not JSON | Fix the file or its mode |
|
||||
| 3 | `library survey: library-mapping-invalid: <file> <reason>` | the entry breaks the schema. The reason names the key | Give it to Jason for the draft |
|
||||
| 3 | `library survey: library-playground-outside-book: <file> universes.<u>.playground "<prefix>" is not inside one of its books` | a playground prefix outside its universe's books | Give it to Jason for the draft |
|
||||
| 2 | `library survey: library-git: <repo> is not a directory` | wrong path | Check `<repo>` |
|
||||
| 2 | `library survey: library-git: repository has no readable HEAD commit (project-git)` | not a repo, a folder inside one, another owner, no commits, a `HEAD` with no commit, or no `git` on `PATH` | Check each. If `<repo>` is the bus mirror, stop and report to Sage |
|
||||
| 2 | `library survey: library-git: <other reason>`, such as `tree listing refused (project-git)` | git failed or ran past 100 seconds | Report to Sage |
|
||||
| 2 | `library survey: library-commit: <reason>` | `HEAD` names something the reader can't take as a commit, for example in a SHA-256 repository | Report to Sage |
|
||||
| 127 | a line ending `exec: node: not found` | `node` isn't in `<node dir>` | Fix `<node dir>` |
|
||||
| other | a Node stack trace | a fault in the survey | Stop and report the exit code to Sage |
|
||||
|
||||
A refusal is the answer, not an obstacle. Don't run as another user, change modes on her repo or edit
|
||||
its refs to get past one.
|
||||
@@ -1,281 +0,0 @@
|
||||
# Host run sheet: preparing a host for the stack
|
||||
|
||||
ops-01 runs this on a fresh host before install (I2), and once per host for enrollment. Jason places the
|
||||
credentials in section 9. Brief: `docs/plans/2026-10-20_installer-rows.md`, I3 (row 233, #1735). The
|
||||
host design is Darkwing's r6 (`agents/darkwing/work/queue-195/DESIGN.md`, section 2) as the brief
|
||||
changes it.
|
||||
|
||||
The hosts are .53 (profile `factory`) and .54 (profile `library`). Both get every section unless a
|
||||
section says otherwise. Every command runs as root unless it starts with `sudo -u mosaic`.
|
||||
|
||||
Each item names the `scripts/case2-precheck.sh` line that verifies it. Install's precheck runs as the
|
||||
stack's user with `--business ID --profile factory|library`. Where no precheck line checks an item, the
|
||||
item says "precheck line missing", and Gosalyn adds the line to I2. Today's precheck (C2-13a) has these
|
||||
gaps; C2-13b adds the library lines (`library.sync`, persona modes, no Discord binding).
|
||||
|
||||
## 1. The stack's user and its home
|
||||
|
||||
```sh
|
||||
useradd --system --user-group --home-dir /srv/mosaic --create-home --shell /usr/sbin/nologin mosaic
|
||||
chmod 0700 /srv/mosaic
|
||||
install -d -o root -g root -m 0755 /etc/mosaic-stack
|
||||
install -d -o root -g root -m 0750 /var/log/mosaic-stack
|
||||
```
|
||||
|
||||
`mosaic` gets no sudo rule and no supplementary group. Check with `sudo -l -U mosaic` (expect "not allowed
|
||||
to run sudo") and `id -G mosaic` (one number).
|
||||
|
||||
Precheck lines:
|
||||
- `ok HOME is /srv/mosaic`
|
||||
- `ok sudo -n true fails as mosaic`
|
||||
- `ok id -G prints one group (<gid>)`
|
||||
- `/srv/mosaic` at 0700: precheck line missing.
|
||||
|
||||
## 2. node, pinned under /opt
|
||||
|
||||
The pin is the version and sha256 the window names. `<v>` below is that version, for example `v24.x.y`.
|
||||
|
||||
```sh
|
||||
install -d -o root -g root -m 0755 /etc/mosaic-stack/node-keys /opt/mosaic-stack
|
||||
cd "$(mktemp -d)"
|
||||
curl -fsSLO https://nodejs.org/dist/<v>/node-<v>-linux-x64.tar.xz
|
||||
curl -fsSLO https://nodejs.org/dist/<v>/SHASUMS256.txt
|
||||
curl -fsSLO https://nodejs.org/dist/<v>/SHASUMS256.txt.asc
|
||||
gpg --no-default-keyring --keyring /etc/mosaic-stack/node-keys/pubring.kbx --verify SHASUMS256.txt.asc SHASUMS256.txt
|
||||
grep " node-<v>-linux-x64.tar.xz\$" SHASUMS256.txt | sha256sum -c -
|
||||
echo "<pinned sha256> node-<v>-linux-x64.tar.xz" | sha256sum -c -
|
||||
tar -xJf node-<v>-linux-x64.tar.xz --no-same-owner
|
||||
mv node-<v>-linux-x64 /opt/mosaic-stack/node-<v>
|
||||
chown -R root:root /opt/mosaic-stack/node-<v>
|
||||
chmod -R go-w /opt/mosaic-stack/node-<v>
|
||||
```
|
||||
|
||||
The keyring holds the Node release keys from the nodejs/release-keys repository, nothing else. Stop on any
|
||||
failed check; don't unpack. Rollback: `rm -r /opt/mosaic-stack/node-<v>`.
|
||||
|
||||
Precheck lines:
|
||||
- `ok node <v>` (version 24 or later only).
|
||||
- The `--node` path in the args file must be a root-owned regular file outside the home. `case2-unit.sh`
|
||||
refuses otherwise at render, which is not a precheck line.
|
||||
- The installed version equals the pin: precheck line missing.
|
||||
|
||||
## 3. claude, factory only (.53)
|
||||
|
||||
Root installs it under `/opt`, never under the stack's home (this replaces r6's `/srv/mosaic/.local/bin`).
|
||||
The pin is 2.1.304 unless the window names a newer one.
|
||||
|
||||
```sh
|
||||
install -d -o root -g root -m 0755 /opt/mosaic-stack/claude-<pin> /etc/claude-code
|
||||
PATH=/opt/mosaic-stack/node-<v>/bin:/usr/sbin:/usr/bin:/sbin:/bin \
|
||||
npm install --prefix /opt/mosaic-stack/claude-<pin> @anthropic-ai/claude-code@<pin>
|
||||
chown -R root:root /opt/mosaic-stack/claude-<pin>
|
||||
/opt/mosaic-stack/claude-<pin>/node_modules/@anthropic-ai/claude-code/bin/claude.exe --version
|
||||
printf '%s\n' '{"env":{"DISABLE_AUTOUPDATER":"1"}}' > /etc/claude-code/managed-settings.json
|
||||
chown root:root /etc/claude-code/managed-settings.json
|
||||
chmod 0644 /etc/claude-code/managed-settings.json
|
||||
```
|
||||
|
||||
Rollback: `rm -r /opt/mosaic-stack/claude-<pin> /etc/claude-code/managed-settings.json`.
|
||||
|
||||
Root's PATH has no npm, so the install line puts section 2's pinned node first; the package's postinstall
|
||||
also runs `node`. The `--version` line must print `<pin> (Claude Code)`. Anything else means the postinstall
|
||||
left its 500-byte stub in `bin/claude.exe` (no native package for the platform, or scripts were off): stop and
|
||||
roll back.
|
||||
|
||||
The args file's `--claude` is
|
||||
`/opt/mosaic-stack/claude-<pin>/node_modules/@anthropic-ai/claude-code/bin/claude.exe`, the regular file the
|
||||
postinstall hardlinks or copies the native binary to. Not `node_modules/.bin/claude`: that is npm's symlink
|
||||
to it, and `case2-unit.sh` refuses a symlink, as it does anything that isn't a root-owned regular file outside
|
||||
the home. Checked against the 2.1.304 package's `install.cjs`; a newer pin needs the same check.
|
||||
|
||||
Precheck lines:
|
||||
- `ok claude replaces its prompt with --system-prompt-file (<n> input tokens)`. It runs the claude the bus
|
||||
unit's `MOSAIC_CLAUDE_BIN` names, so it needs the model credential from section 9.
|
||||
- Managed settings present with the autoupdater off: precheck line missing.
|
||||
|
||||
## 4. bubblewrap, AppArmor and the drift stop
|
||||
|
||||
Both hosts. These are r6's items, unchanged.
|
||||
|
||||
```sh
|
||||
apt-get install bubblewrap=0.9.0-1ubuntu0.3
|
||||
stat -c '%U:%G %a' /usr/bin/bwrap > /etc/mosaic-stack/bwrap.orig # expect root:root 755
|
||||
|
||||
cd "$(mktemp -d)"
|
||||
apt-get download apparmor-profiles=4.0.1really4.0.1-0ubuntu0.24.04.9
|
||||
dpkg-deb --fsys-tarfile apparmor-profiles_*.deb | tar -x ./usr/share/apparmor/extra-profiles/bwrap-userns-restrict
|
||||
echo "11d39094f044f0cda0febb3ad517b830301da6b2ce929664af09ee9e4dd264f9 usr/share/apparmor/extra-profiles/bwrap-userns-restrict" | sha256sum -c -
|
||||
install -o root -g root -m 0644 usr/share/apparmor/extra-profiles/bwrap-userns-restrict /etc/apparmor.d/bwrap-userns-restrict
|
||||
apparmor_parser -r /etc/apparmor.d/bwrap-userns-restrict
|
||||
|
||||
dpkg-statoverride --update --add root mosaic 0750 /usr/bin/bwrap
|
||||
```
|
||||
|
||||
`aa-status` then lists `bwrap` and `unpriv_bwrap` in enforce mode. Install the one profile file, never the
|
||||
whole `apparmor-profiles` package, whose 20 other profiles would load at the next boot. Rollback, in
|
||||
reverse order: `dpkg-statoverride --remove /usr/bin/bwrap`, then `chown` and `chmod` to the values in
|
||||
`bwrap.orig`; `apparmor_parser -R /etc/apparmor.d/bwrap-userns-restrict`, then `rm` it;
|
||||
`apt-get remove bubblewrap`.
|
||||
|
||||
The no-new-privs test must print `bwrap//&unpriv_bwrap (enforce)`:
|
||||
|
||||
```sh
|
||||
systemd-run --wait --pipe --uid=mosaic --gid=mosaic -p NoNewPrivileges=yes -p ProtectSystem=strict \
|
||||
-p ProtectHome=yes -p PrivateTmp=yes \
|
||||
/usr/bin/bwrap --unshare-user --unshare-pid --ro-bind / / cat /proc/self/attr/current
|
||||
```
|
||||
|
||||
The P9 checks: another user's `/usr/bin/bwrap --version` fails with Permission denied, `getent group mosaic`
|
||||
lists no member, and `sysctl fs.protected_hardlinks` prints 1. `sysctl
|
||||
kernel.apparmor_restrict_unprivileged_userns` prints 1 too (Ubuntu 24.04's default); leave it, so nothing
|
||||
else on the host gains user namespaces.
|
||||
|
||||
The drift stop (row 240, I4, #1746) goes in last, after the profile and the statoverride. As root, from
|
||||
the root-owned checkout of the reviewed commit:
|
||||
|
||||
```sh
|
||||
install -d -o root -g root -m 0755 /usr/local/lib/mosaic-stack
|
||||
install -o root -g root -m 0755 scripts/case1-hostcheck.sh /usr/local/lib/mosaic-stack/hostcheck.sh
|
||||
install -o root -g root -m 0644 scripts/case1-pins.sh /usr/local/lib/mosaic-stack/case1-pins.sh
|
||||
printf '%s\n' 'DPkg::Post-Invoke { "/usr/local/lib/mosaic-stack/hostcheck.sh --enforce || true"; };' \
|
||||
> /etc/apt/apt.conf.d/80mosaic-hostcheck
|
||||
install -o root -g root -m 0644 packages/cli/systemd/mosaic-hostcheck.service /etc/systemd/system/
|
||||
systemctl daemon-reload && systemctl enable mosaic-hostcheck.service
|
||||
/usr/local/lib/mosaic-stack/hostcheck.sh --check
|
||||
```
|
||||
|
||||
`--check` prints one `ok` line for each of its seven items and exits 0. Item 7 reads 1023 as the port
|
||||
until I2 installs the Console unit (section 10), then the unit's `--port`. `stack-upgrade.sh` runs `--check`
|
||||
before its plan and refuses `profile-drift` on any exit but 0, a missing file included. Rollback:
|
||||
`systemctl disable mosaic-hostcheck.service`, then `rm` the unit, the hook file and
|
||||
`/usr/local/lib/mosaic-stack`.
|
||||
|
||||
On drift, `--enforce` (the apt hook after every package run, and the unit at boot) unloads the profile,
|
||||
closes `/usr/bin/bwrap` to `root:root` 0700, appends the failed items to `/etc/mosaic-stack/DRIFT` and logs
|
||||
a line in `/var/log/mosaic-stack/hostcheck.log`. Every role session then refuses to start. ops-01 reads the
|
||||
log in each STATE report and sends any `DRIFT` to Mos. Only root removes `DRIFT`, in a reviewed step with
|
||||
a new pin or a Mos go. After that, `chown root:mosaic /usr/bin/bwrap`, `chmod 0750 /usr/bin/bwrap` and
|
||||
`apparmor_parser -r /etc/apparmor.d/bwrap-userns-restrict` put bwrap back, and `--check` must exit 0.
|
||||
|
||||
Before each re-pin window, ops-01 runs `/usr/local/lib/mosaic-stack/hostcheck.sh --upstream`. It
|
||||
downloads the `apparmor-profiles` candidate and compares its `bwrap-userns-restrict` to the pin. A
|
||||
`DIFFERS` line goes to Mos as a new-pin request; it refuses nothing.
|
||||
|
||||
Precheck lines:
|
||||
- `ok bwrap --unshare-all runs`
|
||||
- The AppArmor profile, the statoverride, the no-new-privs result and the P9 checks: precheck line missing.
|
||||
`/usr/local/lib/mosaic-stack/hostcheck.sh --check` covers them (row 240).
|
||||
|
||||
## 5. The port floor
|
||||
|
||||
Leave `net.ipv4.ip_unprivileged_port_start` at its default (1024) or higher. The Console's port is below
|
||||
it and the unit gets `CAP_NET_BIND_SERVICE`, so no other `mosaic` process can bind that port.
|
||||
|
||||
Precheck line: `ok net.ipv4.ip_unprivileged_port_start <n> is above the Console's port <port>`.
|
||||
|
||||
## 6. The release transport
|
||||
|
||||
A release is a git bundle of `refs/heads/refactor` plus the 40-character commit id (I1, mos-1118 choice 2).
|
||||
Mos's go names both, with the bundle's sha256. `<sha>` below is that id.
|
||||
|
||||
First install:
|
||||
|
||||
```sh
|
||||
# Copy the bundle in, then check it before anything reads it.
|
||||
echo "<bundle sha256> /root/<sha>.bundle" | sha256sum -c -
|
||||
git bundle verify /root/<sha>.bundle
|
||||
|
||||
# Root's checkout. stack-upgrade.sh and case2-unit.sh run from here, never from a copy.
|
||||
git clone -q -b refactor /root/<sha>.bundle /root/mosaic-stack
|
||||
git -C /root/mosaic-stack checkout -q --detach <sha>
|
||||
git -C /root/mosaic-stack rev-parse HEAD # must print <sha>
|
||||
|
||||
# The stack's user's copy of the bundle, and its own clone.
|
||||
install -d -o mosaic -g mosaic -m 0700 /srv/mosaic/incoming /srv/mosaic/src
|
||||
install -o mosaic -g mosaic -m 0600 /root/<sha>.bundle /srv/mosaic/incoming/<sha>.bundle
|
||||
sudo -u mosaic -H git clone -q -b refactor /srv/mosaic/incoming/<sha>.bundle /srv/mosaic/src/mosaic-stack
|
||||
```
|
||||
|
||||
Each upgrade, before `stack-upgrade.sh upgrade`:
|
||||
|
||||
```sh
|
||||
echo "<bundle sha256> /root/<sha>.bundle" | sha256sum -c -
|
||||
git bundle verify /root/<sha>.bundle
|
||||
git -C /root/mosaic-stack fetch -q /root/<sha>.bundle refs/heads/refactor:refs/remotes/origin/refactor
|
||||
git -C /root/mosaic-stack checkout -q --detach <sha>
|
||||
install -o mosaic -g mosaic -m 0600 /root/<sha>.bundle /srv/mosaic/incoming/<sha>.bundle
|
||||
/root/mosaic-stack/scripts/stack-upgrade.sh upgrade --instance dev --bundle /srv/mosaic/incoming/<sha>.bundle --sha <sha>
|
||||
```
|
||||
|
||||
The driver fetches the bundle into the stack's user's clone and makes the copy itself. It refuses
|
||||
`head-mismatch` when root's checkout isn't at `<sha>`. Usage, exits and the step log are in
|
||||
`docs/TOOLS.md`, under "Root's upgrade driver". Each run needs Mos's go, and `--migrate` needs Jason present
|
||||
(decision 96).
|
||||
|
||||
When a run doesn't exit 0, send Mos the exit and the last lines of `/var/log/mosaic-stack/upgrade-dev.log`:
|
||||
- Exit 3: refused before anything stopped. The last line names the code. The stack's user's clone and the
|
||||
new copy may already hold the new commit; the units still run the old one.
|
||||
- Exit 1: the old copy runs and passed its gate. Either the driver restarted it after A2 or a refused A3
|
||||
(A2f), or it rolled back after A3, A4 or A5.
|
||||
- Exit 2: both units are stopped and the activation stays open, so the next run refuses at its plan until
|
||||
it is finished with `confirm` or `revert`. One way here: a unit that doesn't stop within `--timeout`
|
||||
keeps its old start time, A2f's gate fails it `stale-start`, and the driver stops both (duckworth-0055
|
||||
N1). That is on purpose; a unit that won't stop is a reason to stop.
|
||||
- Exit 5: `args-failed`. The new copy is live and passed confirm, but `/etc/mosaic-stack/dev.args` still names
|
||||
the old copy. The next run refuses `args-differ`, and a render from that file would put the old copy back.
|
||||
Move the file the result line names into place with `mv -f`. The two differ only in the `--copy` value.
|
||||
|
||||
Precheck lines: none. Root's checkout at `<sha>` and the stack's user's clone: precheck line missing.
|
||||
After install, `stack-copy.sh check --units external` reads the copy the units run.
|
||||
|
||||
## 7. The args file
|
||||
|
||||
`/etc/mosaic-stack/dev.args` holds the `case2-unit.sh` arguments, one per line, with the serve flags after a
|
||||
line holding `--`. I2's install writes it; ops-01 doesn't write it by hand. It must be root's, with no group
|
||||
or other write (`chmod 0644` or tighter). Before `--` it takes only `--user`, `--home`, `--business`,
|
||||
`--copy` (exactly once), `--node`, `--profile`, `--claude` and `--pm`. `stack-upgrade.sh` changes only the
|
||||
`--copy` line, and only after confirm passes.
|
||||
|
||||
Precheck line: none. `stack-upgrade.sh` refuses `args-unreadable` on any of these rules.
|
||||
|
||||
## 8. Enrollment, once per host
|
||||
|
||||
The machine-grant enrollment is Gizmoduck's design r6, commit f9039682e, section 3, steps E1-E4. ops-01's
|
||||
Q-O1 is answered (mos-1125). The host side is the `tools/host/` files: `mosaic-keys`, `mosaic-keys-write`,
|
||||
their sudoers line and the sshd drop-in `/etc/ssh/sshd_config.d/<nn>-mosaic-keys.conf`. The verbs that run
|
||||
it (`hosts.enroll`, the `host-enroll` decision) are rows 234 and 235, not yet on refactor. This item has no
|
||||
commands until they land.
|
||||
|
||||
Precheck line: none. The enrolled host's key and its `mosaic-keys` sudoers line: precheck line missing.
|
||||
|
||||
## 9. Credential slots
|
||||
|
||||
Jason places these, all in one sitting per host. No value appears here or in any message. Check a placed
|
||||
file with `stat -c '%U %a %n' PATH`, never `cat`. `<business>` is the host's business id.
|
||||
|
||||
### .53, factory
|
||||
|
||||
| Path | File | Mode | Owner | Profile | Precheck line |
|
||||
|---|---|---|---|---|---|
|
||||
| `/srv/mosaic/.config/mosaic-dev/secrets/` | `claude-session.env`, one line `CLAUDE_CODE_OAUTH_TOKEN=...` (Q185) | 0600 | mosaic | factory | `claude replaces its prompt with --system-prompt-file` runs claude with it. The file's mode and owner: precheck line missing. |
|
||||
| `/srv/mosaic/.config/mosaic-dev/secrets/agents/<business>/<agent>/` | one file per service | 0600, dirs 0700 | mosaic | both | none. Filled only by `mosaic credentials issue`, or Approve after #436. Never by hand. |
|
||||
|
||||
### .54, library
|
||||
|
||||
| Path | File | Mode | Owner | Profile | Precheck line |
|
||||
|---|---|---|---|---|---|
|
||||
| `/srv/mosaic/.config/mosaic-dev/secrets/` | `claude-session.env`, one line `ZAI_API_KEY=...` | 0600 | mosaic | library | `<path> sets ZAI_API_KEY` |
|
||||
| `/srv/mosaic/.config/mosaic-dev/secrets/` | the Console's proof file, the path the args file's `--proof-file` names | 0600 or 0400 | mosaic | library | none. `case2-unit.sh` refuses at render. Precheck line missing. |
|
||||
| `/srv/mosaic/.config/mosaic-dev/secrets/<business>/` | `library-gitea` | 0600 | mosaic | library | C2-13b's `library.sync` (not landed) |
|
||||
| `/srv/mosaic/.config/mosaic-dev/secrets/agents/<business>/<agent>/` | one file per service | 0600, dirs 0700 | mosaic | both | none. Filled only by `mosaic credentials issue`, or Approve after #436. Never by hand. |
|
||||
|
||||
The installer key, `<configDir>/secrets/hosts/<business>/<hostId>/installer`, is not a slot anyone places.
|
||||
Enrollment (section 8) writes it under the enrolling stack's config directory and deletes it when the host
|
||||
leaves.
|
||||
|
||||
## 10. Console start
|
||||
|
||||
None by hand. I2's `case2-unit.sh` enables both units, starts the bus, then the Console (Q189, mos-1122).
|
||||
`stack-upgrade.sh` stops and starts both units itself.
|
||||
|
||||
Precheck line: none. Both units active after the render: precheck line missing.
|
||||
@@ -593,54 +593,6 @@ gate, along with every `scripts/test-*.sh`.
|
||||
|
||||
---
|
||||
|
||||
## C2-20b persona import follow-up: printed keys, the dry run fence check and the mkdir race
|
||||
|
||||
### Problem
|
||||
|
||||
Webby's round 1 review of row 221 (webby-0073, REVIEW-r1 a0a00630e on webby/reviews) approved it with
|
||||
four notes that don't block. Three are in `scripts/case2-persona-import.mjs` and go in before Jason's
|
||||
import run, because he runs the script once (sage-1941):
|
||||
- N1: lines :147 and :237 print channel and platform keys from `config.yaml` as they are. A key with a
|
||||
newline or a control character could forge an output line.
|
||||
- N2: the dry run counts but doesn't apply C2-08's 8000-char fence. A persona over the fence and under
|
||||
32000 bytes passes the dry run and then refuses at staging.
|
||||
- N4: `privateDir` runs lstat, then mkdir. A directory made between the two gives a raw EEXIST. It still
|
||||
fails closed, so only the error text is wrong.
|
||||
|
||||
N3 (Morgana's 213 `mutants.py:48` B3 pattern no longer matches `bundle.mjs`) isn't in this row. It's in
|
||||
DEFERRED.
|
||||
|
||||
### Owner and reviewer
|
||||
|
||||
- Owner: Gosalyn.
|
||||
- Reviewer: Webby.
|
||||
- After: row 221 (C2-20) lands.
|
||||
|
||||
### Files owned
|
||||
|
||||
`scripts/case2-persona-import.mjs`, `packages/cli/tests/case2-persona-import.test.mjs` and its fixture
|
||||
tree.
|
||||
|
||||
### What ships
|
||||
|
||||
- N1: every printed config key goes through `JSON.stringify`.
|
||||
- N2: the dry run calls `personaTextFault` on each persona and prints the fault's name. It still prints
|
||||
no persona text, no line and no line number.
|
||||
- N4: an EEXIST from the mkdir refuses with a named reason, not a raw EEXIST.
|
||||
|
||||
Tests:
|
||||
- A fixture key with a newline prints as one quoted line.
|
||||
- A persona over the fence makes the dry run print the fault, write nothing and exit nonzero.
|
||||
- The mkdir race refuses with the named reason. A stubbed mkdir that throws EEXIST is enough.
|
||||
- One mutant for each of the three fixes, each killed by its test.
|
||||
|
||||
### Gate
|
||||
|
||||
Webby approves the manifest. The test file runs green on its own, and the three mutants are killed on
|
||||
Sage's slot. The cli suite and every `scripts/test-*.sh` are green on Sage's gate.
|
||||
|
||||
---
|
||||
|
||||
## C2-03a fetch-only sync
|
||||
|
||||
### Problem
|
||||
@@ -675,10 +627,6 @@ Design 7.2's slice:
|
||||
- An `https://` URL only.
|
||||
- The served ref `refs/heads/served`, and `library-diverged`, held until a human `library.sync --accept
|
||||
<commit>`.
|
||||
- The mirror's `HEAD` is a symbolic ref to `refs/heads/served`, so `mosaic library survey <mirror>` reads
|
||||
the served commit. The survey reads `HEAD` and has no ref flag, and design 10 step 7 surveys this mirror
|
||||
(C2-12 run sheet; Sage, 2026-10-21). Test: after the first sync, `git symbolic-ref HEAD` in the mirror
|
||||
prints `refs/heads/served` and the survey's `commit` line equals the served commit.
|
||||
- The sync state file, written atomically inside the mirror, and the 60-second timer.
|
||||
- `library.sync`, human only. A test reaches a local bare repo only through the module parameter that
|
||||
replaces `syncCommand`.
|
||||
|
||||
@@ -106,18 +106,4 @@ X5). At start, after the grant reconcile, the bus unlinks every `host.<id>` key
|
||||
`host_grants` record (r6 N1, G27). It adds no schema step. If it needs one, Sage re-briefs it first and
|
||||
assigns the next free step (#436b holds 3j to 3k, row 206 3k to 3l).
|
||||
|
||||
Creative roles get no host grant (mos-1163, from Webby's N2 on row 213 r4). Since row 234, a role
|
||||
definition's credentials no longer gate host access, so the host grant writer itself refuses a grant whose
|
||||
agent is a `CREATIVE_DEFINITIONS` role (row 213), with a named reason and a test. The Case 2 hub runs
|
||||
creative agents on .54, and without this a creative role has a path to `host.run`. Duckworth's review checks
|
||||
it, and answers from the code whether a decision raised by another role can be spent by a creative one.
|
||||
|
||||
`host.run` refuses too, at spend time, when the agent's current definition is a `CREATIVE_DEFINITIONS` role
|
||||
(sage-1908, accepted in mos-1164). That covers a grant written before the role became creative. The refusal
|
||||
leaves the grant record in place, so `hosts.revoke` still finds it. Each path, the writer refusal at raise
|
||||
and at the step 1 recheck and the spend refusal, gets its own test and its own mutant.
|
||||
`CREATIVE_DEFINITIONS` comes from row 213, so row 213 lands before row b. If that order can't hold, Sage
|
||||
tells Mos before row b lands.
|
||||
|
||||
Gate: as row a, with section 10's row b tests and mutants, G27, G28 and the upsert mutant included, and
|
||||
the creative refusal tests and mutants (writer and spend).
|
||||
Gate: as row a, with section 10's row b tests and mutants, G27, G28 and the upsert mutant included.
|
||||
|
||||
@@ -64,31 +64,3 @@ mos-1081 item 1). No new provider account.
|
||||
Duckworth approves DESIGN.md, then the manifest. Any repository change is green on Sage's gate (cli suite and
|
||||
every `scripts/test-*.sh`), with the design's mutants killed. The row is done when the window's acceptance
|
||||
run passes on .53, Duckworth reads its output, and Mos confirms.
|
||||
|
||||
## Row 195 follow-up: Duckworth's N1-N3 on the Case 1 acceptance script
|
||||
|
||||
Sage, 2026-10-21. Row 195's code landed as b65014647. Duckworth's manifest notes N1-N3 (REVIEW-m1 6afcee2a5)
|
||||
are recorded in docs/plans/DEFERRED.md (d6cff0cdd). Owner Darkwing, reviewer Duckworth, gate owner Sage.
|
||||
|
||||
- N1: F9 runs the `--node` binary as root (`scripts/case1-accept.sh:298`) before F10 checks its path
|
||||
(:303-304). Root must never run a binary the script hasn't checked yet: run F9's parse as `AS_USER`, or move
|
||||
F10's path check ahead of it.
|
||||
- N2: the header (:10) and the TOOLS.md entry must list everything root runs, not just "reads".
|
||||
- N3: F6's prefix match (:261) must refuse a `--claude` path with `..` after `claude-<pin>/`.
|
||||
- Build on a new branch from the refactor tip, starting from Darkwing's `darkwing/row195-n1` 1e3c4767c. That
|
||||
commit hasn't been run.
|
||||
|
||||
Gate: Duckworth approves the manifest. The cli suite and every `scripts/test-*.sh` are green on Sage's gate,
|
||||
and a mutant for each of N1 and N3 is killed. This row lands before the .53 window row below.
|
||||
|
||||
## Row 195 window: the Case 1 acceptance run on 10.1.1.53
|
||||
|
||||
Sage, 2026-10-21. This row carries row 195's done condition from the Gate section above. Sage moved row 195
|
||||
to done at its code landing (rev 2790), which was early, and done rows can't change, so the condition
|
||||
continues here. Owner Darkwing, reviewer Duckworth, gate owner Sage. It waits on row 226 and on the N1-N3
|
||||
follow-up landing.
|
||||
|
||||
The window needs a Jason or Mos go. It takes a backup first where state exists and gives a STATE report
|
||||
after. The Boundaries above apply unchanged.
|
||||
|
||||
Gate: the window's acceptance run passes on .53, Duckworth reads its output, and Mos confirms.
|
||||
|
||||
@@ -256,21 +256,6 @@ r6 B2 as designed:
|
||||
|
||||
The I3 run sheet's hostcheck item points at this row. I3's A1 and its fake don't change.
|
||||
|
||||
### Carried from the I3 review (Filbert 29922 on #1735, sage-1727)
|
||||
|
||||
Row 233 lands with three non-blocking notes that must be fixed before ops-01. This row takes them, and that
|
||||
widens its paths to `scripts/stack-upgrade.sh` and `packages/cli/tests/stack-upgrade.test.mjs`:
|
||||
- N1: after A5 confirms, a failed rename of the new args file calls `finish 1 args-failed` while the new copy
|
||||
is live (`stack-upgrade.sh:280-282` at 1a1dc80ca). TOOLS.md and the run sheet define exit 1 as "the old copy
|
||||
runs". Give this case its own exit code, add it to the exit table in TOOLS.md and the run sheet, and add a
|
||||
test that makes the rename fail after A5 and expects the new code.
|
||||
- N4: run sheet section 3 doesn't put the pinned node's npm on root's PATH and doesn't name the `--claude`
|
||||
path. The npm symlink `node_modules/.bin/claude` is what `case2-unit.sh:140` refuses. The sheet must name
|
||||
the path the check accepts.
|
||||
- N5: run sheet sections 8 and 10 get their precheck lines.
|
||||
|
||||
Filbert's N2 and N3 (no `$REPO` check, no signal handling between A2 and A5) are in DEFERRED.md, not here.
|
||||
|
||||
### Gate
|
||||
|
||||
Filbert approves the manifest. The test file, the cli suite and every `scripts/test-*.sh` are green on
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
# Gate environment rows (2026-10-21)
|
||||
|
||||
Sage, from the row 197 lane proof that stopped on 2026-10-21 (sage-1881, mos-1162). Two small rows.
|
||||
Each lands after row 197.
|
||||
|
||||
## The startup token refusal test sets its file mode
|
||||
|
||||
`packages/bus/tests/process.test.mjs:76` writes the "too open" token file with
|
||||
`writeFileSync(file, secret, { mode: 0o644 })`, and `:82` expects the broker to refuse it.
|
||||
`writeFileSync` applies the process umask to that mode. Under `umask 077` the file is 0600,
|
||||
`packages/bus/src/credentials.mjs:205` accepts it, and the test fails. That happened in the row 197 lane
|
||||
proof, where `scripts/testing/gate-lane.sh:3` set 077 for the test steps.
|
||||
|
||||
- Change: the test calls `chmodSync(file, 0o644)` after the write, so its result no longer depends on the
|
||||
umask.
|
||||
- Sweep: look in `packages/*/tests` for other tests that expect a refusal of a too-open mode set
|
||||
through `writeFileSync` or `mkdirSync`, and fix those the same way. List what the sweep found in
|
||||
BUILD.md, including when it found none.
|
||||
- Test: run the file whole twice, once under `umask 022` and once under `umask 077`. Both runs pass.
|
||||
- Order: Mos ruled (mos-1162) that this lands after row 197 r6. Then r6's proof runs on the unchanged
|
||||
test, so it shows the umask fix itself works.
|
||||
|
||||
## Gate runs use a fixture pi auth file
|
||||
|
||||
The `docs/plans/DEFERRED.md` entry "Gate runs mount the host's pi auth file" (059577886, Webby N4 on the
|
||||
row 197 proof driver, traced by Herb in herb-0051) gets its own row here.
|
||||
|
||||
- Change: every gate step that reaches Compose gets a fixture `PI_AUTH_FILE`. That covers the
|
||||
`test-task.sh` cases that call `scripts/run-task.sh`, `test-release.sh` through `release.sh`
|
||||
`health_check`, and row 197's lane `cleanEnv` in `scripts/testing/gate-lane.mjs`. Either the suites
|
||||
or the lane's `cleanEnv` can set it.
|
||||
- Test: no gate step mounts the host default `/home/jwoltje/.pi/agent/auth.json`. The test reads
|
||||
the Compose arguments or the environment that each step passes. It does not read the host file.
|
||||
- Not in scope: `compose.yaml`'s default for real runs stays as it is.
|
||||
- At landing, the DEFERRED entry moves to Done with the landing commit.
|
||||
@@ -216,112 +216,6 @@ at every gate. Started 2026-09-12 during the control board MVP.
|
||||
READMEs, `docs/TOOLS.md` and Sage's suite recipe should use the glob
|
||||
form wherever Node 24 is a target. Darkwing, S1 packet. (2026-10-04,
|
||||
#1518)
|
||||
- **`stack-upgrade.sh` doesn't check `$REPO`.** Nothing confirms the
|
||||
source checkout is root-owned or that its tree is clean before the
|
||||
upgrade builds from it. Filbert N2 on row 233 (29922, #1735).
|
||||
(2026-10-21)
|
||||
- **`stack-upgrade.sh` has no signal handling between A2 and A5.** A HUP,
|
||||
INT or TERM in that stretch leaves the run failed closed, but recovery
|
||||
is by hand. A trap that writes the stop point and the recovery step to
|
||||
the log would make it a sheet step. Filbert N3 on row 233 (29922,
|
||||
#1735). (2026-10-21)
|
||||
- **`checkCreative` doesn't refuse `credentials`.** Row 213's
|
||||
`checkCreative` (packages/business/src/role.mjs:143 at 2d2ad2760)
|
||||
limits a creative role's tools, authority and messaging, but a role
|
||||
file that gave companion or research a credential would still load.
|
||||
The business file could then map a credential to that instance
|
||||
(business.mjs:157). Nobody has traced whether a mapped credential
|
||||
reaches the run's environment. The decision paths stay closed (M6),
|
||||
but a creative role with `web` holding a live token is a wider channel
|
||||
than design 4 means. The fix: refuse any `credentials` in
|
||||
`checkCreative`, with a role.test.mjs case. It goes after row 213
|
||||
lands, as a follow-up row or in the next row that edits role.mjs.
|
||||
Webby N1 on row 213 r3 (REVIEW-r3.md, 3ab3c010b), mos-1160.
|
||||
(2026-10-21)
|
||||
- **The boot host check orders only one business's bus.**
|
||||
`mosaic-hostcheck.service` (row 240) has
|
||||
`[email protected]`. `case2-unit.sh` enables the
|
||||
bus as `mosaic-bus@<business>.service`, so on a host whose business id
|
||||
isn't `mosaic-stack` nothing orders the two. The bus can start before
|
||||
the boot stop runs, and after a boot-time drift role sessions can use
|
||||
bwrap until it does. The fix: `After=mosaic-hostcheck.service` in
|
||||
`packages/cli/systemd/mosaic-bus.service.in`, which orders every
|
||||
instance and does nothing where the unit isn't installed. It goes in
|
||||
before the first install whose business id isn't `mosaic-stack`.
|
||||
Filbert N1 on row 240 (29945, #1746). (2026-10-21)
|
||||
- **The run sheet writes the apt hook before the first `--check`.**
|
||||
Section 4 installs `80mosaic-hostcheck`, then runs
|
||||
`hostcheck.sh --check`. If that check fails, the next package run
|
||||
closes bwrap before anyone has read the failure. It fails closed, but
|
||||
it surprises an installer. The fix: run `--check` first, or say what a
|
||||
failure at that step means. Doc-only, for the next row that edits
|
||||
`docs/guides/host-run-sheet.md`. Filbert N2 on row 240 (29945, #1746).
|
||||
Filbert's N3, that a closed bwrap appends to `DRIFT` on every later
|
||||
apt run and boot, is by design; ops-01's STATE read should expect the
|
||||
repeats. (2026-10-21)
|
||||
- **The sso-config first-step hint has no business.** When the target
|
||||
copy has no `console.sso`, `stack-release.sh` (`:938`) refuses with
|
||||
"activate $TO without --sso first, then ... activate $TO --sso". The
|
||||
usage line is `activate ID BUSINESS` (`:47`), so pasting either command
|
||||
as printed gives a usage error, not the first step. It fails safe,
|
||||
since the usage error changes nothing. The fix: add `$BUSINESS`
|
||||
(set at `:2138`) to both commands, and the business (`acme`)
|
||||
to the three expected strings in `stack-release.test.mjs`
|
||||
(`:1538`, `:1689`, `:1691`). For a later row that edits
|
||||
`stack-release.sh`. Webby N1 on row 238 r1 (REVIEW-r1.md, 433a95292,
|
||||
#1744). (2026-10-21)
|
||||
- **Gate runs mount the host's pi auth file.** `compose.yaml:43` mounts
|
||||
`${PI_AUTH_FILE:-/home/jwoltje/.pi/agent/auth.json}` read-only into
|
||||
the agent container. No suite sets `PI_AUTH_FILE`, so the
|
||||
`test-task.sh` cases that call `scripts/run-task.sh`, and
|
||||
`test-release.sh` through `release.sh` `health_check` (`:41-54`), run
|
||||
Compose with the host file. Row 197's lane `cleanEnv`
|
||||
(`scripts/testing/gate-lane.mjs:109`) keeps the default too: it neither
|
||||
sets nor passes `PI_AUTH_FILE`. The mount is read-only, and the legacy
|
||||
gate already worked this way before row 197. `test-auth.sh` uses its
|
||||
own fixtures but calls `auth.sh`, not Compose. The fix: a fixture
|
||||
`PI_AUTH_FILE` for the Compose-reaching cases, set by the suites or by
|
||||
the lane's `cleanEnv`, and a test that no gate step mounts the host
|
||||
default. It needs its own row. Webby N4 on the row 197 proof driver
|
||||
(bba870ee9), traced by Herb (herb-0051). (2026-10-21)
|
||||
- **Lane image prep inspects a base that BuildKit never tagged.**
|
||||
(N7 of the row 197 proof.) After the Compose build,
|
||||
`scripts/testing/lane-image.mjs:41` (`prepareImage`) runs
|
||||
`docker image inspect node:24-bookworm-slim` to put the base digest
|
||||
in the receipt. BuildKit resolves the base from the registry
|
||||
without tagging it in the local store, so on a host without the tag
|
||||
the inspect throws "No such image" after a good build. That
|
||||
happened in Sage's proof try 1 (2026-10-21 09:03Z, run cf48efccf083).
|
||||
The throw fails closed: the run's terminal record is unclean, both
|
||||
lanes quarantine, and `gate-lane.sh recover` clears them. Pulling the
|
||||
base first fixes it, and the receipt digest then matches what the
|
||||
build used (91acba91 both ways). The fix: before the build, inspect
|
||||
the base and refuse with a named reason if it's missing, or pull it.
|
||||
After the build, refuse if the base digest changed. Add a test with a
|
||||
fake Docker that has no base tag. Kept out of row 197 r6 by Sage
|
||||
(sage-1883). Mos asked for this record in mos-1162. (2026-10-21)
|
||||
- **Case 1 acceptance script: root parses with the node it's checking, and the header says less than root does.**
|
||||
(Duckworth N1-N3 on the row 195 manifest, REVIEW-m1 6afcee2a5.)
|
||||
N1: F9 runs `$ROOT$NODE` as root (`scripts/case1-accept.sh:298`)
|
||||
before F10 checks that `--node` is the `/opt/mosaic-stack/node-<pin>`
|
||||
path (:303-304). On a host installed as designed, `case2-unit.sh:128-133`
|
||||
refused a non-root-owned `--node` and the args file is root's, so no
|
||||
escalation path exists today. Run F9's parse through `AS_USER`, or
|
||||
apply F10's path check first. N2: the header (:10) and the TOOLS.md
|
||||
entry say root only reads, but root also runs `curl` (F2), `sudo -l`
|
||||
(P1, P3), the jarvis probe (P9), `hostcheck.sh --check` and
|
||||
`systemctl`. Doc-only. N3: F6's prefix match (:261) accepts a
|
||||
`--claude` with `..` after `claude-<pin>/`. That claude runs only as
|
||||
`mosaic`, and F10 uses equality. Darkwing has a follow-up on
|
||||
`darkwing/row195-n1` 1e3c4767c, not yet run; it gets its own row now
|
||||
that 195 has landed (b65014647), Duckworth reviews. (2026-10-21)
|
||||
- **Morgana's row 213 mutation set: the B3 pattern no longer matches `bundle.mjs`.**
|
||||
(Webby N3 on row 221 round 1, REVIEW-r1 a0a00630e.) Row 221's
|
||||
candidate changes `packages/harness/src/bundle.mjs`, and the B3
|
||||
anchor at Morgana's 213 `mutants.py:48` stops matching on that
|
||||
base. This matters only if someone reruns that set. Fix the anchor
|
||||
in that tooling before any rerun, and check that a stale anchor
|
||||
refuses instead of skipping the mutant (sage-1941). (2026-10-21)
|
||||
|
||||
## Queue
|
||||
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ Gaps found while working go to `docs/plans/DEFERRED.md`, not here.
|
||||
|
||||
<!-- mosaic-queue:begin -->
|
||||
|
||||
Generated from `docs/plans/queue.json` revision 2641 by `queue render`. Do not edit between the markers; change the queue with `scripts/mosaic queue`.
|
||||
Generated from `docs/plans/queue.json` revision 2638 by `queue render`. Do not edit between the markers; change the queue with `scripts/mosaic queue`.
|
||||
|
||||
| # | Piece | Owner | Issues | State | After | Gate | Brief | Note |
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
@@ -278,7 +278,7 @@ Generated from `docs/plans/queue.json` revision 2641 by `queue render`. Do not e
|
||||
| 239 | Row 194 follow-up: the credential revoke runs under the writer's lock, refusals after a revoke say so, and a stale-revision fire test (duckworth-0074, mos-1158) | honker; reviewers duckworth | #1745 | queued | 194 done | Duckworth approves the manifest. The bus, business, cli and webui suites and every scripts/test-*.sh are green on Sage's gate, and the mutants are killed. (sage) (sage) | `docs/plans/2026-10-20_agent-lifecycle.md` § Brief: row 194 follow-up, the revoke under the writer's lock and a fire test | — |
|
||||
| 240 | Installer I4: hostcheck, the bwrap profile check, pins and boot unit, from r6 B2 (MVP, Q187, Vikunja #432; split from I3) | darkwing; reviewers filbert | #1746 | queued | 233 done | Filbert approves the manifest. The test file, the cli suite and every scripts/test-*.sh are green on Sage's gate, with the mutants killed. (sage) (sage) | `docs/plans/2026-10-20_installer-rows.md` § I4 hostcheck: the bwrap profile check, pins and boot unit | — |
|
||||
| 241 | Row 237 follow-up: one decision lands once, a two-ticket broker land test and three mutants on the landing guards (megavolt-0069, sage-1651, P19 441) | megavolt; reviewers duckworth | #1747 | done | 237 done | Duckworth approves the manifest. The bus, seat and cli suites and every scripts/test-*.sh are green on Sage's gate, and the three mutants are killed. (sage) (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: row 237 follow-up, one decision lands once, with tests at the broker | Landed 5d4a61776 on refactor, pushed (base e65a3ab4d). Blobs from 3e3ed303e on 2 paths; patch-id a1649f80 equals git diff f5753c0e8..3e3ed303e on those paths; ls-tree modes equal; manifest e8266864 verifies on the landed files. Sage slot on bbf3b1ee8: M1-M3 killed; gate 15 packages 2797/0, 10 script suites 429/0. Duckworth approve 29870 rev 2628. |
|
||||
| 242 | Row 237 follow-up N1: a retry after publish-timeout pushes once; hold the decision or kill and wait for the push, a slow-push retry test and a mutant (duckworth-0069, P19 440) | megavolt; reviewers duckworth | #1748 | done | 237 done | Duckworth approves the manifest. The bus and cli suites and every scripts/test-*.sh are green on Sage's gate, and the mutant is killed. (sage) (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: row 237 follow-up N1, a retry after publish-timeout pushes once | Landed 5fb736b92 on refactor, pushed (base 96bac588f). Blobs from 635c10924 on 3 paths; patch-id ceb741ee equals git diff 8fede5fc6..635c10924 on those paths; ls-tree modes equal; manifest 1fbfab6c verifies on the landed files. Megavolt M1/M2 killed on Sage's slot; Sage gate 15 packages 2826/0, 10 script suites 429/0. Duckworth approve 29889 rev 2639. |
|
||||
| 242 | Row 237 follow-up N1: a retry after publish-timeout pushes once; hold the decision or kill and wait for the push, a slow-push retry test and a mutant (duckworth-0069, P19 440) | megavolt; reviewers duckworth | #1748 | in-review, round 1, request posted | 237 done | Duckworth approves the manifest. The bus and cli suites and every scripts/test-*.sh are green on Sage's gate, and the mutant is killed. (sage) (sage) | `docs/plans/2026-10-20_agent-credentials.md` § Brief: row 237 follow-up N1, a retry after publish-timeout pushes once | — |
|
||||
|
||||
<!-- mosaic-queue:end -->
|
||||
|
||||
|
||||
+9
-80
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": 1,
|
||||
"canonicalRoot": "/mnt/storage/src/mosaic-stack",
|
||||
"revision": 2641,
|
||||
"revision": 2638,
|
||||
"rows": [
|
||||
{
|
||||
"id": 1,
|
||||
@@ -23277,7 +23277,7 @@
|
||||
"closes": [
|
||||
1748
|
||||
],
|
||||
"state": "done",
|
||||
"state": "in-review",
|
||||
"previousState": null,
|
||||
"required": false,
|
||||
"requiredSince": null,
|
||||
@@ -23342,24 +23342,18 @@
|
||||
}
|
||||
],
|
||||
"duplicateRisk": false,
|
||||
"receipts": [
|
||||
{
|
||||
"reviewer": "duckworth",
|
||||
"op": "duckworth-r242-record-1",
|
||||
"at": "2026-10-21T03:48:36.391Z",
|
||||
"verdict": "approve",
|
||||
"comment": 29889,
|
||||
"candidate": "1fbfab6c68e8d76d2d69b13c415257280d4fa8c5584e24d5dfd13dca1420a3da"
|
||||
}
|
||||
]
|
||||
"receipts": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"claim": null,
|
||||
"note": "Landed 5fb736b92 on refactor, pushed (base 96bac588f). Blobs from 635c10924 on 3 paths; patch-id ceb741ee equals git diff 8fede5fc6..635c10924 on those paths; ls-tree modes equal; manifest 1fbfab6c verifies on the landed files. Megavolt M1/M2 killed on Sage's slot; Sage gate 15 packages 2826/0, 10 script suites 429/0. Duckworth approve 29889 rev 2639.",
|
||||
"claim": {
|
||||
"seat": "megavolt",
|
||||
"op": "megavolt-242-start-1"
|
||||
},
|
||||
"note": null,
|
||||
"blockedReason": null,
|
||||
"createdAt": "2026-10-21T01:54:53.103Z",
|
||||
"updatedAt": "2026-10-21T04:13:55.780Z",
|
||||
"updatedAt": "2026-10-21T03:46:05.721Z",
|
||||
"updatedBy": "sage"
|
||||
}
|
||||
],
|
||||
@@ -93279,71 +93273,6 @@
|
||||
"receipt": "ok sage-242-request-1.outcome rev 2638 row 242 round 1 request sage-242-request-1 posted comment 29888"
|
||||
},
|
||||
"viewSha": "d7bf764deb95140e4b2748863b838f5598f57162a0388adcfb24b4ca6cb90449"
|
||||
},
|
||||
{
|
||||
"rev": 2639,
|
||||
"op": "duckworth-r242-record-1",
|
||||
"verb": "review-record",
|
||||
"args": {
|
||||
"id": 242,
|
||||
"verdict": "approve",
|
||||
"comment": 29889,
|
||||
"candidate": "1fbfab6c68e8d76d2d69b13c415257280d4fa8c5584e24d5dfd13dca1420a3da"
|
||||
},
|
||||
"by": "duckworth",
|
||||
"at": "2026-10-21T03:48:36.391Z",
|
||||
"semantics": 2,
|
||||
"result": {
|
||||
"row": 242,
|
||||
"round": 1,
|
||||
"verdict": "approve",
|
||||
"receipt": "ok duckworth-r242-record-1 rev 2639 row 242 round 1 approve by duckworth (comment 29889)"
|
||||
},
|
||||
"viewSha": "80ea9e552b2edb1937fce5ff23bc6cf9b6b9e2381cbb2e5808d7c87acf3d4b45"
|
||||
},
|
||||
{
|
||||
"rev": 2640,
|
||||
"op": "sage-242-landed-note",
|
||||
"verb": "note",
|
||||
"args": {
|
||||
"id": 242,
|
||||
"text": "Landed 5fb736b92 on refactor, pushed (base 96bac588f). Blobs from 635c10924 on 3 paths; patch-id ceb741ee equals git diff 8fede5fc6..635c10924 on those paths; ls-tree modes equal; manifest 1fbfab6c verifies on the landed files. Megavolt M1/M2 killed on Sage's slot; Sage gate 15 packages 2826/0, 10 script suites 429/0. Duckworth approve 29889 rev 2639."
|
||||
},
|
||||
"by": "sage",
|
||||
"at": "2026-10-21T04:13:30.071Z",
|
||||
"semantics": 2,
|
||||
"result": {
|
||||
"row": 242,
|
||||
"field": "note",
|
||||
"receipt": "ok sage-242-landed-note rev 2640 row 242 note"
|
||||
},
|
||||
"viewSha": "b0997e13a14bd17120aef27778c84deacdb08149688d0399e035fb8bc365bc37"
|
||||
},
|
||||
{
|
||||
"rev": 2641,
|
||||
"op": "sage-242-done",
|
||||
"verb": "move",
|
||||
"args": {
|
||||
"id": 242,
|
||||
"to": "done",
|
||||
"reason": null,
|
||||
"candidate": null,
|
||||
"evidence": null,
|
||||
"issue": null
|
||||
},
|
||||
"by": "sage",
|
||||
"at": "2026-10-21T04:13:55.780Z",
|
||||
"semantics": 2,
|
||||
"result": {
|
||||
"row": 242,
|
||||
"from": "in-review",
|
||||
"to": "done",
|
||||
"round": 1,
|
||||
"issue": null,
|
||||
"candidate": null,
|
||||
"receipt": "ok sage-242-done rev 2641 row 242 in-review→done round 1"
|
||||
},
|
||||
"viewSha": "418b83170fd6c8ba7aa577b935f802b3a5dfead59be2260b11115206f324abbc"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Generated
+1
-2
@@ -10,8 +10,7 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-coding-agent": "0.85.1",
|
||||
"oauth4webapi": "3.8.8",
|
||||
"yaml": "2.9.0"
|
||||
"oauth4webapi": "3.8.8"
|
||||
}
|
||||
},
|
||||
"node_modules/@anthropic-ai/sdk": {
|
||||
|
||||
+1
-2
@@ -6,7 +6,6 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-coding-agent": "0.85.1",
|
||||
"oauth4webapi": "3.8.8",
|
||||
"yaml": "2.9.0"
|
||||
"oauth4webapi": "3.8.8"
|
||||
}
|
||||
}
|
||||
|
||||
+4
-17
@@ -218,11 +218,6 @@ an operator inspect content and delivery evidence after an uncertain result.
|
||||
| `credentials.issue` | `{agent,service,token,date}`; human only (row 199, #1697). Writes the token to `<configDir>/secrets/agents/<business>/<agent>/<service>` (0600, dirs 0700: tmp, fsync, rename), rewrites the agent's reference in the business file to `{"store":true,<rotateBy or expires>:date}`, then holds the token in memory, with no restart. Over an issued entry it is a rotate: the old value is gone from disk and memory when it returns. `service` is `gitea` or `vikunja` and the business file must already name it for the agent (`credential-unknown`). A token the bus already holds is `credential-leak`; a bad token `credential-format`; a bad date `credential-date`. Returns `{agent,verb,service,date,state}`, `verb` `issue` or `rotate`. The tester gets `tester-refused`. |
|
||||
| `credentials.revoke` | `{agent,service?,reason}`; human, or the tester (Q173). Drops the entry from memory, then unlinks a store file; a `file` or `env` reference keeps its file and becomes `store`, so a restart loads nothing. Without `service`, every kind the agent has. Returns `{agent,verb,services:[{service,state}]}`. |
|
||||
| `credentials.delete` | `{agent,reason}`; human only. `credentials.revoke` for every kind, then removes the agent's store dir; a file there other than a token is `credential-file`. While the agent or one of its threads holds a claim, `agent-running`. |
|
||||
| `hosts.status` | No args; the human, the tester or the business's chief (row 234, #1740). `[{host,address,port,user,sudo,state,hostKeys,installerFingerprint,checkedAt,hostLineLeft,revoking}]` from the `hosts` records, with host keys as fingerprints. Never a key. |
|
||||
| `hosts.check` | `{host}`; same callers. Runs the host's `list <user>` as `mosaic-installer` with the installer key and the pinned host keys, then sets `state` `ready` and `checkedAt` and writes `grant.host.checked`. A nonzero exit is `host-failed`, a record that changed during the run `host-changed`, a record with no installer key `host-not-enrolled`. |
|
||||
| `hosts.remove` | `{host}`; the human or the tester. Deletes the record, writes `grant.host.removed` and removes the installer key. A `host_grants` record for the host is `host-in-use`, a guarded event naming a host line left on the host `host-line-left`. |
|
||||
| `hosts.revoke` | `{agent,host,reason}`; the human, the business's assistant, or the tester when `bus.tester` is exactly `true` (row 235, #1741, r6 section 6). Anyone else gets `revoke-refused`. The tester check reads `bus.tester` again at the call, `tester-dev-only`. One transaction deletes the `host_grants` record and writes `grant.revoked` with `hostLine:"pending"`. With no await between, the key leaves memory and its file goes, and a `host.run` or executor in flight aborts. Then `remove <user> <tag>` runs on the host and `grant.revoke.closed` records `hostLine:"removed"` or `hostLineLeft`. A revoke with no record still runs, with `granted:false`. Returns `{agent,host,tag,granted,keyFile,hostLine or hostLineLeft}`. A restart with a pending marker runs the remove once the bus is up; `hosts.status` lists its tag under `revoking`. |
|
||||
| `hosts.sweep` | `{host}`; the human or the tester (r6 X3). Runs `list <user>` and removes each listed tag this business recorded for the host in a `grant.step` or `grant.revoked` that no live grant holds. Another business's line and an unrecorded `mosaic-` line stay. Writes `grant.host.swept {host,removed,left}`; `hostLineLeft` then counts from it. Returns `{host,removed,hostLineLeft}`. |
|
||||
|
||||
Each of the three leaves one receipt in the organization's `changes.jsonl`: the actor and a
|
||||
`detail` of `{verb,agent,kind,date or reason}`, never a value. A change to the store alone writes
|
||||
@@ -709,10 +704,10 @@ scope probes and rotation/expiry notifications; S2 never probes real services.
|
||||
|
||||
## Schema and verification
|
||||
|
||||
`schema.sql` is v3j, SHA-256
|
||||
`0a7b633ce7eec9d0bb37c3255f4244d97bd0c8eac38db91a11b4ef6cc982ec8c`.
|
||||
It has 18 tables, 72 triggers and five views. Source digest and a trusted full
|
||||
sqlite_master digest are checked at open, alongside schema version `3j`, WAL,
|
||||
`schema.sql` is v3i, SHA-256
|
||||
`6cde5232c57ac04dc6073112c0830c89cfc5e953d7a5727e7716263747fe8737`.
|
||||
It has 16 tables, 71 triggers and five views. Source digest and a trusted full
|
||||
sqlite_master digest are checked at open, alongside schema version `3i`, WAL,
|
||||
quick_check and foreign-key integrity. Missing metadata refuses; it never
|
||||
reinitializes an existing file. Full synchronous WAL transactions either commit
|
||||
or roll back. SQL UPDATE, DELETE and INSERT OR REPLACE refuse on evidence tables.
|
||||
@@ -872,14 +867,6 @@ one transaction; a failure leaves the store at 3h. It runs only through
|
||||
refuses a 3i store. The 3h fixture, `tests/fixtures/schema-3h.sql`, is pinned from
|
||||
81f26551b's tree; no live store is used.
|
||||
|
||||
Schema 3j (row 234, #1740) adds only new objects: the `hosts` and `host_grants` tables, which
|
||||
hold enrolled hosts and host grants, and the `events_grant_actor` trigger. The trigger refuses an
|
||||
`action.allowed` event whose `body.action` or `body.operation` matches `grant.*` unless its actor
|
||||
is `actor_role` NULL with `actor_run` 'grant', the broker's grant writer (#436b section 7). The
|
||||
step runs in one transaction, and a failure leaves the store at 3i. The 3i fixture,
|
||||
`tests/fixtures/schema-3i.sql`, is pinned from 8fede5fc6's tree, and `tests/grant-migration.test.mjs`
|
||||
covers the step and the trigger.
|
||||
|
||||
The managed runner calls usage.begin before an actual harness turn and usage.end
|
||||
after it, including a failed/stopped turn. Each takes only {turn: deliveredMessageId}.
|
||||
The broker requires the bound role holder and its delivery, binds run identity,
|
||||
|
||||
@@ -363,34 +363,3 @@ CREATE TABLE usage_records (
|
||||
CREATE TRIGGER usage_records_no_update BEFORE UPDATE ON usage_records BEGIN SELECT RAISE(ABORT, 'usage_records is append-only'); END;
|
||||
CREATE TRIGGER usage_records_no_delete BEFORE DELETE ON usage_records BEGIN SELECT RAISE(ABORT, 'usage_records is append-only'); END;
|
||||
CREATE TRIGGER usage_records_no_replace BEFORE INSERT ON usage_records WHEN EXISTS (SELECT 1 FROM usage_records WHERE seq=NEW.seq OR (business=NEW.business AND run=NEW.run AND turn=NEW.turn AND source=NEW.source AND phase=NEW.phase)) BEGIN SELECT RAISE(ABORT, 'usage_records is append-only'); END;
|
||||
CREATE TABLE hosts (
|
||||
business TEXT NOT NULL,
|
||||
host TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
port INTEGER NOT NULL CHECK (port BETWEEN 1 AND 65535),
|
||||
user TEXT NOT NULL,
|
||||
sudo INTEGER NOT NULL CHECK (sudo IN (0,1)),
|
||||
host_keys TEXT NOT NULL CHECK (json_valid(host_keys) AND json_type(host_keys) = 'array' AND json_array_length(host_keys) > 0),
|
||||
installer_fingerprint TEXT,
|
||||
state TEXT NOT NULL CHECK (state IN ('pending-install','ready')),
|
||||
decision TEXT NOT NULL REFERENCES decisions(id),
|
||||
checked_at TEXT,
|
||||
PRIMARY KEY (business, host),
|
||||
CHECK (state = 'pending-install' OR (installer_fingerprint IS NOT NULL AND checked_at IS NOT NULL))
|
||||
) STRICT;
|
||||
CREATE TABLE host_grants (
|
||||
business TEXT NOT NULL,
|
||||
agent TEXT NOT NULL,
|
||||
host TEXT NOT NULL,
|
||||
commands TEXT NOT NULL CHECK (json_valid(commands) AND json_type(commands) = 'array' AND json_array_length(commands) > 0),
|
||||
rotate_by TEXT NOT NULL,
|
||||
tag TEXT NOT NULL CHECK (length(tag) = 39 AND tag GLOB 'mosaic-*' AND NOT substr(tag, 8) GLOB '*[^0-9a-f]*'),
|
||||
decision TEXT NOT NULL REFERENCES decisions(id),
|
||||
PRIMARY KEY (business, agent, host),
|
||||
FOREIGN KEY (business, host) REFERENCES hosts(business, host)
|
||||
) STRICT;
|
||||
CREATE TRIGGER events_grant_actor BEFORE INSERT ON events
|
||||
WHEN NEW.kind = 'action.allowed'
|
||||
AND (json_extract(NEW.body, '$.action') GLOB 'grant.*' OR json_extract(NEW.body, '$.operation') GLOB 'grant.*')
|
||||
AND NOT (NEW.actor_role IS NULL AND NEW.actor_run IS 'grant')
|
||||
BEGIN SELECT RAISE(ABORT, 'only the grant writer records grant events'); END;
|
||||
|
||||
+17
-836
@@ -3,7 +3,7 @@ import { isAbsolute } from 'node:path';
|
||||
import { NAME as HARNESS_NAME } from '../../plugins/src/kinds.mjs';
|
||||
import { loadRequirements } from '../../tasks/src/requirements.mjs';
|
||||
import { MERGE, LandingRefusal, readLanding } from './landing.mjs';
|
||||
import { ID_PATTERN, THREAD_DEFINITION, END_PROTECTED, forkProblem, forkUrl, credentialKind, validArgv, commandAllowed, HOST_ID, CREATIVE_DEFINITIONS } from '../../business/src/vocabulary.mjs';
|
||||
import { ID_PATTERN, THREAD_DEFINITION, END_PROTECTED, forkProblem, forkUrl, credentialKind, validArgv, commandAllowed } from '../../business/src/vocabulary.mjs';
|
||||
|
||||
// Kept closed while S1 lands; its vocabulary is the integration authority.
|
||||
export const ACTIONS = Object.freeze([
|
||||
@@ -182,64 +182,6 @@ const STAFF_COUNT = 20;
|
||||
// Row 93 (#1587): the review loop's evidence, written only by the verbs below. A push is an
|
||||
// action.allowed for git.push.working that names its commit, written only by recordPush.
|
||||
const REVIEW_KINDS = ['review.requested', 'review.verdict'];
|
||||
// Row 234 (#1740, #436b section 7): grant evidence is an action.allowed whose body.action or
|
||||
// body.operation starts with grant., written only by #grantEvent under this actor. No session has a
|
||||
// NULL role with a non-NULL run, and the 3j trigger refuses any other actor.
|
||||
const GRANT_RUN = 'grant';
|
||||
const grantName = (body) => [body?.action, body?.operation].some(n => typeof n === 'string' && n.startsWith('grant.'));
|
||||
// Every grant-evidence read filters on this (duckworth-0067 N1): a look-alike under another kind or
|
||||
// actor is not evidence.
|
||||
const GRANT_EVIDENCE = "kind='action.allowed' AND actor_role IS NULL AND actor_run='grant'";
|
||||
// r6 R4: the host record's identity, hashed at raise and at each later check.
|
||||
export const registrySha256 = ({ address, port, user, sudo, hostKeys }) =>
|
||||
createHash('sha256').update(JSON.stringify({ address, port, user, sudo: !!sudo, hostKeys })).digest('hex');
|
||||
// Row 234 (#1740, #436b section 7): the one writer of grant evidence, session-less, as actor (NULL,
|
||||
// 'grant'). The broker's #grantEvent calls it after its secret check, and the tests write their fixtures
|
||||
// through it (duckworth-0079 F1). No verb reaches it. Only the consume record {operation, decision}
|
||||
// names the decision as `decision`, so #spent counts it and nothing else. Every other body has a
|
||||
// grant.* action, names the decision grantDecision, and body.by names the caller the broker checked.
|
||||
export function writeGrantEvent(store, at, business, body, subject = null) {
|
||||
const consume = body?.operation !== undefined;
|
||||
if (
|
||||
!grantName(body) ||
|
||||
(consume
|
||||
? Object.keys(body).length !== 2 || typeof body.decision !== 'string' || !body.operation.startsWith('grant.')
|
||||
: typeof body.action !== 'string' || !body.action.startsWith('grant.') || 'decision' in body)
|
||||
)
|
||||
throw new Error('grant event shape');
|
||||
const eid = randomUUID();
|
||||
store.run(
|
||||
'INSERT INTO events(id,at,business,kind,actor_role,actor_run,subject,body) VALUES(?,?,?,?,?,?,?,?)',
|
||||
eid,
|
||||
at,
|
||||
business,
|
||||
'action.allowed',
|
||||
null,
|
||||
GRANT_RUN,
|
||||
subject,
|
||||
JSON.stringify(body),
|
||||
);
|
||||
return eid;
|
||||
}
|
||||
export const HOSTS_VERBS = Object.freeze(['hosts.status', 'hosts.check', 'hosts.remove', 'hosts.revoke', 'hosts.sweep']);
|
||||
// The OpenSSH fingerprint of a "<type> <base64>" host key line. host-grant.mjs has the same; the broker
|
||||
// doesn't import it, so the sandbox's RUNNER_FILES stay as they are.
|
||||
const fingerprintOf = (line) =>
|
||||
'SHA256:' + createHash('sha256').update(Buffer.from(line.split(' ')[1], 'base64')).digest('base64').replace(/=+$/, '');
|
||||
// Row 234 (#1740, r6 E1): an enrollment's raise binding. The human sees each scanned key with its
|
||||
// fingerprint, and the sudo mark in plain words.
|
||||
const enrollBinding = (enroll) => ({
|
||||
body: enroll,
|
||||
block:
|
||||
`\n\nEnroll host ${enroll.host}: user ${enroll.user} at ${enroll.address} port ${enroll.port}.` +
|
||||
`\nHost keys from ssh-keyscan, equal to the requested fingerprints:` +
|
||||
enroll.hostKeys.map((k) => `\n${fingerprintOf(k)} ${k}`).join('') +
|
||||
(enroll.sudo
|
||||
? `\n${enroll.user} has sudo on this host. Approving lets later grants for ${enroll.user} be installed, and section 9's first limit applies to ${enroll.user}.`
|
||||
: `\n${enroll.user} has no sudo on this host.`),
|
||||
});
|
||||
// r6 E3: the installer line's comment, then the tag's 32 hex digits.
|
||||
const INSTALLER_COMMENT = 'mosaic-installer-';
|
||||
// Row 121 (#1615): an instance of THREAD_DEFINITION (vocabulary.mjs since row 155) talks with the
|
||||
// user in threads. Its runs claim a thread, not the role, and every message to or from it names its
|
||||
// thread (REQ-MSG-1).
|
||||
@@ -282,19 +224,11 @@ export class Broker {
|
||||
#usage;
|
||||
#limits;
|
||||
#harnessOn;
|
||||
// Row 234 (#1740): the trusted enrollment half (host-grant.mjs), or null where hosts are off.
|
||||
#hostGrant;
|
||||
// Row 235 (#1741, r6 X2 to X5): grantKeys from host-grant.mjs, the executor's calls on Credentials, or null.
|
||||
#hostKeys;
|
||||
// r6 X3: interrupted host grants whose remote undo waits for reconcileHosts, each with its claim.
|
||||
#hostUndo = [];
|
||||
// r6 section 6 (N4): revokes a restart cut short, whose step 3 waits for reconcileHosts.
|
||||
#revokeUndo = [];
|
||||
// Row 125 (#1619, REQ-LIMIT-4): a run a limit stops, by business:run, until its next receive or state.
|
||||
#stops = new Map();
|
||||
#clock = 0;
|
||||
// credentialStatus is the runtime's metadata-only Credentials.status(); the broker never gets use().
|
||||
constructor({ store, businesses, secretCheck = () => {}, credentialStatus = () => [], organization = null, project = null, usage = null, limits = null, harnessOn = null, credentialVerbs = null, hostGrant = null, hostKeys = null }) {
|
||||
constructor({ store, businesses, secretCheck = () => {}, credentialStatus = () => [], organization = null, project = null, usage = null, limits = null, harnessOn = null, credentialVerbs = null }) {
|
||||
if (!object(businesses) || !Object.keys(businesses).length) fail('invalid-business');
|
||||
this.#businesses = structuredClone(businesses);
|
||||
this.#store = store;
|
||||
@@ -303,8 +237,6 @@ export class Broker {
|
||||
this.#organization = organization;
|
||||
// Row 199: the runtime's credential lifecycle (credential-verbs.mjs); it holds the store, not the broker.
|
||||
this.#credentialVerbs = credentialVerbs;
|
||||
this.#hostGrant = hostGrant;
|
||||
this.#hostKeys = hostKeys;
|
||||
this.#project = project;
|
||||
this.#usage = usage;
|
||||
this.#limits = limits;
|
||||
@@ -672,743 +604,9 @@ export class Broker {
|
||||
);
|
||||
return eid;
|
||||
}
|
||||
// Row 234 (#1740): grant evidence, through writeGrantEvent. Caller owns the transaction.
|
||||
#grantEvent(business, body, subject = null) {
|
||||
this.#secretCheck({ kind: 'action.allowed', body, subject });
|
||||
return writeGrantEvent(this.#store, this.#now(), business, body, subject);
|
||||
}
|
||||
// PRD 1.6 REQ-WAIT-1: a hard wait goes to the human at every class, cited or not. Jason's ruling
|
||||
// Q169 makes a role.revoke whose target's definition is in END_PROTECTED one, so no arbiter
|
||||
// resolves a revoke of the assistant.
|
||||
// Row 234 (#1740, r6 X1): the raise's grant binding, if the human's cli resolve chose its approval
|
||||
// option on a credential.mint routed to the human. Null otherwise: an arbiter, the tester or an agent
|
||||
// closes with via 'broker'.
|
||||
#approvedGrant(business, decision) {
|
||||
const d = this.#store.get('SELECT action,route_to FROM decisions WHERE business=? AND id=?', business, decision);
|
||||
const raise = this.#raised(business, decision);
|
||||
if (d?.action !== 'credential.mint' || d.route_to !== 'human' || !raise?.grant) return null;
|
||||
const r = this.#closed(decision);
|
||||
if (r?.op !== 'resolved' || r.choice !== raise.approvalChoice || r.via !== 'cli' || r.by !== this.#business(business).human)
|
||||
return null;
|
||||
return raise.grant;
|
||||
}
|
||||
// r6 X1: the executor's own spend. The caller owns the transaction. The consume record is the only
|
||||
// guarded body with `decision` (#436b section 7), so #spent counts it.
|
||||
#consumeGrant(business, decision, method) {
|
||||
const grant = this.#approvedGrant(business, decision);
|
||||
if (grant?.method !== method) fail('not-authorized');
|
||||
if (this.#spent(business, decision)) fail('decision-consumed');
|
||||
this.#grantEvent(business, { operation: 'grant.' + method, decision }, decision);
|
||||
return grant;
|
||||
}
|
||||
#hostRecord(business, host) {
|
||||
const r = this.#store.get('SELECT * FROM hosts WHERE business=? AND host=?', business, host);
|
||||
return r && { ...r, sudo: r.sudo === 1, hostKeys: JSON.parse(r.host_keys) };
|
||||
}
|
||||
// r6 X4 first bullet, the Approve record check: the host record and the session's grant record, whose
|
||||
// decision is a credential.mint with a `host` grant, resolved yes by the human via cli and spent by
|
||||
// #consumeGrant as grant.host. Read at each call, so a grant, a revoke and a hosts.remove need no reload.
|
||||
#hostAccess(s, host) {
|
||||
// mos-1164 (sage-1908): a creative role has no path to host.run, even through a record written before
|
||||
// its instance became creative. The record stays, so hosts.revoke still finds it.
|
||||
if (CREATIVE_DEFINITIONS.includes(this.#business(s.business).roles[s.role]?.definition)) fail('host-creative-role');
|
||||
const r = this.#hostRecord(s.business, host);
|
||||
if (!r) fail('host-unknown');
|
||||
const g = this.#store.get('SELECT * FROM host_grants WHERE business=? AND agent=? AND host=?', s.business, s.role, host);
|
||||
const spent = g && this.#store.get(
|
||||
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.operation')='grant.host' AND json_extract(body,'$.decision')=? LIMIT 1`,
|
||||
s.business,
|
||||
g.decision,
|
||||
);
|
||||
// The grant must name this agent and host too, so one approval can't stand behind another record.
|
||||
const grant = spent && this.#approvedGrant(s.business, g.decision);
|
||||
if (grant?.method !== 'host' || grant.agent !== s.role || grant.host !== host) fail('host-not-granted');
|
||||
return { entry: { address: r.address, port: r.port, user: r.user, hostKeys: r.hostKeys }, commands: JSON.parse(g.commands) };
|
||||
}
|
||||
// A grant outcome, from the bus, to the human's inbox and to the raising role, threaded as a
|
||||
// close is.
|
||||
#grantNotice(business, decision, body) {
|
||||
const d = this.#store.get('SELECT raised_by_role,raised_by_run FROM decisions WHERE id=?', decision);
|
||||
const thread = this.#threaded(business, d.raised_by_role)
|
||||
? (this.#store.get(
|
||||
"SELECT thread FROM thread_claims WHERE business=? AND holder_run=? AND op='claim' ORDER BY seq DESC LIMIT 1",
|
||||
business,
|
||||
d.raised_by_run,
|
||||
)?.thread ?? null)
|
||||
: null;
|
||||
for (const [to, t] of [['human', null], [d.raised_by_role, thread]]) {
|
||||
const mid = randomUUID();
|
||||
this.#store.run(
|
||||
'INSERT INTO messages(id,at,business,from_role,from_run,to_role,class,in_reply_to,decision,corrects,body) VALUES(?,?,?,?,?,?,?,?,?,?,?)',
|
||||
mid,
|
||||
this.#now(),
|
||||
business,
|
||||
NOTICE_ROLE,
|
||||
NOTICE_RUN,
|
||||
to,
|
||||
'RESULT',
|
||||
null,
|
||||
decision,
|
||||
null,
|
||||
body,
|
||||
);
|
||||
this.#route(business, mid, to, t);
|
||||
}
|
||||
}
|
||||
#enrollFailed(business, decision, host, code, extra = {}) {
|
||||
this.#store.run('DELETE FROM hosts WHERE business=? AND host=? AND decision=?', business, host, decision);
|
||||
this.#grantEvent(business, { action: 'grant.failed', grantDecision: decision, host, code, ...extra }, host);
|
||||
this.#grantNotice(business, decision, `Enrollment of host ${host} (decision ${decision}) failed: ${code}.`);
|
||||
}
|
||||
// Trusted host API, as reconcileGrants is, and no verb reaches it: the executor's entry for one
|
||||
// decision. Step 1 checks everything again, so a second start for a spent decision ends
|
||||
// decision-consumed, and an unresolved or agent-resolved one ends not-authorized, with nothing
|
||||
// written (r6 G10).
|
||||
runEnrollment(business, decision) {
|
||||
return this.#runEnrollment(business, decision);
|
||||
}
|
||||
// r6 E2, started by the human's cli yes. Never throws: the outcome is in the store and the notices,
|
||||
// and the return value is its code, 'enrolled' or the refusal.
|
||||
async #runEnrollment(business, decision) {
|
||||
let grant;
|
||||
try {
|
||||
// Step 1, one transaction: spend, the not-enrolled check, the registry step and the record.
|
||||
grant = this.#store.transaction(() => {
|
||||
const g = this.#consumeGrant(business, decision, 'host-enroll');
|
||||
if (this.#hostRecord(business, g.host)) {
|
||||
this.#grantEvent(business, { action: 'grant.failed', grantDecision: decision, host: g.host, code: 'host-enrolled' }, g.host);
|
||||
this.#grantNotice(business, decision, `Enrollment of host ${g.host} (decision ${decision}) failed: host-enrolled.`);
|
||||
return null;
|
||||
}
|
||||
this.#grantEvent(business, { action: 'grant.host.enroll.step', grantDecision: decision, host: g.host, step: 'registry' }, g.host);
|
||||
this.#store.run(
|
||||
'INSERT INTO hosts(business,host,address,port,user,sudo,host_keys,installer_fingerprint,state,decision,checked_at) VALUES(?,?,?,?,?,?,?,?,?,?,?)',
|
||||
business, g.host, g.address, g.port, g.user, Number(g.sudo), JSON.stringify(g.hostKeys), null, 'pending-install', decision, null,
|
||||
);
|
||||
return g;
|
||||
});
|
||||
} catch (e) {
|
||||
// Spent, not approved or no store: nothing was written. The start reconcile ends a resolved,
|
||||
// unspent decision.
|
||||
return e instanceof BusError ? e.code : 'host-failed';
|
||||
}
|
||||
if (!grant) return 'host-enrolled';
|
||||
const host = grant.host;
|
||||
try {
|
||||
if (!this.#hostGrant) fail('host-not-configured');
|
||||
// Steps 2 and 3: the key pair, and the private half to its file.
|
||||
const key = await this.#hostGrant.enroll(business, host);
|
||||
// Step 4.
|
||||
this.#store.transaction(() => {
|
||||
const r = this.#hostRecord(business, host);
|
||||
if (r?.decision !== decision) fail('host-changed');
|
||||
this.#store.run('UPDATE hosts SET installer_fingerprint=? WHERE business=? AND host=?', key.fingerprint, business, host);
|
||||
this.#grantEvent(
|
||||
business,
|
||||
{
|
||||
action: 'grant.host.enrolled',
|
||||
grantDecision: decision,
|
||||
host,
|
||||
registrySha256: registrySha256(r),
|
||||
installerFingerprint: key.fingerprint,
|
||||
user: r.user,
|
||||
sudo: r.sudo,
|
||||
},
|
||||
host,
|
||||
);
|
||||
this.#grantNotice(
|
||||
business,
|
||||
decision,
|
||||
`Host ${host} is enrolled (decision ${decision}) and pending install. ops-01 writes this line to ` +
|
||||
`/etc/ssh/mosaic-keys/mosaic-installer, with <from> the value in /etc/mosaic-keys/from:\n` +
|
||||
`restrict,command="/usr/local/sbin/mosaic-keys",from="<from>" ${key.publicLine} ` +
|
||||
`${INSTALLER_COMMENT}${key.tag.slice('mosaic-'.length)}\n` +
|
||||
`/etc/mosaic-keys/users lists ${r.user}.` +
|
||||
(r.sudo ? ` /etc/mosaic-keys/privileged lists ${r.user}.` : ` /etc/mosaic-keys/privileged doesn't list ${r.user}.`) +
|
||||
`\nThen run: mosaic hosts check ${host}`,
|
||||
);
|
||||
});
|
||||
return 'enrolled';
|
||||
} catch (e) {
|
||||
const code = e instanceof BusError ? e.code : 'host-failed';
|
||||
try {
|
||||
this.#hostGrant?.unenroll(business, host);
|
||||
} catch {}
|
||||
try {
|
||||
this.#store.transaction(() => this.#enrollFailed(business, decision, host, code));
|
||||
} catch {}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
// Row 235 (#1741, r6 X2): a host grant's end, in the caller's transaction. The tag is listed every time,
|
||||
// so sweep and status can match a line left on the host.
|
||||
#hostGrantFailed(business, decision, g, code, extra = {}) {
|
||||
const tag = this.#hostGrant?.grantTag(business, g.agent, g.host) ?? null;
|
||||
this.#grantEvent(business, { action: 'grant.failed', grantDecision: decision, agent: g.agent, host: g.host, code, tag, ...extra }, g.host);
|
||||
this.#grantNotice(
|
||||
business,
|
||||
decision,
|
||||
`Grant of host ${g.host} to ${g.agent} (decision ${decision}) failed: ${code}.` +
|
||||
(extra.hostLineLeft ? ` A line tagged ${extra.hostLineLeft} may be left on the host. Run: mosaic hosts sweep ${g.host}` : ''),
|
||||
);
|
||||
}
|
||||
// r6 R1: the agent's definition, if the agent is a role of the business and the definition declares host.
|
||||
// mos-1163: a creative role gets no host grant, whatever its definition declares. The raise binding and
|
||||
// the step 1 recheck both come here.
|
||||
#hostDefinition(business, agent) {
|
||||
const b = this.#business(business);
|
||||
if (!Object.hasOwn(b.roles, agent)) fail('unknown-role');
|
||||
const name = b.roles[agent].definition;
|
||||
if (CREATIVE_DEFINITIONS.includes(name)) fail('host-creative-role');
|
||||
const definition = Object.hasOwn(b.definitions ?? {}, name) ? b.definitions[name] : null;
|
||||
if (!definition?.credentials?.some((c) => c.service === 'host')) fail('host-not-declared');
|
||||
return definition;
|
||||
}
|
||||
// r6 X2 step 1, X5: a grant.revoked of (agent, host) recorded after the decision's raise.
|
||||
#revokedSince(business, decision, agent, host) {
|
||||
return Boolean(
|
||||
this.#store.get(
|
||||
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.revoked' AND json_extract(body,'$.agent')=? AND json_extract(body,'$.host')=? AND seq > (SELECT seq FROM events WHERE business=? AND kind='action.allowed' AND json_extract(body,'$.operation')='decision.raise' AND json_extract(body,'$.decision')=? ORDER BY seq LIMIT 1) LIMIT 1`,
|
||||
business, agent, host, business, decision,
|
||||
),
|
||||
);
|
||||
}
|
||||
// r6 X2 step 1's checks after the spend, R4's binding again. Throws the code that ends the grant.
|
||||
#hostGrantRecheck(business, decision, g) {
|
||||
if (!this.#hostGrant || !this.#hostKeys) fail('host-not-configured');
|
||||
const definition = this.#hostDefinition(business, g.agent);
|
||||
if (this.#hostGrant.definitionSha256(definition) !== g.definitionSha256) fail('decision-mismatch');
|
||||
const r = this.#hostRecord(business, g.host);
|
||||
if (!r) fail('host-unknown');
|
||||
if (registrySha256(r) !== g.registrySha256) fail('decision-mismatch');
|
||||
if (r.state !== 'ready') fail('host-not-ready');
|
||||
if (sha256(JSON.stringify(g.commands)) !== g.commandsSha256) fail('decision-mismatch');
|
||||
if (this.#revokedSince(business, decision, g.agent, g.host)) fail('revoked');
|
||||
return r;
|
||||
}
|
||||
// Trusted host API, as runEnrollment is, and no verb reaches it: the grant executor's entry for one
|
||||
// decision. A second start ends decision-consumed with nothing written (r6 G10).
|
||||
runHostGrant(business, decision) {
|
||||
return this.#runHostGrant(business, decision);
|
||||
}
|
||||
// r6 X2, started by the human's cli yes. Never throws: the outcome is in the store and the notices, and
|
||||
// the return value is 'applied' or the code grant.failed records. Every host_grants write shares its
|
||||
// transaction with grant.applied (sage-1745).
|
||||
async #runHostGrant(business, decision) {
|
||||
let start;
|
||||
try {
|
||||
// Step 1, one transaction: the spend, then R4's checks again. A failed check still spends.
|
||||
start = this.#store.transaction(() => {
|
||||
const g = this.#consumeGrant(business, decision, 'host');
|
||||
let record;
|
||||
try {
|
||||
record = this.#hostGrantRecheck(business, decision, g);
|
||||
} catch (e) {
|
||||
if (!(e instanceof BusError)) throw e;
|
||||
this.#hostGrantFailed(business, decision, g, e.code);
|
||||
return { g, code: e.code };
|
||||
}
|
||||
const live = this.#store.get('SELECT commands FROM host_grants WHERE business=? AND agent=? AND host=?', business, g.agent, g.host);
|
||||
return { g, record, previous: live ? JSON.parse(live.commands) : null };
|
||||
});
|
||||
} catch (e) {
|
||||
// Spent, not approved or no store: nothing was written. The start reconcile ends a resolved,
|
||||
// unspent decision.
|
||||
return e instanceof BusError ? e.code : 'host-failed';
|
||||
}
|
||||
if (start.code) return start.code;
|
||||
const { g, record, previous } = start;
|
||||
// Right after the commit, with no await between, so no revoke or host.run falls in between (X2).
|
||||
let signal;
|
||||
try {
|
||||
signal = this.#hostKeys.claim(business, g.agent, g.host);
|
||||
} catch (e) {
|
||||
const code = e instanceof BusError ? e.code : 'host-failed';
|
||||
try {
|
||||
this.#store.transaction(() => this.#hostGrantFailed(business, decision, g, code));
|
||||
} catch {}
|
||||
return code;
|
||||
}
|
||||
const tag = this.#hostGrant.grantTag(business, g.agent, g.host);
|
||||
const change = previous !== null;
|
||||
const step = (name, extra = {}) =>
|
||||
this.#store.transaction(() =>
|
||||
this.#grantEvent(business, { action: 'grant.step', grantDecision: decision, agent: g.agent, host: g.host, user: record.user, tag, step: name, ...extra }, g.host),
|
||||
);
|
||||
// X5: checked after each await. A revoke during steps 2 to 5 ends the grant revoked.
|
||||
const stop = () => {
|
||||
if (signal.aborted) fail('revoked');
|
||||
};
|
||||
let installing = false,
|
||||
registered = false,
|
||||
committed = false;
|
||||
try {
|
||||
let key = null;
|
||||
if (!change) {
|
||||
// Step 2. A commands change keeps its key and line and skips to step 5.
|
||||
key = await this.#hostGrant.grantKey(tag);
|
||||
stop();
|
||||
// Steps 3 and 4.
|
||||
step('install');
|
||||
installing = true;
|
||||
await this.#hostGrant.install(business, g.host, record, tag, key.publicLine, signal);
|
||||
stop();
|
||||
await this.#hostGrant.verify(g.host, record, key, signal);
|
||||
stop();
|
||||
}
|
||||
// Step 5. Nothing from the abort check to the end of commit awaits (X5, N2).
|
||||
step('commit', { previous });
|
||||
stop();
|
||||
const applied = () => {
|
||||
this.#grantEvent(
|
||||
business,
|
||||
{ action: 'grant.applied', grantDecision: decision, agent: g.agent, host: g.host, user: record.user, tag, fingerprint: key?.fingerprint ?? null, commandsSha256: g.commandsSha256 },
|
||||
g.host,
|
||||
);
|
||||
this.#grantNotice(
|
||||
business,
|
||||
decision,
|
||||
change
|
||||
? `The commands of ${g.agent}'s grant on host ${g.host} changed (decision ${decision}).`
|
||||
: `${g.agent} has access to host ${g.host} as ${record.user} (decision ${decision}), tag ${tag}.`,
|
||||
);
|
||||
};
|
||||
if (change) {
|
||||
this.#store.transaction(() => {
|
||||
const out = this.#store.run(
|
||||
'UPDATE host_grants SET commands=?, decision=? WHERE business=? AND agent=? AND host=?',
|
||||
JSON.stringify(g.commands), decision, business, g.agent, g.host,
|
||||
);
|
||||
if (out.changes !== 1) fail('host-changed');
|
||||
applied();
|
||||
});
|
||||
committed = true;
|
||||
} else {
|
||||
this.#hostKeys.register(business, g.agent, g.host, g.rotateBy);
|
||||
registered = true;
|
||||
this.#hostKeys.issue(business, g.agent, g.host, key.text, g.rotateBy, () => {
|
||||
this.#store.transaction(() => {
|
||||
this.#store.run(
|
||||
'INSERT INTO host_grants(business,agent,host,commands,rotate_by,tag,decision) VALUES(?,?,?,?,?,?,?)',
|
||||
business, g.agent, g.host, JSON.stringify(g.commands), g.rotateBy, tag, decision,
|
||||
);
|
||||
applied();
|
||||
});
|
||||
committed = true;
|
||||
});
|
||||
}
|
||||
return 'applied';
|
||||
} catch (e) {
|
||||
// Once the record and grant.applied commit, an abort is an ordinary revoke's to handle (C1).
|
||||
if (committed) return 'applied';
|
||||
const code = signal.aborted ? 'revoked' : e instanceof BusError ? e.code : 'host-failed';
|
||||
// X3's table: a key file and its reference go, then the line, best effort.
|
||||
if (registered) {
|
||||
try {
|
||||
this.#hostKeys.revoke(business, g.agent, g.host);
|
||||
} catch {}
|
||||
try {
|
||||
this.#hostKeys.unregister(business, g.agent, g.host);
|
||||
} catch {}
|
||||
}
|
||||
let extra = {};
|
||||
if (installing) {
|
||||
try {
|
||||
await this.#hostGrant.remove(business, g.host, record, tag);
|
||||
} catch {
|
||||
extra = { hostLineLeft: tag };
|
||||
}
|
||||
}
|
||||
try {
|
||||
this.#store.transaction(() => this.#hostGrantFailed(business, decision, g, code, extra));
|
||||
} catch {}
|
||||
return code;
|
||||
} finally {
|
||||
this.#hostKeys.release(business, g.agent, g.host, signal);
|
||||
}
|
||||
}
|
||||
// r6 X3 and duckworth-0067 N1: credential.mint decisions for `method`, resolved yes by the human via
|
||||
// cli and never spent.
|
||||
#openGrantDecisions(business, method) {
|
||||
return this.#store
|
||||
.all("SELECT id FROM decisions WHERE business=? AND action='credential.mint' AND route_to='human' ORDER BY at,id", business)
|
||||
.map((d) => d.id)
|
||||
.filter((id) => this.#approvedGrant(business, id)?.method === method && !this.#spent(business, id));
|
||||
}
|
||||
// Trusted host API, at start before the socket opens (r6 X3). An enrollment spent with no
|
||||
// grant.host.enrolled or grant.failed died after its registry step: the key file and the record
|
||||
// go, and it ends grant.failed interrupted. A resolved, unspent one is spent and ends the same way.
|
||||
// Neither runs late.
|
||||
reconcileGrants() {
|
||||
const ended = [];
|
||||
for (const business of Object.keys(this.#businesses)) {
|
||||
const spent = this.#store.all(
|
||||
`SELECT json_extract(body,'$.decision') AS decision FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.operation')='grant.host-enroll' ORDER BY seq`,
|
||||
business,
|
||||
);
|
||||
for (const { decision } of spent) {
|
||||
const end = this.#store.get(
|
||||
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.grantDecision')=? AND json_extract(body,'$.action') IN ('grant.host.enrolled','grant.failed') LIMIT 1`,
|
||||
business,
|
||||
decision,
|
||||
);
|
||||
if (end) continue;
|
||||
const host = this.#raised(business, decision).grant.host;
|
||||
this.#hostGrant?.unenroll(business, host);
|
||||
this.#store.transaction(() =>
|
||||
this.#enrollFailed(business, decision, host, 'interrupted', { tag: this.#hostGrant?.installerTag(business, host) ?? null }),
|
||||
);
|
||||
ended.push(decision);
|
||||
}
|
||||
for (const decision of this.#openGrantDecisions(business, 'host-enroll')) {
|
||||
this.#store.transaction(() => {
|
||||
const g = this.#consumeGrant(business, decision, 'host-enroll');
|
||||
this.#grantEvent(business, { action: 'grant.failed', grantDecision: decision, host: g.host, code: 'interrupted', tag: this.#hostGrant?.installerTag(business, g.host) ?? null }, g.host);
|
||||
this.#grantNotice(business, decision, `Enrollment of host ${g.host} (decision ${decision}) failed: interrupted.`);
|
||||
});
|
||||
ended.push(decision);
|
||||
}
|
||||
// Row 235 (r6 X3): a host grant spent with no grant.applied or grant.failed died mid-executor. The
|
||||
// record and grant.applied commit in one transaction (X2 step 5), so no record names it and the
|
||||
// start sweep has unlinked any key file it wrote. A last step of install, or commit for a new key,
|
||||
// may have left a line: the slot is claimed here, before anyone can call, and reconcileHosts
|
||||
// removes the line. Any other ends interrupted now.
|
||||
const hostSpent = this.#store.all(
|
||||
`SELECT json_extract(body,'$.decision') AS decision FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.operation')='grant.host' ORDER BY seq`,
|
||||
business,
|
||||
);
|
||||
for (const { decision } of hostSpent) {
|
||||
const end = this.#store.get(
|
||||
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.grantDecision')=? AND json_extract(body,'$.action') IN ('grant.applied','grant.failed') LIMIT 1`,
|
||||
business,
|
||||
decision,
|
||||
);
|
||||
if (end) continue;
|
||||
const g = this.#raised(business, decision).grant;
|
||||
const last = this.#store.get(
|
||||
`SELECT body FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.grantDecision')=? AND json_extract(body,'$.action')='grant.step' ORDER BY seq DESC LIMIT 1`,
|
||||
business,
|
||||
decision,
|
||||
);
|
||||
const step = last ? JSON.parse(last.body) : null;
|
||||
if (step && (step.step === 'install' || (step.step === 'commit' && step.previous === null))) {
|
||||
let signal = null;
|
||||
try {
|
||||
signal = this.#hostKeys.claim(business, g.agent, g.host);
|
||||
} catch {}
|
||||
this.#hostUndo.push({ business, decision, g, user: step.user, tag: step.tag, signal });
|
||||
continue;
|
||||
}
|
||||
this.#store.transaction(() => this.#hostGrantFailed(business, decision, g, 'interrupted'));
|
||||
ended.push(decision);
|
||||
}
|
||||
for (const decision of this.#openGrantDecisions(business, 'host')) {
|
||||
this.#store.transaction(() => this.#hostGrantFailed(business, decision, this.#consumeGrant(business, decision, 'host'), 'interrupted'));
|
||||
ended.push(decision);
|
||||
}
|
||||
// r6 section 6 (N4): a grant.revoked still pending has done step 1 and maybe step 2. The record is
|
||||
// gone, so the start sweep took any key file left. reconcileHosts runs step 3.
|
||||
for (const m of this.#openRevokes(business)) this.#revokeUndo.push({ business, ...m });
|
||||
}
|
||||
return ended;
|
||||
}
|
||||
// Trusted host API, after the socket opens (r6 X3): the remote undo of each grant reconcileGrants left
|
||||
// claimed. `remove <user> <tag>` through the installer, then grant.failed interrupted, with
|
||||
// hostLineLeft if the remove failed, and the claim released. It only takes access away, so it needs no
|
||||
// decision. Never throws, and returns the decisions it ended.
|
||||
async reconcileHosts() {
|
||||
const ended = [];
|
||||
for (const u of this.#hostUndo.splice(0)) {
|
||||
let extra = {};
|
||||
try {
|
||||
const record = this.#hostRecord(u.business, u.g.host);
|
||||
if (!record || !this.#hostGrant || !u.signal) fail('host-failed');
|
||||
await this.#hostGrant.remove(u.business, u.g.host, { ...record, user: u.user }, u.tag);
|
||||
} catch {
|
||||
extra = { hostLineLeft: u.tag };
|
||||
}
|
||||
try {
|
||||
this.#store.transaction(() => this.#hostGrantFailed(u.business, u.decision, u.g, 'interrupted', extra));
|
||||
ended.push(u.decision);
|
||||
} catch {}
|
||||
try {
|
||||
if (u.signal) this.#hostKeys.release(u.business, u.g.agent, u.g.host, u.signal);
|
||||
} catch {}
|
||||
}
|
||||
for (const m of this.#revokeUndo.splice(0)) {
|
||||
try {
|
||||
await this.#closeRevoke(m.business, m);
|
||||
ended.push(m.revoke);
|
||||
} catch {}
|
||||
}
|
||||
return ended;
|
||||
}
|
||||
// The grant.revoked bodies still pending, with no grant.revoke.closed of the same revoke id. A body
|
||||
// with no revoke id predates row 235 and has no step 3.
|
||||
#openRevokes(business, host = null) {
|
||||
return this.#store
|
||||
.all(
|
||||
`SELECT body FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.revoked' AND json_extract(body,'$.hostLine')='pending' AND json_type(body,'$.revoke')='text' AND (? IS NULL OR json_extract(body,'$.host')=?) ORDER BY seq`,
|
||||
business,
|
||||
host,
|
||||
host,
|
||||
)
|
||||
.map((e) => JSON.parse(e.body))
|
||||
.filter(
|
||||
(m) =>
|
||||
!this.#store.get(
|
||||
`SELECT 1 FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.revoke.closed' AND json_extract(body,'$.revoke')=? LIMIT 1`,
|
||||
business,
|
||||
m.revoke,
|
||||
),
|
||||
);
|
||||
}
|
||||
// r6 section 6 step 3: `remove <user> <tag>` through the installer, then grant.revoke.closed, with
|
||||
// hostLineLeft if the host can't be reached or has no record. The user is the host record's, as the
|
||||
// executor's. Returns the closed body.
|
||||
async #closeRevoke(business, m) {
|
||||
let line = { hostLine: 'removed' };
|
||||
try {
|
||||
const record = this.#hostRecord(business, m.host);
|
||||
if (!record || !this.#hostGrant) fail('host-failed');
|
||||
await this.#hostGrant.remove(business, m.host, record, m.tag);
|
||||
} catch {
|
||||
line = { hostLineLeft: m.tag };
|
||||
}
|
||||
const body = { action: 'grant.revoke.closed', revoke: m.revoke, agent: m.agent, host: m.host, tag: m.tag, ...line, by: m.by };
|
||||
this.#store.transaction(() => this.#grantEvent(business, body, m.host));
|
||||
return body;
|
||||
}
|
||||
// r6 section 6: local first, so the part that matters can't wait on the network. Step 1 is one
|
||||
// transaction: the record goes, if there is one, and grant.revoked records the pending marker. The tag
|
||||
// is computed, so a revoke with no record still names the line (N4). Step 2 follows with no await
|
||||
// between: the key leaves memory, its file goes, and a host.run or executor in flight aborts (X5).
|
||||
// Step 3 removes the line.
|
||||
async #revokeHost(s, a, by) {
|
||||
keys(a, ['agent', 'host', 'reason'], ['agent', 'host', 'reason']);
|
||||
if (typeof a.agent !== 'string' || !ID_PATTERN.test(a.agent) || typeof a.host !== 'string' || !HOST_ID.test(a.host)) fail('invalid-request');
|
||||
string(a.reason, 500);
|
||||
if (!this.#hostGrant) fail('host-not-configured');
|
||||
const tag = this.#hostGrant.grantTag(s.business, a.agent, a.host);
|
||||
const revoke = randomUUID();
|
||||
const granted = this.#store.transaction(() => {
|
||||
if (!this.#hostRecord(s.business, a.host)) fail('host-unknown');
|
||||
const out = this.#store.run('DELETE FROM host_grants WHERE business=? AND agent=? AND host=?', s.business, a.agent, a.host);
|
||||
this.#grantEvent(
|
||||
s.business,
|
||||
{ action: 'grant.revoked', revoke, agent: a.agent, host: a.host, tag, hostLine: 'pending', granted: out.changes === 1, reason: a.reason, by },
|
||||
a.host,
|
||||
);
|
||||
return out.changes === 1;
|
||||
});
|
||||
let keyFile = 'removed';
|
||||
if (this.#hostKeys) {
|
||||
try {
|
||||
this.#hostKeys.revoke(s.business, a.agent, a.host);
|
||||
} catch (e) {
|
||||
// No reference: only a claim can be held, an executor's before its register.
|
||||
if (e instanceof BusError && e.code === 'credential-unknown') this.#hostKeys.abortClaim(s.business, a.agent, a.host);
|
||||
else keyFile = 'left';
|
||||
}
|
||||
}
|
||||
const closed = await this.#closeRevoke(s.business, { revoke, agent: a.agent, host: a.host, tag, by });
|
||||
return { agent: a.agent, host: a.host, tag, granted, keyFile, ...(closed.hostLineLeft ? { hostLineLeft: closed.hostLineLeft } : { hostLine: 'removed' }) };
|
||||
}
|
||||
// r6 X3 sweep (B4): the tags this business recorded on the host, from grant.step and grant.revoked,
|
||||
// less those of live grants.
|
||||
#sweepTags(business, host) {
|
||||
const tags = new Set(
|
||||
this.#store
|
||||
.all(
|
||||
`SELECT json_extract(body,'$.tag') AS tag FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.host')=? AND json_extract(body,'$.action') IN ('grant.step','grant.revoked') AND json_type(body,'$.tag')='text'`,
|
||||
business,
|
||||
host,
|
||||
)
|
||||
.map((e) => e.tag),
|
||||
);
|
||||
for (const { tag } of this.#store.all('SELECT tag FROM host_grants WHERE business=? AND host=?', business, host)) tags.delete(tag);
|
||||
return tags;
|
||||
}
|
||||
// r6 E1, R3: the raise checks and the keyscan, then the raise transaction. Row 235 (#1741, r6 R4): a
|
||||
// host grant has no keyscan, so its store checks all run inside the raise transaction.
|
||||
async #raiseGrant(s, a) {
|
||||
try {
|
||||
this.#store.transaction(() => this.#agent(s));
|
||||
if (a.action !== 'credential.mint' || 'spec_path' in a || 'spec_commit' in a) fail('invalid-request');
|
||||
if (this.#business(s.business).roles[s.role]?.definition !== STAFF_TO) fail('grant-chief-only');
|
||||
if (!this.#hostGrant) fail('host-not-configured');
|
||||
if (a.grant?.method === 'host') {
|
||||
const g = this.#hostGrant.hostGrantCheck(a.grant, this.#now().slice(0, 10));
|
||||
return this.#store.transaction(() => {
|
||||
const result = this.#dispatch(s, 'decision.raise', a, null, this.#hostGrantBinding(s.business, g));
|
||||
this.#secretCheck(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
const enroll = this.#hostGrant.enrollCheck(a.grant);
|
||||
if (this.#hostRecord(s.business, enroll.host)) fail('host-enrolled');
|
||||
const hostKeys = await this.#hostGrant.keyscan(enroll.address, enroll.port);
|
||||
if (!this.#hostGrant.sameFingerprints(hostKeys, enroll.fingerprints)) fail('host-key-mismatch');
|
||||
return this.#store.transaction(() => {
|
||||
if (this.#hostRecord(s.business, enroll.host)) fail('host-enrolled');
|
||||
const result = this.#dispatch(s, 'decision.raise', a, null, enrollBinding({ ...enroll, hostKeys }));
|
||||
this.#secretCheck(result);
|
||||
return result;
|
||||
});
|
||||
} catch (e) {
|
||||
throw this.#refused(s, e, { verb: 'decision.raise', args: a });
|
||||
}
|
||||
}
|
||||
// r6 R4: a host grant's store checks and its raise binding. The caller owns the transaction. The body
|
||||
// is R4's eight fields. The block shows the human the host as enrolled, each prefix and whether the
|
||||
// key is new, and the chief can't shape it.
|
||||
#hostGrantBinding(business, g) {
|
||||
const definition = this.#hostDefinition(business, g.agent);
|
||||
const h = this.#hostRecord(business, g.host);
|
||||
if (!h) fail('host-unknown');
|
||||
if (h.state !== 'ready') fail('host-not-ready');
|
||||
const live = this.#store.get('SELECT 1 FROM host_grants WHERE business=? AND agent=? AND host=?', business, g.agent, g.host);
|
||||
const body = {
|
||||
method: 'host',
|
||||
agent: g.agent,
|
||||
host: g.host,
|
||||
commands: g.commands,
|
||||
commandsSha256: sha256(JSON.stringify(g.commands)),
|
||||
rotateBy: g.rotateBy,
|
||||
registrySha256: registrySha256(h),
|
||||
definitionSha256: this.#hostGrant.definitionSha256(definition),
|
||||
};
|
||||
const block =
|
||||
`\n\nGrant ${g.agent} access to host ${g.host}: user ${h.user} at ${h.address} port ${h.port}.` +
|
||||
(h.sudo ? `\n${h.user} has sudo on this host.` : `\n${h.user} has no sudo on this host.`) +
|
||||
`\nCommands, each an argv prefix:` +
|
||||
g.commands.map((prefix) => `\n${prefix.map((x) => JSON.stringify(x)).join(' ')}`).join('') +
|
||||
`\nRotate by ${g.rotateBy}.` +
|
||||
(live
|
||||
? `\nThis changes the commands of ${g.agent}'s grant on ${g.host}. The key stays.`
|
||||
: `\nThis makes a new key for ${g.agent} on ${g.host}.`);
|
||||
return { body, block };
|
||||
}
|
||||
#hostsCaller(s, verb) {
|
||||
if (s.reader) fail('read-only');
|
||||
if (s.tester) {
|
||||
// r6 section 6 (N8): a tester revoke needs bus.tester exactly true on the session's business, read
|
||||
// again here. Missing or any other value isn't dev.
|
||||
if (verb === 'hosts.revoke' && this.#business(s.business).vars?.['bus.tester'] !== true) fail('tester-dev-only');
|
||||
return 'tester';
|
||||
}
|
||||
if (s.human) {
|
||||
this.#human(s);
|
||||
return s.human;
|
||||
}
|
||||
// hosts.remove and hosts.sweep take access away, as a revoke does: the human or the tester (r6 E4, X3).
|
||||
if (verb === 'hosts.remove' || verb === 'hosts.sweep') fail('human-required');
|
||||
this.#store.transaction(() => this.#agent(s));
|
||||
// r6 section 6 (G26): the assistant revokes in its own business. The verb acts on the session's
|
||||
// business only, so another business's grant can't be named.
|
||||
if (verb === 'hosts.revoke') {
|
||||
if (!this.#threaded(s.business, s.role)) fail('revoke-refused');
|
||||
return s.role;
|
||||
}
|
||||
if (this.#business(s.business).roles[s.role]?.definition !== STAFF_TO) fail('grant-chief-only');
|
||||
return s.role;
|
||||
}
|
||||
// r6 E4: hosts.status, hosts.check and hosts.remove. Async, because check runs ssh. Row 235 adds
|
||||
// hosts.revoke and hosts.sweep (r6 section 6, X3).
|
||||
async #requestHosts(s, verb, a) {
|
||||
try {
|
||||
const by = this.#hostsCaller(s, verb);
|
||||
if (verb === 'hosts.status') {
|
||||
keys(a, []);
|
||||
return this.#store
|
||||
.all('SELECT host FROM hosts WHERE business=? ORDER BY host', s.business)
|
||||
.map(({ host }) => {
|
||||
const r = this.#hostRecord(s.business, host);
|
||||
return {
|
||||
host,
|
||||
address: r.address,
|
||||
port: r.port,
|
||||
user: r.user,
|
||||
sudo: r.sudo,
|
||||
state: r.state,
|
||||
hostKeys: r.hostKeys.map(fingerprintOf),
|
||||
installerFingerprint: r.installer_fingerprint,
|
||||
checkedAt: r.checked_at,
|
||||
hostLineLeft: this.#hostLinesLeft(s.business, host),
|
||||
// r6 section 6: the tags of revokes still in progress.
|
||||
revoking: this.#openRevokes(s.business, host).map((m) => m.tag),
|
||||
};
|
||||
});
|
||||
}
|
||||
if (verb === 'hosts.revoke') return await this.#revokeHost(s, a, by);
|
||||
keys(a, ['host'], ['host']);
|
||||
if (typeof a.host !== 'string' || !HOST_ID.test(a.host)) fail('invalid-request');
|
||||
if (!this.#hostGrant) fail('host-not-configured');
|
||||
if (verb === 'hosts.sweep') {
|
||||
const r = this.#hostRecord(s.business, a.host);
|
||||
if (!r) fail('host-unknown');
|
||||
const left = this.#hostLinesLeft(s.business, a.host);
|
||||
const { listed, removed } = await this.#hostGrant.sweep(s.business, a.host, r, this.#sweepTags(s.business, a.host));
|
||||
// A left tag still listed and not removed stays left.
|
||||
const still = left.filter((tag) => listed.includes(tag) && !removed.includes(tag));
|
||||
this.#store.transaction(() => this.#grantEvent(s.business, { action: 'grant.host.swept', host: a.host, removed, left: still, by }, a.host));
|
||||
return { host: a.host, removed, hostLineLeft: still };
|
||||
}
|
||||
if (verb === 'hosts.remove') {
|
||||
return this.#store.transaction(() => {
|
||||
const r = this.#hostRecord(s.business, a.host);
|
||||
if (!r) fail('host-unknown');
|
||||
if (this.#store.get('SELECT 1 FROM host_grants WHERE business=? AND host=? LIMIT 1', s.business, a.host)) fail('host-in-use');
|
||||
if (this.#hostLinesLeft(s.business, a.host).length) fail('host-line-left');
|
||||
this.#store.run('DELETE FROM hosts WHERE business=? AND host=?', s.business, a.host);
|
||||
this.#grantEvent(s.business, { action: 'grant.host.removed', host: a.host, registrySha256: registrySha256(r), by }, a.host);
|
||||
// Last, so a key file that won't go rolls the record and the event back.
|
||||
this.#hostGrant.unenroll(s.business, a.host);
|
||||
return { host: a.host, removed: true };
|
||||
});
|
||||
}
|
||||
const before = this.#hostRecord(s.business, a.host);
|
||||
if (!before) fail('host-unknown');
|
||||
if (!before.installer_fingerprint) fail('host-not-enrolled');
|
||||
const out = await this.#hostGrant.check(s.business, a.host, before);
|
||||
if (out.exit !== 0) fail('host-failed');
|
||||
return this.#store.transaction(() => {
|
||||
const r = this.#hostRecord(s.business, a.host);
|
||||
const sha = r && registrySha256(r);
|
||||
if (!r || r.decision !== before.decision || sha !== registrySha256(before) || out.installerFingerprint !== r.installer_fingerprint)
|
||||
fail('host-changed');
|
||||
const at = this.#now();
|
||||
this.#store.run("UPDATE hosts SET state='ready',checked_at=? WHERE business=? AND host=?", at, s.business, a.host);
|
||||
this.#grantEvent(
|
||||
s.business,
|
||||
{ action: 'grant.host.checked', host: a.host, registrySha256: sha, installerFingerprint: r.installer_fingerprint, by },
|
||||
a.host,
|
||||
);
|
||||
return { host: a.host, state: 'ready', checkedAt: at };
|
||||
});
|
||||
} catch (e) {
|
||||
throw this.#refused(s, e, { verb, args: a });
|
||||
}
|
||||
}
|
||||
// r6 E4, duckworth-0079 F2 and F3: every guarded body that left a line on the host names the host.
|
||||
// Row 235 adds the sweep clear (F4): the last grant.host.swept carries what it left, and only later
|
||||
// bodies add to it.
|
||||
#hostLinesLeft(business, host) {
|
||||
const swept = this.#store.get(
|
||||
`SELECT seq, body FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.action')='grant.host.swept' AND json_extract(body,'$.host')=? ORDER BY seq DESC LIMIT 1`,
|
||||
business,
|
||||
host,
|
||||
);
|
||||
const left = swept ? JSON.parse(swept.body).left : [];
|
||||
for (const e of this.#store.all(
|
||||
`SELECT json_extract(body,'$.hostLineLeft') AS tag FROM events WHERE business=? AND ${GRANT_EVIDENCE} AND json_extract(body,'$.host')=? AND json_extract(body,'$.hostLineLeft') IS NOT NULL AND seq > ? ORDER BY seq`,
|
||||
business,
|
||||
host,
|
||||
swept?.seq ?? 0,
|
||||
))
|
||||
if (!left.includes(e.tag)) left.push(e.tag);
|
||||
return left;
|
||||
}
|
||||
#hardWait(s, action, target) {
|
||||
if (GATED.has(action)) return true;
|
||||
return action === 'role.revoke' && END_PROTECTED.includes(this.#business(s.business).roles[target]?.definition);
|
||||
@@ -2048,7 +1246,6 @@ export class Broker {
|
||||
this.#agent(s);
|
||||
if (['human.input', 'launch.revoked', 'launch.restored', ...REVIEW_KINDS].includes(kind)) fail('reserved-event');
|
||||
if (kind === 'action.allowed' && ['git.push.working', MERGE].includes(body?.action)) fail('reserved-event');
|
||||
if (kind === 'action.allowed' && grantName(body)) fail('reserved-event');
|
||||
return this.#event(s, kind, body, subject);
|
||||
});
|
||||
}
|
||||
@@ -2170,18 +1367,10 @@ export class Broker {
|
||||
const args = request.args ?? {};
|
||||
if (!object(args)) fail('invalid-request');
|
||||
this.#secretCheck(args);
|
||||
// Row 213 (C2-08, Case 2 design 5.1 M6): a creative role has no free-text decision channel. It
|
||||
// runs before the spec-cited branch below, so a cited raise refuses too.
|
||||
if (request.verb === 'decision.raise' && !s.human && !s.tester &&
|
||||
CREATIVE_DEFINITIONS.includes(this.#business(s.business).roles[s.role]?.definition))
|
||||
fail('decision-not-allowed');
|
||||
if (request.verb === 'usage.begin' || request.verb === 'usage.end')
|
||||
return this.#requestUsage(s, request.verb, structuredClone(args));
|
||||
if ((request.verb === 'message.receive' || request.verb === 'state') && this.#stops.has(s.business + ':' + s.run))
|
||||
this.#limitStop(s);
|
||||
// Row 234 (#1740, r6 E1): a raise with `grant` runs its keyscan before the raise transaction.
|
||||
if (request.verb === 'decision.raise' && 'grant' in args) return this.#raiseGrant(s, structuredClone(args));
|
||||
if (HOSTS_VERBS.includes(request.verb)) return this.#requestHosts(s, request.verb, structuredClone(args));
|
||||
if (request.verb === 'spec.read' || request.verb === 'record.write' ||
|
||||
(request.verb === 'decision.raise' && ('spec_path' in args || 'spec_commit' in args)))
|
||||
return this.#requestProject(s, { verb: request.verb, args: structuredClone(args) });
|
||||
@@ -2538,18 +1727,21 @@ export class Broker {
|
||||
a = request.args ?? {};
|
||||
keys(a, ['host', 'argv', 'stdin', 'timeout', 'decision'], ['host', 'argv']);
|
||||
this.#secretCheck(a);
|
||||
this.#store.transaction(() => this.#agent(s));
|
||||
const b = this.#business(s.business);
|
||||
identifier(a.host);
|
||||
// Row 234 (#1740, r6 X4): the store records, not the business file.
|
||||
const access = this.#store.transaction(() => (this.#agent(s), this.#hostAccess(s, a.host)));
|
||||
if (!Object.hasOwn(b.hosts ?? {}, a.host)) fail('host-unknown');
|
||||
const grant = Object.hasOwn(b.roles[s.role]?.hosts ?? {}, a.host) ? b.roles[s.role].hosts[a.host] : null;
|
||||
if (!grant) fail('host-not-granted');
|
||||
if (!validArgv(a.argv) || !validStdin(a.stdin)) fail('invalid-request');
|
||||
if (!commandAllowed(a.argv, access.commands)) fail('command-not-granted');
|
||||
if (!commandAllowed(a.argv, grant.commands)) fail('command-not-granted');
|
||||
timeout = a.timeout ?? HOST_TIMEOUT_DEFAULT;
|
||||
if (!Number.isInteger(timeout) || timeout < 1 || timeout > HOST_TIMEOUT_MAX) fail('invalid-request');
|
||||
if (a.decision !== undefined) identifier(a.decision);
|
||||
if (!executor) fail('host-not-configured');
|
||||
// A busy host refuses before the decision is spent; the executor checks again under its lock.
|
||||
if (executor.busy(s, a.host)) fail('host-busy');
|
||||
entry = access.entry;
|
||||
entry = b.hosts[a.host];
|
||||
bound = hostRun(a.host, a.argv, a.stdin);
|
||||
this.#store.transaction(() =>
|
||||
this.#consumeAuthority(
|
||||
@@ -2601,7 +1793,7 @@ export class Broker {
|
||||
});
|
||||
return out;
|
||||
}
|
||||
#dispatch(s, verb, a, spec = null, binding = null) {
|
||||
#dispatch(s, verb, a, spec = null) {
|
||||
const b = this.#business(s.business),
|
||||
by = s.human || s.run;
|
||||
switch (verb) {
|
||||
@@ -2706,12 +1898,9 @@ export class Broker {
|
||||
'spec_commit',
|
||||
'argv',
|
||||
'stdin',
|
||||
'grant',
|
||||
],
|
||||
['action', 'question', 'options', 'recommendation', 'blocking'],
|
||||
);
|
||||
// Only #raiseGrant passes `binding`, after its checks.
|
||||
if (('grant' in a) !== (binding !== null)) fail('invalid-request');
|
||||
this.#agent(s);
|
||||
if ((a.spec_path !== undefined || a.spec_commit !== undefined) && !spec) fail('invalid-spec-citation');
|
||||
const cls = this.#classification(s, a.action, a.target);
|
||||
@@ -2772,20 +1961,18 @@ export class Broker {
|
||||
if (!sudo && (a.argv !== undefined || a.stdin !== undefined)) fail('invalid-request');
|
||||
let question = pushCommit ? `${a.question} (commit ${pushCommit})` : a.question;
|
||||
if (sudo) {
|
||||
if (a.target === undefined) fail('host-unknown');
|
||||
// The human is asked only about a call host.run would take: the raiser's own grant and prefix (N1).
|
||||
// Row 234 (r6 X4): read from the store records, with the Approve record check.
|
||||
const access = this.#hostAccess(s, a.target);
|
||||
if (a.target === undefined || !Object.hasOwn(b.hosts ?? {}, a.target)) fail('host-unknown');
|
||||
if (!validArgv(a.argv) || !validStdin(a.stdin)) fail('invalid-request');
|
||||
if (!commandAllowed(a.argv, access.commands)) fail('command-not-granted');
|
||||
const h = access.entry;
|
||||
// The human is asked only about a call host.run would take: the raiser's own grant and prefix (N1).
|
||||
const grant = Object.hasOwn(b.roles[s.role]?.hosts ?? {}, a.target) ? b.roles[s.role].hosts[a.target] : null;
|
||||
if (!grant) fail('host-not-granted');
|
||||
if (!commandAllowed(a.argv, grant.commands)) fail('command-not-granted');
|
||||
const h = b.hosts[a.target];
|
||||
question +=
|
||||
`\n\nHost ${a.target}, ${h.user} at ${h.address} port ${h.port}, runs as root:` +
|
||||
`\nargv: ${a.argv.map((x) => JSON.stringify(x)).join(' ')}` +
|
||||
`\nstdin: ${JSON.stringify(a.stdin ?? '')}`;
|
||||
}
|
||||
// Rows 234 and 235: the grant's block, built by the broker. The chief can't shape it.
|
||||
if (binding) question += binding.block;
|
||||
string(question);
|
||||
const did = randomUUID();
|
||||
this.#store.run(
|
||||
@@ -2823,7 +2010,6 @@ export class Broker {
|
||||
a.action === 'role.revoke' ? (this.#holder(s.business, a.target)?.holder_run ?? null) : null,
|
||||
...(pushCommit ? { pushCommit } : {}),
|
||||
...(sudo ? { hostRun: hostRun(a.target, a.argv, a.stdin) } : {}),
|
||||
...(binding ? { grant: binding.body } : {}),
|
||||
},
|
||||
a.task_ref ?? (taskRef(a.target) ? a.target : did),
|
||||
);
|
||||
@@ -2874,11 +2060,6 @@ export class Broker {
|
||||
a.note ?? null,
|
||||
s.human ? 'cli' : 'broker',
|
||||
);
|
||||
// Row 234 (#1740, r6 X1): the human's cli approve of a grant mint starts the executor once this
|
||||
// transaction commits. It rechecks all of this itself, so a rollback starts nothing.
|
||||
const grant = op === 'resolved' ? this.#approvedGrant(s.business, d.id) : null;
|
||||
if (grant?.method === 'host-enroll') setImmediate(() => this.#runEnrollment(s.business, d.id));
|
||||
if (grant?.method === 'host') setImmediate(() => this.#runHostGrant(s.business, d.id));
|
||||
if (s.human)
|
||||
this.#event(
|
||||
s,
|
||||
@@ -2922,7 +2103,7 @@ export class Broker {
|
||||
);
|
||||
this.#route(s.business, mid, d.raised_by_role, thread);
|
||||
}
|
||||
return grant ? { id: d.id, op, grant: 'started' } : { id: d.id, op };
|
||||
return { id: d.id, op };
|
||||
}
|
||||
case 'message.send': {
|
||||
keys(a, ['to', 'body', 'class', 'in_reply_to', 'corrects', 'decision'], ['to', 'body']);
|
||||
|
||||
@@ -13,7 +13,7 @@ const inside = (root, path) => {
|
||||
const r = relative(root, path);
|
||||
return r === '' || (!r.startsWith('..') && !isAbsolute(r));
|
||||
};
|
||||
export const day = (value) =>
|
||||
const day = (value) =>
|
||||
typeof value === 'string' &&
|
||||
/^\d{4}-\d{2}-\d{2}$/.test(value) &&
|
||||
!Number.isNaN(Date.parse(value)) &&
|
||||
@@ -98,7 +98,7 @@ export function assertCleanKey(value, key) {
|
||||
if (key.needles.some((n) => encoded.includes(n))) deny('credential-leak');
|
||||
}
|
||||
// Row 199 (#1697, design D1, D4): a store dir is the stack instance's user's own and nobody else's.
|
||||
export const privateDir = (path, { missing = false } = {}) => {
|
||||
const privateDir = (path, { missing = false } = {}) => {
|
||||
let st;
|
||||
try {
|
||||
st = lstatSync(path);
|
||||
@@ -128,7 +128,19 @@ export class Credentials {
|
||||
try {
|
||||
for (const [instance, services] of Object.entries(references))
|
||||
for (const [service, ref] of Object.entries(services)) {
|
||||
const date = this.#checkRef(instance, service, ref);
|
||||
if (!credentialKind(service) || !ref || typeof ref !== 'object')
|
||||
deny('credential-reference');
|
||||
const date = service === 'vikunja' ? ref.expires : ref.rotateBy;
|
||||
if (!day(date)) deny('credential-date');
|
||||
if (
|
||||
(ref.service !== undefined && ref.service !== service) ||
|
||||
Object.keys(ref).some(
|
||||
(k) => !['service', 'file', 'env', 'store', service === 'vikunja' ? 'expires' : 'rotateBy'].includes(k),
|
||||
) ||
|
||||
Boolean(ref.file) === Boolean(ref.env) ||
|
||||
(ref.store !== undefined && (ref.store !== true || ref.file !== this.#storePath(instance, service)))
|
||||
)
|
||||
deny('credential-reference');
|
||||
this.#refs.set(instance + ':' + service, { ref, date });
|
||||
const value = this.#read(ref, env, service);
|
||||
if (value !== null) this.#tokens.set(instance + ':' + service, { ...value, date });
|
||||
@@ -138,60 +150,6 @@ export class Credentials {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
// One reference's checks, for the constructor and register (row 235, r6 X4). Returns its date.
|
||||
#checkRef(instance, service, ref) {
|
||||
if (!credentialKind(service) || !ref || typeof ref !== 'object') deny('credential-reference');
|
||||
const date = service === 'vikunja' ? ref.expires : ref.rotateBy;
|
||||
if (!day(date)) deny('credential-date');
|
||||
if (
|
||||
(ref.service !== undefined && ref.service !== service) ||
|
||||
Object.keys(ref).some(
|
||||
(k) => !['service', 'file', 'env', 'store', service === 'vikunja' ? 'expires' : 'rotateBy'].includes(k),
|
||||
) ||
|
||||
Boolean(ref.file) === Boolean(ref.env) ||
|
||||
(ref.store !== undefined && (ref.store !== true || ref.file !== this.#storePath(instance, service)))
|
||||
)
|
||||
deny('credential-reference');
|
||||
return date;
|
||||
}
|
||||
// Row 235 (#1741, r6 X4): the grant executor adds a reference before `issue`, which refuses an unknown
|
||||
// one. It reads no file, so a key file a failed revoke left can't come back. An entry with a live
|
||||
// token refuses, and an entry with none, revoked or never issued, is replaced.
|
||||
register(instance, service, ref) {
|
||||
const k = instance + ':' + service;
|
||||
if (this.#tokens.has(k)) deny('credential-reference');
|
||||
const date = this.#checkRef(instance, service, ref);
|
||||
this.#refs.set(k, { ref, date });
|
||||
this.#revoked.delete(k);
|
||||
}
|
||||
// r6 X3, X4: the executor's undo for a reference it registered. An entry with a live token refuses.
|
||||
unregister(instance, service) {
|
||||
const k = instance + ':' + service;
|
||||
if (this.#tokens.has(k)) deny('credential-reference');
|
||||
this.#refs.delete(k);
|
||||
this.#revoked.delete(k);
|
||||
}
|
||||
// r6 X5: the executor holds the entry's #inflight slot for its steps, so a host.run refuses host-busy
|
||||
// and revoke's abort() reaches the executor. A slot already held refuses host-busy. Returns the signal.
|
||||
claim(instance, service) {
|
||||
const k = instance + ':' + service;
|
||||
if (this.#inflight.has(k)) deny('host-busy');
|
||||
const controller = new AbortController();
|
||||
this.#inflight.set(k, controller);
|
||||
return controller.signal;
|
||||
}
|
||||
// Frees the slot only if `signal` is the claim's own, so a late release can't free a later claim.
|
||||
release(instance, service, signal) {
|
||||
const k = instance + ':' + service;
|
||||
if (this.#inflight.get(k)?.signal === signal) this.#inflight.delete(k);
|
||||
}
|
||||
// r6 X5: hosts.revoke with no reference to revoke. Aborts a live claim or call and says whether there
|
||||
// was one.
|
||||
abortClaim(instance, service) {
|
||||
const controller = this.#inflight.get(instance + ':' + service);
|
||||
controller?.abort();
|
||||
return { pending: Boolean(controller) };
|
||||
}
|
||||
#storePath(instance, service) {
|
||||
if (!this.#storeRoot) deny('credential-reference');
|
||||
const [business, agent, ...rest] = instance.split('/');
|
||||
|
||||
@@ -1,357 +0,0 @@
|
||||
// Row 234 (#1740, #436a row a): the trusted half of host enrollment, run in the bus child. The broker
|
||||
// gets it as `hostGrant` and holds every store write. This module holds what touches the network or
|
||||
// a key file: the raise's ssh-keyscan (E1), the installer key pair (E2 steps 2 and 3) and the installer's
|
||||
// `list` for hosts.check (E4). Row 235 (#1741, #436 row b) adds the host grant raise binding (R4), the
|
||||
// grant executor's remote steps (X2 steps 2 to 4 and the `remove` undo) and `grantKeys`, the broker's
|
||||
// narrow handle on Credentials.
|
||||
//
|
||||
// The installer key lives at <configDir>/secrets/hosts/<business>/<hostId>/installer, 0600 in 0700 dirs,
|
||||
// written as 210's issue writes (tmp, fsync, rename). It is never read into an event or a message.
|
||||
import { spawn } from 'node:child_process';
|
||||
import { createHash } from 'node:crypto';
|
||||
import {
|
||||
closeSync, constants, fsyncSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, renameSync, rmSync,
|
||||
rmdirSync, unlinkSync, writeSync,
|
||||
} from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { BusError } from './broker.mjs';
|
||||
import { day, parseHostKey, privateDir } from './credentials.mjs';
|
||||
import { runHost, HOST_LIMITS } from './host-run.mjs';
|
||||
import { checkAddress, checkCommands, HOST_KEY, USER } from '../../business/src/hosts.mjs';
|
||||
import { canonicalJson } from '../../business/src/util.mjs';
|
||||
import { HOST_ID, ID_PATTERN } from '../../business/src/vocabulary.mjs';
|
||||
|
||||
const deny = (code) => {
|
||||
throw new BusError(code);
|
||||
};
|
||||
const PATH = '/usr/bin:/bin';
|
||||
const KILL_WITH_PARENT = ['/usr/bin/setpriv', '--pdeathsig', 'KILL', '--'];
|
||||
// E1: the users no enrollment may name. The host writer refuses them again (tools/host/mosaic-keys-write).
|
||||
export const RESERVED_USERS = Object.freeze(['root', 'localadmin', 'mosaic-installer']);
|
||||
const FINGERPRINT = /^SHA256:[A-Za-z0-9+/]{43}$/;
|
||||
// E1: the three key types the keyscan asks for, so any other fingerprint can't match.
|
||||
const SCAN_TYPES = 'ed25519,ecdsa,rsa';
|
||||
export const INSTALLER_USER = 'mosaic-installer';
|
||||
const INSTALLER_AGENT = '@installer';
|
||||
const SCAN_MS = 10000;
|
||||
|
||||
// X2 step 2: `mosaic-` and the first 32 hex digits of sha256 over business, agent and host id joined
|
||||
// with NUL. Names match ID_PATTERN or HOST_ID, neither holds NUL, so the join is one to one.
|
||||
export function grantTag(business, agent, hostId) {
|
||||
return 'mosaic-' + createHash('sha256').update([business, agent, hostId].join('\0')).digest('hex').slice(0, 32);
|
||||
}
|
||||
export const installerTag = (business, hostId) => grantTag(business, INSTALLER_AGENT, hostId);
|
||||
|
||||
// The OpenSSH fingerprint of a "<type> <base64>" line: sha256 over the decoded blob.
|
||||
export function fingerprint(line) {
|
||||
const blob = Buffer.from(line.split(' ')[1], 'base64');
|
||||
return 'SHA256:' + createHash('sha256').update(blob).digest('base64').replace(/=+$/, '');
|
||||
}
|
||||
|
||||
// E1's binding. Anything off refuses invalid-request; the broker adds the chief, action and enrolled
|
||||
// checks. Returns a fresh object with only the bound keys.
|
||||
export function enrollCheck(grant) {
|
||||
const allowed = ['method', 'host', 'address', 'port', 'user', 'sudo', 'fingerprints'];
|
||||
if (!grant || typeof grant !== 'object' || Array.isArray(grant)) deny('invalid-request');
|
||||
const own = Object.keys(grant);
|
||||
if (own.some((k) => !allowed.includes(k)) || allowed.some((k) => !own.includes(k))) deny('invalid-request');
|
||||
if (grant.method !== 'host-enroll') deny('invalid-request');
|
||||
if (typeof grant.host !== 'string' || !HOST_ID.test(grant.host)) deny('invalid-request');
|
||||
try {
|
||||
checkAddress(grant.address, 'grant.address');
|
||||
} catch {
|
||||
deny('invalid-request');
|
||||
}
|
||||
if (!Number.isInteger(grant.port) || grant.port < 1 || grant.port > 65535) deny('invalid-request');
|
||||
if (typeof grant.user !== 'string' || !USER.test(grant.user) || RESERVED_USERS.includes(grant.user)) deny('invalid-request');
|
||||
if (typeof grant.sudo !== 'boolean') deny('invalid-request');
|
||||
const prints = grant.fingerprints;
|
||||
if (!Array.isArray(prints) || prints.length < 1 || prints.length > 3) deny('invalid-request');
|
||||
if (prints.some((f) => typeof f !== 'string' || !FINGERPRINT.test(f)) || new Set(prints).size !== prints.length) deny('invalid-request');
|
||||
return { method: 'host-enroll', host: grant.host, address: grant.address, port: grant.port, user: grant.user, sudo: grant.sudo, fingerprints: [...prints] };
|
||||
}
|
||||
|
||||
// R4's binding for a host grant. Anything off refuses invalid-request. `today` is the bus clock's UTC
|
||||
// day. rotateBy must be a real calendar day after it (210's day check, credentials.mjs; sage-1782). The
|
||||
// broker checks the agent, its definition and the host inside the raise transaction. Returns a fresh
|
||||
// object with only the bound keys.
|
||||
export function hostGrantCheck(grant, today) {
|
||||
const allowed = ['method', 'agent', 'host', 'commands', 'rotateBy'];
|
||||
if (!grant || typeof grant !== 'object' || Array.isArray(grant)) deny('invalid-request');
|
||||
const own = Object.keys(grant);
|
||||
if (own.some((k) => !allowed.includes(k)) || allowed.some((k) => !own.includes(k))) deny('invalid-request');
|
||||
if (grant.method !== 'host') deny('invalid-request');
|
||||
if (typeof grant.agent !== 'string' || !ID_PATTERN.test(grant.agent)) deny('invalid-request');
|
||||
if (typeof grant.host !== 'string' || !HOST_ID.test(grant.host)) deny('invalid-request');
|
||||
let commands;
|
||||
try {
|
||||
commands = checkCommands(grant.commands, 'grant.commands');
|
||||
} catch {
|
||||
deny('invalid-request');
|
||||
}
|
||||
if (!day(grant.rotateBy) || grant.rotateBy <= today) deny('invalid-request');
|
||||
return { method: 'host', agent: grant.agent, host: grant.host, commands, rotateBy: grant.rotateBy };
|
||||
}
|
||||
|
||||
// R4's definitionSha256: sha256 over the canonical JSON of the definition the business loaded, since
|
||||
// the broker doesn't read roles/ (sage-0590). A change to any field the loader keeps changes it.
|
||||
export const definitionSha256 = (definition) => createHash('sha256').update(canonicalJson(definition)).digest('hex');
|
||||
|
||||
// r6 X4: the store reference for an agent's host.<id> key, as Credentials checks it. The runtime's start
|
||||
// load and the executor's register both use it.
|
||||
export const hostReference = (storeRoot, business, agent, hostId, rotateBy) => ({
|
||||
store: true,
|
||||
file: storeRoot ? join(storeRoot, business, agent, 'host.' + hostId) : null,
|
||||
rotateBy,
|
||||
});
|
||||
|
||||
// Row 235 (r6 X2 to X5): the grant executor's calls on Credentials, keyed by (business, agent, hostId).
|
||||
// The broker gets this and never Credentials itself, so it still has no use().
|
||||
export function grantKeys({ credentials, storeRoot }) {
|
||||
const at = (business, agent) => business + '/' + agent;
|
||||
const service = (hostId) => 'host.' + hostId;
|
||||
return {
|
||||
claim: (business, agent, hostId) => credentials.claim(at(business, agent), service(hostId)),
|
||||
release: (business, agent, hostId, signal) => credentials.release(at(business, agent), service(hostId), signal),
|
||||
abortClaim: (business, agent, hostId) => credentials.abortClaim(at(business, agent), service(hostId)),
|
||||
register: (business, agent, hostId, rotateBy) =>
|
||||
credentials.register(at(business, agent), service(hostId), hostReference(storeRoot, business, agent, hostId, rotateBy)),
|
||||
unregister: (business, agent, hostId) => credentials.unregister(at(business, agent), service(hostId)),
|
||||
issue: (business, agent, hostId, text, rotateBy, commit) => credentials.issue(at(business, agent), service(hostId), text, rotateBy, commit),
|
||||
revoke: (business, agent, hostId) => credentials.revoke(at(business, agent), service(hostId)),
|
||||
};
|
||||
}
|
||||
|
||||
// r6 section 6 and N1 of duckworth-0063: at start, before Credentials loads, unlink each host.<id> key
|
||||
// file in a loaded business's agent store that has no host_grants record. `granted` holds
|
||||
// 'business/agent/hostId' for each record. A file an interrupted executor wrote before its commit, or one
|
||||
// a revoke failed to unlink, goes here. No reference loads for a file with no record (X4), so nothing
|
||||
// holds it. A store dir that isn't private refuses credential-file, as Credentials would.
|
||||
export function sweepHostKeys(storeRoot, businesses, granted) {
|
||||
const removed = [];
|
||||
if (!storeRoot || !privateDir(storeRoot, { missing: true })) return removed;
|
||||
for (const business of businesses) {
|
||||
const dir = join(storeRoot, business);
|
||||
if (!privateDir(dir, { missing: true })) continue;
|
||||
for (const agent of readdirSync(dir)) {
|
||||
const agentDir = join(dir, agent);
|
||||
if (!lstatSync(agentDir).isDirectory()) continue;
|
||||
privateDir(agentDir);
|
||||
for (const name of readdirSync(agentDir)) {
|
||||
const hostId = name.startsWith('host.') ? name.slice(5) : null;
|
||||
if (!hostId || !HOST_ID.test(hostId) || granted.has(business + '/' + agent + '/' + hostId)) continue;
|
||||
unlinkSync(join(agentDir, name));
|
||||
removed.push({ instance: business + '/' + agent, service: name });
|
||||
}
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
// The tags in `list` output, one per line, the last field of each.
|
||||
export const listedTags = (stdout) => stdout.split('\n').filter(Boolean).map((line) => line.trim().split(/\s+/).at(-1));
|
||||
|
||||
// The keyscan's output lines, "<host> <type> <base64>", as "<type> <base64>". Comment lines and any
|
||||
// other type drop out. A key listed twice counts once.
|
||||
export function scanLines(stdout) {
|
||||
const keys = [];
|
||||
for (const line of stdout.split('\n')) {
|
||||
if (!line || line.startsWith('#')) continue;
|
||||
const parts = line.trim().split(/\s+/);
|
||||
if (parts.length !== 3) continue;
|
||||
const key = parts[1] + ' ' + parts[2];
|
||||
if (HOST_KEY.test(key) && !keys.includes(key)) keys.push(key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
// E1: `ssh-keyscan -T 5 -p <port> -t ed25519,ecdsa,rsa <address>` from the stack host. It reads public
|
||||
// keys and logs in to nothing. A scan that can't start refuses host-failed. One that runs and gets no key,
|
||||
// as from a host that doesn't answer, returns no lines, so the raise refuses host-key-mismatch
|
||||
// (duckworth-0081 N3).
|
||||
export function keyscan(address, port, { bin = 'ssh-keyscan', limitMs = SCAN_MS } = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn(KILL_WITH_PARENT[0], [...KILL_WITH_PARENT.slice(1), bin, '-T', '5', '-p', String(port), '-t', SCAN_TYPES, '--', address], {
|
||||
env: { PATH },
|
||||
detached: true,
|
||||
stdio: ['ignore', 'pipe', 'ignore'],
|
||||
});
|
||||
const out = [];
|
||||
let size = 0;
|
||||
child.stdout.on('data', (chunk) => {
|
||||
size += chunk.length;
|
||||
if (size <= 65536) out.push(chunk);
|
||||
});
|
||||
const timer = setTimeout(() => {
|
||||
try {
|
||||
process.kill(-child.pid, 'SIGKILL');
|
||||
} catch {}
|
||||
}, limitMs);
|
||||
child.on('error', () => (clearTimeout(timer), reject(new BusError('host-failed'))));
|
||||
child.on('close', () => (clearTimeout(timer), resolve(scanLines(Buffer.concat(out).toString('utf8')))));
|
||||
});
|
||||
}
|
||||
|
||||
// E1: the scanned set equals the requested set, or host-key-mismatch.
|
||||
export function sameFingerprints(lines, prints) {
|
||||
const scanned = new Set(lines.map(fingerprint));
|
||||
return scanned.size === prints.length && prints.every((f) => scanned.has(f));
|
||||
}
|
||||
|
||||
const run = (bin, args) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const child = spawn(bin, args, { env: { PATH }, stdio: ['ignore', 'ignore', 'ignore'] });
|
||||
child.on('error', () => reject(new BusError('host-failed')));
|
||||
child.on('close', (code) => (code === 0 ? resolve() : reject(new BusError('host-failed'))));
|
||||
});
|
||||
|
||||
// `installerUser` is the installer's login. Only the tests change it, because a scratch sshd can only
|
||||
// log in as the test's own user.
|
||||
export function hostGrant({ configDir, runRoot, limits = HOST_LIMITS, scan = keyscan, keygen = 'ssh-keygen', installerUser = INSTALLER_USER }) {
|
||||
const keyRoot = join(configDir, 'secrets', 'hosts');
|
||||
const keyPath = (business, hostId) => join(keyRoot, business, hostId, 'installer');
|
||||
const readKey = (business, hostId) => {
|
||||
const file = keyPath(business, hostId);
|
||||
for (const dir of [keyRoot, dirname(dirname(file)), dirname(file)]) privateDir(dir);
|
||||
let fd;
|
||||
try {
|
||||
fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW);
|
||||
return parseHostKey(readFileSync(fd, 'utf8'));
|
||||
} catch (e) {
|
||||
if (e instanceof BusError) throw e;
|
||||
deny('credential-file');
|
||||
} finally {
|
||||
if (fd !== undefined) closeSync(fd);
|
||||
}
|
||||
};
|
||||
// One installer request, `list`, `add` or `remove`, pinned to the record's host keys (E3).
|
||||
const installer = (business, hostId, record, command, signal = null) => {
|
||||
const key = readKey(business, hostId);
|
||||
const entry = { address: record.address, port: record.port, user: installerUser, hostKeys: record.hostKeys };
|
||||
return runHost({ root: runRoot, hostId, entry, key, timeout: 30, limits, command, signal });
|
||||
};
|
||||
const ok = (out) => {
|
||||
if (out.exit !== 0) deny('host-failed');
|
||||
return out;
|
||||
};
|
||||
return {
|
||||
enrollCheck,
|
||||
hostGrantCheck,
|
||||
definitionSha256,
|
||||
sameFingerprints,
|
||||
fingerprint,
|
||||
installerTag,
|
||||
grantTag,
|
||||
keyscan: (address, port) => scan(address, port),
|
||||
// E2 steps 2 and 3. Returns the public line and fingerprint; the private half only reaches the file.
|
||||
async enroll(business, hostId) {
|
||||
mkdirSync(runRoot, { recursive: true, mode: 0o700 });
|
||||
privateDir(runRoot);
|
||||
const dir = mkdtempSync(join(runRoot, 'h-'));
|
||||
try {
|
||||
const tag = installerTag(business, hostId);
|
||||
await run(keygen, ['-q', '-t', 'ed25519', '-N', '', '-C', INSTALLER_USER + '-' + tag.slice('mosaic-'.length), '-f', join(dir, 'key')]);
|
||||
const key = parseHostKey(readFileSync(join(dir, 'key'), 'utf8'));
|
||||
const file = keyPath(business, hostId);
|
||||
mkdirSync(keyRoot, { recursive: true, mode: 0o700 });
|
||||
privateDir(keyRoot);
|
||||
for (const d of [dirname(dirname(file)), dirname(file)]) {
|
||||
if (!privateDir(d, { missing: true })) mkdirSync(d, { mode: 0o700 });
|
||||
privateDir(d);
|
||||
}
|
||||
const tmp = file + '.tmp';
|
||||
try {
|
||||
unlinkSync(tmp);
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') deny('credential-file');
|
||||
}
|
||||
let fd;
|
||||
try {
|
||||
fd = openSync(tmp, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
||||
writeSync(fd, key.text);
|
||||
fsyncSync(fd);
|
||||
} finally {
|
||||
if (fd !== undefined) closeSync(fd);
|
||||
}
|
||||
renameSync(tmp, file);
|
||||
const dirFd = openSync(dirname(file), constants.O_RDONLY);
|
||||
try {
|
||||
fsyncSync(dirFd);
|
||||
} finally {
|
||||
closeSync(dirFd);
|
||||
}
|
||||
return { publicLine: key.publicLine, fingerprint: key.fingerprint, tag };
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
// The X3 undo and hosts.remove: the installer key and its two dirs, if present.
|
||||
unenroll(business, hostId) {
|
||||
const file = keyPath(business, hostId);
|
||||
for (const f of [file + '.tmp', file]) {
|
||||
try {
|
||||
unlinkSync(f);
|
||||
} catch (e) {
|
||||
if (e.code !== 'ENOENT') deny('credential-file');
|
||||
}
|
||||
}
|
||||
for (const d of [dirname(file), dirname(dirname(file))]) {
|
||||
try {
|
||||
rmdirSync(d);
|
||||
} catch (e) {
|
||||
if (!['ENOENT', 'ENOTEMPTY'].includes(e.code)) deny('credential-file');
|
||||
}
|
||||
}
|
||||
},
|
||||
// E4: `list <user>` as mosaic-installer with the installer key and the pinned host keys. A wrong
|
||||
// pin refuses host-key-mismatch (runHost). Returns the installer fingerprint and the exit.
|
||||
async check(business, hostId, record) {
|
||||
const key = readKey(business, hostId);
|
||||
const entry = { address: record.address, port: record.port, user: installerUser, hostKeys: record.hostKeys };
|
||||
const out = await runHost({ root: runRoot, hostId, entry, key, timeout: 30, limits, command: `list ${record.user}` });
|
||||
return { installerFingerprint: key.fingerprint, exit: out.exit };
|
||||
},
|
||||
// X2 step 2: a new ed25519 pair with the tag as its comment, made in a 0700 dir under the run root
|
||||
// and read back into memory. The dir goes before this returns, so no private half stays on disk.
|
||||
async grantKey(tag) {
|
||||
mkdirSync(runRoot, { recursive: true, mode: 0o700 });
|
||||
privateDir(runRoot);
|
||||
const dir = mkdtempSync(join(runRoot, 'h-'));
|
||||
try {
|
||||
await run(keygen, ['-q', '-t', 'ed25519', '-N', '', '-C', tag, '-f', join(dir, 'key')]);
|
||||
return parseHostKey(readFileSync(join(dir, 'key'), 'utf8'));
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
// X2 step 3: `list`, `remove` the tag if it's there, then `add`. Any request that doesn't exit 0
|
||||
// refuses host-failed. `signal` is the executor's claim, so a revoke stops the call.
|
||||
async install(business, hostId, record, tag, publicLine, signal) {
|
||||
const listed = ok(await installer(business, hostId, record, `list ${record.user}`, signal));
|
||||
if (listedTags(listed.stdout).includes(tag)) ok(await installer(business, hostId, record, `remove ${record.user} ${tag}`, signal));
|
||||
ok(await installer(business, hostId, record, `add ${record.user} ${publicLine} ${tag}`, signal));
|
||||
},
|
||||
// X2 step 4: log in as the record's user with the new key and run `true`.
|
||||
async verify(hostId, record, key, signal) {
|
||||
const entry = { address: record.address, port: record.port, user: record.user, hostKeys: record.hostKeys };
|
||||
ok(await runHost({ root: runRoot, hostId, entry, key, timeout: 30, limits, command: 'true', signal }));
|
||||
},
|
||||
// X3's undo and sweep: `remove <user> <tag>`, with no signal, since it runs after an abort too.
|
||||
async remove(business, hostId, record, tag) {
|
||||
ok(await installer(business, hostId, record, `remove ${record.user} ${tag}`));
|
||||
},
|
||||
// X3's sweep (B4): `list <user>`, then `remove` for each listed tag in `tags`. A line with any other
|
||||
// tag stays, so another business's line and an unrecorded one are left alone. Returns the listed
|
||||
// tags and the removed ones.
|
||||
async sweep(business, hostId, record, tags) {
|
||||
const listed = listedTags(ok(await installer(business, hostId, record, `list ${record.user}`)).stdout);
|
||||
const removed = [];
|
||||
for (const tag of listed) {
|
||||
if (!tags.has(tag) || removed.includes(tag)) continue;
|
||||
ok(await installer(business, hostId, record, `remove ${record.user} ${tag}`));
|
||||
removed.push(tag);
|
||||
}
|
||||
return { listed, removed };
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -159,9 +159,7 @@ function runSsh(args, stdin, timeoutMs, signal, limits, onSpawn) {
|
||||
|
||||
// D7: one call. `key` is the parsed entry from credentials.mjs (text and publicLine); `entry` is
|
||||
// the registry's { address, port, user, hostKeys }. `root` is <configDir>/secrets/run.
|
||||
// Row 234 (#1740): `command`, when set, is sent as is in place of the sudo argv. The installer key's
|
||||
// forced command reads it (tools/host/mosaic-keys).
|
||||
export async function runHost({ root, hostId, entry, key, argv, stdin, timeout, signal = null, limits = HOST_LIMITS, command = null }) {
|
||||
export async function runHost({ root, hostId, entry, key, argv, stdin, timeout, signal = null, limits = HOST_LIMITS }) {
|
||||
if (signal?.aborted) deny('credential-unavailable');
|
||||
const dir = mkdtempSync(join(runRoot(root), 'h-'));
|
||||
const sock = join(dir, 'a.sock');
|
||||
@@ -180,7 +178,7 @@ export async function runHost({ root, hostId, entry, key, argv, stdin, timeout,
|
||||
await addKey(sock, key.text, timeout + 30, { limitMs: limits.agentWaitMs, signal });
|
||||
if (signal?.aborted) deny('credential-unavailable');
|
||||
const out = await runSsh(
|
||||
[...sshArgs({ hostId, ...entry, dir }), command ?? remoteCommand(argv)],
|
||||
[...sshArgs({ hostId, ...entry, dir }), remoteCommand(argv)],
|
||||
stdin,
|
||||
timeout * 1000,
|
||||
signal,
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
-- Row 234 (#436a row a, #1740): enrolled hosts and host grants live in the store, written only by
|
||||
-- the grant executor, hosts.check, hosts.remove and revoke, each in the transaction of its event.
|
||||
-- A grant event is an action.allowed whose body.action or body.operation is grant.*; the trigger
|
||||
-- refuses one unless the actor is (NULL, 'grant'), the broker's own grant writer (#436b section 7).
|
||||
CREATE TABLE hosts (
|
||||
business TEXT NOT NULL,
|
||||
host TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
port INTEGER NOT NULL CHECK (port BETWEEN 1 AND 65535),
|
||||
user TEXT NOT NULL,
|
||||
sudo INTEGER NOT NULL CHECK (sudo IN (0,1)),
|
||||
host_keys TEXT NOT NULL CHECK (json_valid(host_keys) AND json_type(host_keys) = 'array' AND json_array_length(host_keys) > 0),
|
||||
installer_fingerprint TEXT,
|
||||
state TEXT NOT NULL CHECK (state IN ('pending-install','ready')),
|
||||
decision TEXT NOT NULL REFERENCES decisions(id),
|
||||
checked_at TEXT,
|
||||
PRIMARY KEY (business, host),
|
||||
CHECK (state = 'pending-install' OR (installer_fingerprint IS NOT NULL AND checked_at IS NOT NULL))
|
||||
) STRICT;
|
||||
CREATE TABLE host_grants (
|
||||
business TEXT NOT NULL,
|
||||
agent TEXT NOT NULL,
|
||||
host TEXT NOT NULL,
|
||||
commands TEXT NOT NULL CHECK (json_valid(commands) AND json_type(commands) = 'array' AND json_array_length(commands) > 0),
|
||||
rotate_by TEXT NOT NULL,
|
||||
tag TEXT NOT NULL CHECK (length(tag) = 39 AND tag GLOB 'mosaic-*' AND NOT substr(tag, 8) GLOB '*[^0-9a-f]*'),
|
||||
decision TEXT NOT NULL REFERENCES decisions(id),
|
||||
PRIMARY KEY (business, agent, host),
|
||||
FOREIGN KEY (business, host) REFERENCES hosts(business, host)
|
||||
) STRICT;
|
||||
CREATE TRIGGER events_grant_actor BEFORE INSERT ON events
|
||||
WHEN NEW.kind = 'action.allowed'
|
||||
AND (json_extract(NEW.body, '$.action') GLOB 'grant.*' OR json_extract(NEW.body, '$.operation') GLOB 'grant.*')
|
||||
AND NOT (NEW.actor_role IS NULL AND NEW.actor_run IS 'grant')
|
||||
BEGIN SELECT RAISE(ABORT, 'only the grant writer records grant events'); END;
|
||||
@@ -16,7 +16,6 @@ import { organizationWriter } from '../../business/src/organization.mjs';
|
||||
import { credentialVerbs } from './credential-verbs.mjs';
|
||||
import { webService } from './web.mjs';
|
||||
import { hostExecutor, sweepRunDir } from './host-run.mjs';
|
||||
import { grantKeys, hostGrant, hostReference, sweepHostKeys } from './host-grant.mjs';
|
||||
import { verifyHuman } from './human.mjs';
|
||||
import { createUsage } from './usage.mjs';
|
||||
import { createLimits } from './limits.mjs';
|
||||
@@ -96,21 +95,8 @@ export async function startBroker({
|
||||
];
|
||||
// Row 199 (#1697, design D1): the per-agent store is <configDir>/secrets/agents.
|
||||
const storeRoot = organization ? join(organization.dir, 'secrets', 'agents') : null;
|
||||
store = new Store(dataRoot);
|
||||
// Row 234 (#1740, r6 X4 third bullet): each host grant record gives its agent a store reference to
|
||||
// host.<id>, so a restart finds the keys the grant executor wrote. The loader refuses host.<id> in a
|
||||
// role's credentials, so these never meet a business-file reference.
|
||||
const granted = new Set();
|
||||
for (const g of store.all('SELECT business, agent, host, rotate_by FROM host_grants ORDER BY business, agent, host')) {
|
||||
granted.add(g.business + '/' + g.agent + '/' + g.host);
|
||||
if (!Object.hasOwn(businesses, g.business)) continue;
|
||||
const refs = (references[g.business + '/' + g.agent] = { ...(references[g.business + '/' + g.agent] ?? {}) });
|
||||
refs['host.' + g.host] = hostReference(storeRoot, g.business, g.agent, g.host, g.rotate_by);
|
||||
}
|
||||
// Row 235 (r6 section 6, N1): a host.<id> key file with no record goes before Credentials loads.
|
||||
for (const entry of sweepHostKeys(storeRoot, Object.keys(businesses), granted))
|
||||
process.stderr.write(`hosts: ${JSON.stringify({ event: 'host-key-swept', ...entry })}\n`);
|
||||
credentials = new Credentials({ references, repoRoots: protectedRoots, dataRoot, storeRoot });
|
||||
store = new Store(dataRoot);
|
||||
// vikunja:19/305: the plug-in switch through the same human-only path as the limits: the verbs
|
||||
// plugins and plugins.set, logged in changes.jsonl with the actor, a missing module refused.
|
||||
const plugins=organization?pluginSettings({dir:organization.dir,rolesDir:organization.rolesDir,exists:hasModule}):null;
|
||||
@@ -126,12 +112,7 @@ export async function startBroker({
|
||||
const limits = createLimits({ store, read: id => settings ? settings.current(id) : businesses[id], log: limitLog });
|
||||
for (const id of Object.keys(businesses)) await limits.refresh(id);
|
||||
const withTokens = (id, result) => ({ ...result, tokens: limits.report(id) });
|
||||
// Row 210 (#1707, design D7 step 6) and row 234 (#1740, r6 E2): the run dir and the host enrollment half.
|
||||
const runRoot = organization ? join(organization.dir, 'secrets', 'run') : null;
|
||||
const broker = new Broker({
|
||||
hostGrant: runRoot ? hostGrant({ configDir: organization.dir, runRoot }) : null,
|
||||
// Row 235 (#1741, r6 X4, X5): the grant executor's claim, register and issue, never use().
|
||||
hostKeys: storeRoot ? grantKeys({ credentials, storeRoot }) : null,
|
||||
usage,
|
||||
limits,
|
||||
store,
|
||||
@@ -200,9 +181,8 @@ export async function startBroker({
|
||||
}
|
||||
const web = await webServices(businesses);
|
||||
// Row 210 (#1707, design D7 step 6): clear what a killed bus child left, before anyone can call.
|
||||
const runRoot = organization ? join(organization.dir, 'secrets', 'run') : null;
|
||||
if (runRoot) sweepRunDir(runRoot);
|
||||
// Row 234 (r6 X3): end the enrollments a killed bus child left, before anyone can call.
|
||||
broker.reconcileGrants();
|
||||
const path = join(store.directory, 'broker.sock');
|
||||
server = await serve({
|
||||
web: (business) => web.get(business) ?? null,
|
||||
@@ -229,9 +209,6 @@ export async function startBroker({
|
||||
return broker.bindTester({ business });
|
||||
},
|
||||
});
|
||||
// Row 235 (r6 X3): the remote undo of interrupted host grants, once the bus is up, so a start doesn't
|
||||
// wait on the network.
|
||||
broker.reconcileHosts();
|
||||
// S6 launcher operations. The host decides capacity and the instance list; the broker
|
||||
// authorizes role.launch and keeps the evidence, refusals included.
|
||||
// A refusal is recorded against the caller, as request() records one.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createServer } from 'node:net';
|
||||
import { lstatSync, chmodSync, unlinkSync } from 'node:fs';
|
||||
import { BusError, TASK_VERBS, WEB_VERBS, HOST_VERBS, HOSTS_VERBS, PROJECT_FILE_VERBS, PROJECT_SAVE_VERB, PROJECT_SAVE_REQUEST_MAX } from './broker.mjs';
|
||||
import { BusError, TASK_VERBS, WEB_VERBS, HOST_VERBS, PROJECT_FILE_VERBS, PROJECT_SAVE_VERB, PROJECT_SAVE_REQUEST_MAX } from './broker.mjs';
|
||||
const LIMIT = 65536;
|
||||
// Row 148: a document save may carry up to 1 MiB of text. Only a request that names that verb near
|
||||
// its start (the proof object comes first) may pass LIMIT; the parsed verb is checked again below.
|
||||
@@ -123,10 +123,7 @@ export async function serve({ broker, path, authenticateHuman = null, authentica
|
||||
// Row138: only project Git effects need an await; preserve every other sync path below.
|
||||
if (r.verb === 'usage.begin' || r.verb === 'usage.end' ||
|
||||
r.verb === 'spec.read' || r.verb === 'record.write' || PROJECT_FILE_VERBS.includes(r.verb) ||
|
||||
// Row 234 (#1740): a grant raise awaits its keyscan, and hosts.check its ssh.
|
||||
HOSTS_VERBS.includes(r.verb) ||
|
||||
(r.verb === 'decision.raise' && (Object.hasOwn(r.args ?? {}, 'spec_path') || Object.hasOwn(r.args ?? {}, 'spec_commit') ||
|
||||
Object.hasOwn(r.args ?? {}, 'grant')))) {
|
||||
(r.verb === 'decision.raise' && (Object.hasOwn(r.args ?? {}, 'spec_path') || Object.hasOwn(r.args ?? {}, 'spec_commit')))) {
|
||||
const own = transient;
|
||||
transient = null;
|
||||
// Local Git may take 100 seconds; keep its result beyond the ordinary idle deadline.
|
||||
|
||||
@@ -13,8 +13,8 @@ import { join, isAbsolute } from 'node:path';
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
const ddl = readFileSync(new URL('../schema.sql', import.meta.url), 'utf8');
|
||||
export const SCHEMA_SHA256 = '0a7b633ce7eec9d0bb37c3255f4244d97bd0c8eac38db91a11b4ef6cc982ec8c';
|
||||
export const SCHEMA_VERSION = '3j';
|
||||
export const SCHEMA_SHA256 = '6cde5232c57ac04dc6073112c0830c89cfc5e953d7a5727e7716263747fe8737';
|
||||
export const SCHEMA_VERSION = '3i';
|
||||
// Ordered, named offline steps. New schema changes append a step and keep prior DDL pinned.
|
||||
const legacyDDL = readFileSync(new URL('./migrations/3b.sql', import.meta.url), 'utf8');
|
||||
const LEGACY_SHA256 = '179ffe356d4ff19a49b5ebad39b6c6bfd7771deb8e1b7c55b5e746f039d69e65';
|
||||
@@ -56,11 +56,6 @@ const migrations = [{
|
||||
from: '3h',
|
||||
to: '3i',
|
||||
sql: readFileSync(new URL('./migrations/3h-3i.sql', import.meta.url), 'utf8'),
|
||||
}, {
|
||||
// Row 234 (#1740): enrolled hosts, host grants and the grant event guard. Only new objects.
|
||||
from: '3i',
|
||||
to: '3j',
|
||||
sql: readFileSync(new URL('./migrations/3i-3j.sql', import.meta.url), 'utf8'),
|
||||
}];
|
||||
const timedTables = [
|
||||
'events',
|
||||
|
||||
@@ -69,7 +69,6 @@ async function engine(root, name, { store, schema, step = (s) => s }) {
|
||||
for (const file of ['3b.sql', '3b-3c.sql', '3c-3d.sql', '3d-3e.sql', '3e-3f.sql', '3f-3g.sql', '3g-3h.sql'])
|
||||
copyFileSync(here('../src/migrations/' + file), join(moduleRoot, 'src/migrations', file));
|
||||
writeFileSync(join(moduleRoot, 'src/migrations/3h-3i.sql'), step(readFileSync(here('../src/migrations/3h-3i.sql'), 'utf8')));
|
||||
copyFileSync(here('../src/migrations/3i-3j.sql'), join(moduleRoot, 'src/migrations/3i-3j.sql'));
|
||||
return (await import(pathToFileURL(join(moduleRoot, 'src/store.mjs')))).Store;
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ test('REQ-LIMIT-4 3h copy migrates to 3i: every row keeps its seq, the sequence
|
||||
const { root, path } = source3h(t), before = snapshot(path), was = master(path);
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
new Store(root, { migrateSchema: true }).close();
|
||||
assert.equal(version(path), '3j');
|
||||
assert.equal(version(path), '3i');
|
||||
// Every table's rows as they were, usage_records with its seq values and sqlite_sequence with 50.
|
||||
assert.deepEqual(snapshot(path, before.columns).rows, before.rows);
|
||||
assert.deepEqual(before.rows.usage_records.map(r => r.seq), [1, 2, 3]);
|
||||
@@ -85,9 +84,7 @@ test('REQ-LIMIT-4 3h copy migrates to 3i: every row keeps its seq, the sequence
|
||||
// sqlite_master as at 3h, the account line aside: same tables, indexes and triggers, same text.
|
||||
const old = ' account TEXT CHECK (account IS NULL),\n';
|
||||
assert.equal(was.filter(r => r.sql?.includes(old)).map(r => r.name).join(), 'usage_records');
|
||||
// Row 234 (#1740) adds 3i→3j's own objects after this step. Its test is grant-migration.test.mjs.
|
||||
const later = ['hosts', 'host_grants', 'events_grant_actor', 'sqlite_autoindex_hosts_1', 'sqlite_autoindex_host_grants_1'];
|
||||
assert.deepEqual(master(path).filter(r => !later.includes(r.name)), was.map(r => r.name === 'usage_records' ? { ...r, sql: r.sql.replace(old, ' account TEXT,\n') } : r));
|
||||
assert.deepEqual(master(path), was.map(r => r.name === 'usage_records' ? { ...r, sql: r.sql.replace(old, ' account TEXT,\n') } : r));
|
||||
assert.equal(was.filter(r => r.type === 'trigger' && r.tbl_name === 'usage_records').length, 3);
|
||||
const store = new Store(root);
|
||||
try {
|
||||
@@ -125,11 +122,11 @@ test('REQ-LIMIT-4 a 3h→3i step that fails partway leaves the store at 3h with
|
||||
assert.deepEqual(snapshot(path, before.columns).rows, before.rows);
|
||||
// Still a whole 3h store: the real step migrates it.
|
||||
new Store(root, { migrateSchema: true }).close();
|
||||
assert.equal(version(path), '3j');
|
||||
assert.equal(version(path), '3i');
|
||||
assert.deepEqual(snapshot(path, before.columns).rows, before.rows);
|
||||
});
|
||||
|
||||
test('REQ-LIMIT-4 the 3h engine refuses a migrated store, migrating or not, and leaves it as it was', async t => {
|
||||
test('REQ-LIMIT-4 the 3h engine refuses a 3i store, migrating or not, and leaves it at 3i', async t => {
|
||||
const { root, path } = source3h(t);
|
||||
new Store(root, { migrateSchema: true }).close();
|
||||
const after = snapshot(path), was = master(path);
|
||||
@@ -137,14 +134,14 @@ test('REQ-LIMIT-4 the 3h engine refuses a migrated store, migrating or not, and
|
||||
schema: ddl3h,
|
||||
store: (source) => source
|
||||
.replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${createHash('sha256').update(ddl3h).digest('hex')}';`)
|
||||
.replace("export const SCHEMA_VERSION = '3j';", "export const SCHEMA_VERSION = '3h';")
|
||||
.replace("export const SCHEMA_VERSION = '3i';", "export const SCHEMA_VERSION = '3h';")
|
||||
.replace(/\}, \{\n {2}\/\/ Row 126 \(#1620\)[\s\S]*?\}\];\nconst timedTables/, '}];\nconst timedTables'),
|
||||
});
|
||||
const pinned = readFileSync(join(root, 'engine-3h/src/store.mjs'), 'utf8');
|
||||
assert.ok(pinned.includes("export const SCHEMA_VERSION = '3h';") && !pinned.includes('3h-3i'), 'the 3h engine has no 3h→3i step');
|
||||
assert.throws(() => new Store3h(root), /schema-mismatch/);
|
||||
assert.throws(() => new Store3h(root, { migrateSchema: true }), /schema-mismatch/);
|
||||
assert.equal(version(path), '3j');
|
||||
assert.equal(version(path), '3i');
|
||||
assert.deepEqual(master(path), was);
|
||||
assert.deepEqual(snapshot(path, after.columns).rows, after.rows);
|
||||
});
|
||||
|
||||
@@ -606,7 +606,7 @@ async function database3c(t) {
|
||||
let source = readFileSync(here('../src/store.mjs'), 'utf8');
|
||||
const pinned = source
|
||||
.replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${createHash('sha256').update(ddl3c).digest('hex')}';`)
|
||||
.replace("export const SCHEMA_VERSION = '3j';", "export const SCHEMA_VERSION = '3c';")
|
||||
.replace("export const SCHEMA_VERSION = '3i';", "export const SCHEMA_VERSION = '3c';")
|
||||
.replace(/\}, \{\n {2}from: '3c',[\s\S]*?\}\];\nconst timedTables/, '}];\nconst timedTables');
|
||||
assert.notEqual(pinned, source);
|
||||
assert.ok(!pinned.includes('3c-3d'), 'the 3c engine has no 3c→3d step');
|
||||
@@ -630,7 +630,7 @@ test('REQ-ROLE-2, REQ-COS-1: the 3c→3d migration lets the chief of staff end a
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
const store = new Store(root, { migrateSchema: true });
|
||||
t.after(() => store.close());
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3j');
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3i');
|
||||
assert.equal(store.get("SELECT body FROM events WHERE id='preserved'").body, '{"fixture":true}');
|
||||
assert.equal(store.get("SELECT holder_run FROM role_claims WHERE role='coder'").holder_run, 'coder-run');
|
||||
const b = new Broker({ store, businesses: demo(), organization: null });
|
||||
|
||||
@@ -33,7 +33,7 @@ test('explicit 3b copy migration preserves evidence and opens as 3g; normal star
|
||||
const original = readFileSync(source);
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
const store = new Store(root, { migrateSchema: true });
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3j');
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3i');
|
||||
assert.equal(store.get("SELECT body FROM events WHERE id='preserved'").body, '{"fixture":true}');
|
||||
assert.equal(store.get('SELECT count(*) n FROM task_comment_cursors').n, 0);
|
||||
const epoch = store.get("SELECT value FROM meta WHERE key='comment_cursor_epoch'").value;
|
||||
@@ -75,15 +75,15 @@ test('named migration registry chains 3b through 3g to a fixture-only future ver
|
||||
const sha = createHash('sha256').update(futureDDL).digest('hex');
|
||||
let source = readFileSync(new URL('../src/store.mjs', import.meta.url), 'utf8');
|
||||
source = source.replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${sha}';`)
|
||||
.replace("export const SCHEMA_VERSION = '3j';", "export const SCHEMA_VERSION = '3k';")
|
||||
.replace('}];\nconst timedTables', `}, { from: '3j', to: '3k', sql: ${JSON.stringify(futureSQL)} }];\nconst timedTables`);
|
||||
.replace("export const SCHEMA_VERSION = '3i';", "export const SCHEMA_VERSION = '3j';")
|
||||
.replace('}];\nconst timedTables', `}, { from: '3i', to: '3j', sql: ${JSON.stringify(futureSQL)} }];\nconst timedTables`);
|
||||
writeFileSync(join(moduleRoot, 'src/store.mjs'), source);
|
||||
writeFileSync(join(moduleRoot, 'schema.sql'), futureDDL);
|
||||
for (const name of ['3b.sql', '3b-3c.sql', '3c-3d.sql', '3d-3e.sql', '3e-3f.sql', '3f-3g.sql', '3g-3h.sql', '3h-3i.sql', '3i-3j.sql'])
|
||||
for (const name of ['3b.sql', '3b-3c.sql', '3c-3d.sql', '3d-3e.sql', '3e-3f.sql', '3f-3g.sql', '3g-3h.sql', '3h-3i.sql'])
|
||||
copyFileSync(new URL('../src/migrations/' + name, import.meta.url), join(moduleRoot, 'src/migrations', name));
|
||||
const { Store: FutureStore } = await import(pathToFileURL(join(moduleRoot, 'src/store.mjs')));
|
||||
const future = new FutureStore(root, { migrateSchema: true });
|
||||
assert.equal(future.get("SELECT value FROM meta WHERE key='schema_version'").value, '3k');
|
||||
assert.equal(future.get("SELECT value FROM meta WHERE key='schema_version'").value, '3j');
|
||||
assert.equal(future.get("SELECT name FROM sqlite_master WHERE name='future_fixture'").name, 'future_fixture');
|
||||
assert.equal(future.get("SELECT count(*) n FROM task_comment_cursors").n, 0);
|
||||
assert.equal(future.get("SELECT id FROM events").id, 'preserved');
|
||||
@@ -109,7 +109,7 @@ test('offline command migrates only the supplied fixture root and reports usage
|
||||
const command = new URL('../src/migrate-schema.mjs', import.meta.url).pathname;
|
||||
const migrated = spawnSync(process.execPath, [command, root], { encoding: 'utf8' });
|
||||
assert.equal(migrated.status, 0, migrated.stderr);
|
||||
assert.match(migrated.stdout, /bus schema 3j ready/);
|
||||
assert.match(migrated.stdout, /bus schema 3i ready/);
|
||||
new Store(root).close();
|
||||
const usage = spawnSync(process.execPath, [command], { encoding: 'utf8' });
|
||||
assert.equal(usage.status, 2);
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { Store } from '../src/store.mjs';
|
||||
import { Broker } from '../src/broker.mjs';
|
||||
import { startBroker } from '../src/runtime.mjs';
|
||||
import { businessDoc, rolesCopy, systemFor, writeJson } from '../../business/tests/helpers.mjs';
|
||||
|
||||
// Row 213 (C2-08, #1714, Case 2 design 5.1): a creative instance talks with the user only, and it has
|
||||
// no decision channel (M6). The messaging lists are read from the shipped role files.
|
||||
const shipped = (name) =>
|
||||
JSON.parse(readFileSync(fileURLToPath(new URL(`../../../roles/${name}.json`, import.meta.url)), 'utf8'));
|
||||
|
||||
const within = { authority: { withinRole: ['message.send'], crossRole: [] } };
|
||||
const roles = {
|
||||
chief: { definition: 'chief-of-staff', ...within },
|
||||
assistant: { definition: 'assistant', ...within },
|
||||
pm: { definition: 'pm', ...within },
|
||||
bean: { definition: 'companion', ...within },
|
||||
quill: { definition: 'proofreader', ...within },
|
||||
};
|
||||
const definitions = {
|
||||
'chief-of-staff': {},
|
||||
assistant: { messaging: shipped('assistant').messaging },
|
||||
pm: {},
|
||||
companion: { messaging: shipped('companion').messaging },
|
||||
proofreader: { messaging: shipped('proofreader').messaging },
|
||||
};
|
||||
|
||||
function setup(t) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'bus-creative-'));
|
||||
const store = new Store(root);
|
||||
t.after(() => {
|
||||
store.close();
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
});
|
||||
const b = new Broker({ store, businesses: { demo: {
|
||||
id: 'demo', human: 'jason', arbiters: { technical: 'pm', delivery: 'chief' }, roles, definitions,
|
||||
projects: { stack: { root: '/nonexistent' } }, vars: { 'bus.tester': true },
|
||||
} } });
|
||||
const caps = {};
|
||||
caps.human = b.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
||||
const project = b.request(caps.human, { verb: 'project.create', args: { name: 'demo' } }).id;
|
||||
const thread = b.request(caps.human, { verb: 'thread.create', args: { project, name: 'main' } }).id;
|
||||
for (const role of Object.keys(roles)) {
|
||||
caps[role] = b.bindLaunch({ business: 'demo', role, run: `${role}-run`, harness: 'pi', ...(role === 'assistant' ? { thread } : {}) });
|
||||
b.request(caps[role], { verb: 'role.claim' });
|
||||
}
|
||||
caps.tester = b.bindTester({ business: 'demo' });
|
||||
const call = (who, verb, args = {}) => b.request(caps[who], { verb, args });
|
||||
const count = (sql) => store.get(sql).n;
|
||||
return { call, count, store };
|
||||
}
|
||||
|
||||
const raise = { action: 'policy.change', question: 'Change?', options: [{ key: 'yes', text: 'Yes' }, { key: 'no', text: 'No' }], recommendation: 'yes', blocking: false };
|
||||
|
||||
test('M6: a creative raise refuses decision-not-allowed, cited or not, and no decision row appears; the assistant still raises', (t) => {
|
||||
const { call, count } = setup(t);
|
||||
for (const who of ['bean', 'quill']) {
|
||||
assert.throws(() => call(who, 'decision.raise', raise), { code: 'decision-not-allowed' }, who);
|
||||
// The refusal comes before the spec-cited path, so a cited raise never reaches the project.
|
||||
assert.throws(() => call(who, 'decision.raise', { ...raise, project: 'stack', spec_path: 'spec/north-star.md', spec_commit: 'a'.repeat(40) }),
|
||||
{ code: 'decision-not-allowed' }, `${who} cited`);
|
||||
}
|
||||
assert.equal(count('SELECT count(*) n FROM decisions'), 0);
|
||||
const d = call('assistant', 'decision.raise', raise);
|
||||
assert.match(String(d.id), /./);
|
||||
assert.equal(count('SELECT count(*) n FROM decisions'), 1);
|
||||
});
|
||||
|
||||
test('a creative instance sends only to the user and hears only from the user', (t) => {
|
||||
const { call, count } = setup(t);
|
||||
for (const who of ['bean', 'quill']) {
|
||||
call(who, 'message.send', { to: 'human', body: 'hello' });
|
||||
for (const to of ['chief', 'assistant', 'pm', 'bean', 'quill'].filter((n) => n !== who)) {
|
||||
assert.throws(() => call(who, 'message.send', { to, body: 'hello' }), { code: 'message-recipient-refused' }, `${who} to ${to}`);
|
||||
}
|
||||
for (const from of ['chief', 'pm']) {
|
||||
assert.throws(() => call(from, 'message.send', { to: who, body: 'hello' }), { code: 'message-sender-refused' }, `${from} to ${who}`);
|
||||
}
|
||||
call('human', 'message.send', { to: who, body: 'hello' });
|
||||
}
|
||||
assert.equal(count("SELECT count(*) n FROM messages WHERE from_role IN ('bean','quill')"), 2);
|
||||
assert.equal(count("SELECT count(*) n FROM messages WHERE to_role IN ('bean','quill')"), 2);
|
||||
});
|
||||
|
||||
// M10 through the broker (webby-0040 B1): the broker names the actor from the session, so these cases
|
||||
// pin that a chief session reaches the writer as chief-of-staff.chief and a tester session as tester.
|
||||
// A real organization file and writer, as tester-writes.test.mjs.
|
||||
async function runtime(t) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'bus-creative-m10-'));
|
||||
const rolesDir = rolesCopy(root);
|
||||
const doc = businessDoc(root, 'demo');
|
||||
doc.plugins = { ...doc.plugins, harness: ['pi'] };
|
||||
doc.roles.bean = { definition: 'companion' };
|
||||
for (const r of Object.values(doc.roles)) r.vars = { harness: 'pi', model: 'claude-sonnet-5-5', thinking: 'high', ...r.vars };
|
||||
// Only bean names the sonnet key, so the chief may still change every other key.
|
||||
for (const [name, r] of Object.entries(doc.roles)) if (name !== 'bean') r.vars.model = 'claude-opus-5-5';
|
||||
const file = join(root, 'businesses/demo.json');
|
||||
writeJson(file, doc);
|
||||
mkdirSync(join(root, 'data'), { mode: 0o700 });
|
||||
const bus = await startBroker({
|
||||
dataRoot: join(root, 'data'),
|
||||
businesses: {
|
||||
demo: {
|
||||
id: 'demo', human: 'jason', arbiters: { technical: 'chief', delivery: 'chief' }, vars: { 'bus.tester': true },
|
||||
plugins: { harness: ['pi'] },
|
||||
roles: { chief: { definition: 'chief-of-staff', authority: shipped('chief-of-staff').authority }, bean: { definition: 'companion', ...within } },
|
||||
},
|
||||
},
|
||||
organization: { dir: root, rolesDir, system: systemFor(root) },
|
||||
});
|
||||
t.after(async () => { await bus.close(); rmSync(root, { recursive: true, force: true }); });
|
||||
const b = bus.broker;
|
||||
const human = b.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
||||
const tester = b.bindTester({ business: 'demo' });
|
||||
const chief = b.bindLaunch({ business: 'demo', role: 'chief', run: 'chief-run', harness: 'pi' });
|
||||
b.request(chief, { verb: 'role.claim' });
|
||||
const call = (cap, verb, args = {}) => b.request(cap, { verb, args });
|
||||
const history = join(root, 'businesses/.history/demo/changes.jsonl');
|
||||
const log = () => (existsSync(history) ? readFileSync(history, 'utf8').trim().split('\n').filter(Boolean).map(JSON.parse) : []);
|
||||
const bytes = () => readFileSync(file, 'utf8');
|
||||
return { human, tester, chief, call, log, bytes };
|
||||
}
|
||||
|
||||
test('M10 through the broker: the chief and the tester are refused on bean, the human\'s limits.set of its models key works', async (t) => {
|
||||
const { human, tester, chief, call, log, bytes } = await runtime(t);
|
||||
const { revision, models } = call(human, 'limits');
|
||||
const changed = { ...models, 'claude-sonnet-5-5': { ...models['claude-sonnet-5-5'], model: 'claude-sonnet-5-5-next' } };
|
||||
const before = bytes();
|
||||
// The chief of staff's organization.set reaches the writer as chief-of-staff.chief and is refused there.
|
||||
assert.throws(() => call(chief, 'organization.set', { revision, models: changed }), { code: 'organization-creative-human-only' });
|
||||
assert.throws(() => call(chief, 'organization.set', { revision, instances: { bean: 'claude-opus-5-5' } }), { code: 'organization-creative-instance' });
|
||||
// The tester never reaches the writer through these two verbs (webby-0040 N5).
|
||||
assert.throws(() => call(tester, 'organization.set', { revision, models: changed }), { code: 'tester-refused' });
|
||||
assert.throws(() => call(tester, 'limits.set', { revision, models: changed }), { code: 'tester-refused' });
|
||||
// Its instances.set and routes.set do reach the writer, as tester, and are refused there.
|
||||
assert.throws(() => call(tester, 'instances.set', { revision, instance: 'bean', op: 'change', vars: { thinking: 'low' } }),
|
||||
{ code: 'organization-creative-human-only' });
|
||||
assert.throws(() => call(tester, 'instances.set', { revision, instance: 'muse', op: 'add', definition: 'ideas' }),
|
||||
{ code: 'organization-creative-human-only' });
|
||||
assert.throws(() => call(tester, 'routes.set', { revision, routes: { bean: { harness: 'pi', model: 'claude-opus-5-5', thinking: 'high', fallback: null } } }),
|
||||
{ code: 'organization-creative-human-only' });
|
||||
assert.equal(bytes(), before);
|
||||
assert.deepEqual(log().filter((e) => e.state === 'committed'), []);
|
||||
// The human's limits.set of the same change lands, logged with the human as actor.
|
||||
call(human, 'limits.set', { revision, models: changed });
|
||||
assert.equal(JSON.parse(bytes()).launch.models['claude-sonnet-5-5'].model, 'claude-sonnet-5-5-next');
|
||||
assert.deepEqual(log().filter((e) => e.state === 'committed').map((e) => e.actor), ['jason']);
|
||||
});
|
||||
@@ -1,152 +0,0 @@
|
||||
// Row 235 (#1741, #436 row b, r6 X4, X5): the grant executor's Credentials calls. register and
|
||||
// unregister add and drop one store reference in the running bus, and claim, release and abortClaim
|
||||
// hold the (agent, host.<id>) slot that host.run and revoke share. Keys are made by ssh-keygen in a
|
||||
// scratch root, and nothing connects to any host.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { Credentials } from '../src/credentials.mjs';
|
||||
|
||||
const AGENT = 'demo/ops';
|
||||
const SERVICE = 'host.web1';
|
||||
|
||||
function setup(t) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'bus-claim-'));
|
||||
t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||
const storeRoot = join(root, 'secrets', 'agents');
|
||||
mkdirSync(storeRoot, { recursive: true, mode: 0o700 });
|
||||
chmodSync(join(root, 'secrets'), 0o700);
|
||||
const file = join(storeRoot, 'demo', 'ops', SERVICE);
|
||||
const ref = { service: SERVICE, store: true, file, rotateBy: '2099-01-01' };
|
||||
const key = (name) => {
|
||||
execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-C', 'test', '-f', join(root, name)]);
|
||||
return readFileSync(join(root, name), 'utf8');
|
||||
};
|
||||
const c = new Credentials({ references: {}, storeRoot, repoRoots: [], dataRoot: '/nonexistent-data' });
|
||||
t.after(() => c.close());
|
||||
const state = () => c.status().find((e) => e.instance === AGENT && e.service === SERVICE)?.state;
|
||||
const run = () => c.use(AGENT, SERVICE, async () => ({ ok: true }));
|
||||
return { root, storeRoot, file, ref, key, c, state, run };
|
||||
}
|
||||
|
||||
test('X4: register adds a store reference to the running bus, and issue then writes the key', async (t) => {
|
||||
const s = setup(t);
|
||||
assert.throws(() => s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01'), /credential-unknown/);
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
assert.equal(s.state(), 'not-issued');
|
||||
await assert.rejects(s.run(), /credential-unavailable/);
|
||||
assert.equal(s.c.issue(AGENT, SERVICE, s.key('k2'), '2099-01-01').state, 'valid');
|
||||
assert.deepEqual(await s.run(), { ok: true });
|
||||
});
|
||||
|
||||
test('X4: register runs the constructor\'s reference checks', (t) => {
|
||||
const s = setup(t);
|
||||
const other = join(s.storeRoot, 'demo', 'pm', SERVICE);
|
||||
for (const [ref, code] of [
|
||||
[null, /credential-reference/],
|
||||
[{ ...s.ref, rotateBy: '2099-02-30' }, /credential-date/],
|
||||
[{ ...s.ref, file: other }, /credential-reference/],
|
||||
[{ ...s.ref, extra: 1 }, /credential-reference/],
|
||||
[{ ...s.ref, service: 'host.web2' }, /credential-reference/],
|
||||
[{ ...s.ref, env: 'X' }, /credential-reference/],
|
||||
])
|
||||
assert.throws(() => s.c.register(AGENT, SERVICE, ref), code);
|
||||
assert.throws(() => s.c.register(AGENT, 'nope', s.ref), /credential-reference/);
|
||||
assert.throws(() => s.c.register('demo/@tester', SERVICE, { ...s.ref, file: join(s.storeRoot, 'demo', '@tester', SERVICE) }), /credential-reference/);
|
||||
assert.equal(s.state(), undefined);
|
||||
});
|
||||
|
||||
test('X4: register reads no file, so a key file left at the path stays unused, and a live token refuses', async (t) => {
|
||||
const s = setup(t);
|
||||
mkdirSync(join(s.storeRoot, 'demo', 'ops'), { recursive: true, mode: 0o700 });
|
||||
writeFileSync(s.file, s.key('left'), { mode: 0o600 });
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
assert.equal(s.state(), 'not-issued');
|
||||
await assert.rejects(s.run(), /credential-unavailable/);
|
||||
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
|
||||
assert.throws(() => s.c.register(AGENT, SERVICE, s.ref), /credential-reference/);
|
||||
assert.equal(s.state(), 'valid');
|
||||
// A revoked entry has no token, so a new grant registers again.
|
||||
s.c.revoke(AGENT, SERVICE);
|
||||
assert.equal(s.state(), 'revoked');
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
assert.equal(s.state(), 'not-issued');
|
||||
});
|
||||
|
||||
test('X3, X4: unregister drops an entry with no token and refuses one with a live token', (t) => {
|
||||
const s = setup(t);
|
||||
s.c.unregister(AGENT, SERVICE);
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
s.c.unregister(AGENT, SERVICE);
|
||||
assert.equal(s.state(), undefined);
|
||||
assert.throws(() => s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01'), /credential-unknown/);
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
s.c.issue(AGENT, SERVICE, s.key('k2'), '2099-01-01');
|
||||
assert.throws(() => s.c.unregister(AGENT, SERVICE), /credential-reference/);
|
||||
assert.equal(s.state(), 'valid');
|
||||
s.c.revoke(AGENT, SERVICE);
|
||||
assert.equal(existsSync(s.file), false);
|
||||
s.c.unregister(AGENT, SERVICE);
|
||||
assert.equal(s.state(), undefined);
|
||||
});
|
||||
|
||||
test('X5: a claim holds the slot, so a second claim and a host.run refuse host-busy until release', async (t) => {
|
||||
const s = setup(t);
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
|
||||
const signal = s.c.claim(AGENT, SERVICE);
|
||||
assert.equal(signal.aborted, false);
|
||||
assert.equal(s.c.busy(AGENT, SERVICE), true);
|
||||
assert.throws(() => s.c.claim(AGENT, SERVICE), /host-busy/);
|
||||
await assert.rejects(s.run(), /host-busy/);
|
||||
// A claim needs no reference: the executor claims before it registers a new key.
|
||||
const other = s.c.claim('demo/pm', SERVICE);
|
||||
s.c.release('demo/pm', SERVICE, other);
|
||||
s.c.release(AGENT, SERVICE, signal);
|
||||
assert.equal(s.c.busy(AGENT, SERVICE), false);
|
||||
assert.deepEqual(await s.run(), { ok: true });
|
||||
});
|
||||
|
||||
test('X5: a claim made while a host.run is in flight refuses host-busy', async (t) => {
|
||||
const s = setup(t);
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
|
||||
let finish;
|
||||
const running = s.c.use(AGENT, SERVICE, () => new Promise((r) => (finish = r)));
|
||||
assert.throws(() => s.c.claim(AGENT, SERVICE), /host-busy/);
|
||||
finish({ ok: true });
|
||||
assert.deepEqual(await running, { ok: true });
|
||||
s.c.release(AGENT, SERVICE, s.c.claim(AGENT, SERVICE));
|
||||
});
|
||||
|
||||
test('X5: a stale release leaves a later claim in place', (t) => {
|
||||
const s = setup(t);
|
||||
const first = s.c.claim(AGENT, SERVICE);
|
||||
s.c.release(AGENT, SERVICE, first);
|
||||
const second = s.c.claim(AGENT, SERVICE);
|
||||
s.c.release(AGENT, SERVICE, first);
|
||||
s.c.release(AGENT, SERVICE);
|
||||
assert.equal(s.c.busy(AGENT, SERVICE), true);
|
||||
s.c.release(AGENT, SERVICE, second);
|
||||
assert.equal(s.c.busy(AGENT, SERVICE), false);
|
||||
});
|
||||
|
||||
test('X5: abortClaim aborts a live claim and says pending, and revoke\'s abort reaches a claim too', (t) => {
|
||||
const s = setup(t);
|
||||
assert.deepEqual(s.c.abortClaim(AGENT, SERVICE), { pending: false });
|
||||
const signal = s.c.claim(AGENT, SERVICE);
|
||||
assert.deepEqual(s.c.abortClaim(AGENT, SERVICE), { pending: true });
|
||||
assert.equal(signal.aborted, true);
|
||||
// The slot stays held until the executor releases it.
|
||||
assert.equal(s.c.busy(AGENT, SERVICE), true);
|
||||
s.c.release(AGENT, SERVICE, signal);
|
||||
s.c.register(AGENT, SERVICE, s.ref);
|
||||
s.c.issue(AGENT, SERVICE, s.key('k1'), '2099-01-01');
|
||||
const live = s.c.claim(AGENT, SERVICE);
|
||||
s.c.revoke(AGENT, SERVICE);
|
||||
assert.equal(live.aborted, true);
|
||||
s.c.release(AGENT, SERVICE, live);
|
||||
});
|
||||
-365
@@ -1,365 +0,0 @@
|
||||
PRAGMA journal_mode = WAL;
|
||||
PRAGMA foreign_keys = ON;
|
||||
CREATE TABLE meta (key TEXT PRIMARY KEY, value TEXT NOT NULL) STRICT;
|
||||
CREATE TABLE events (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id TEXT NOT NULL UNIQUE,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
kind TEXT NOT NULL CHECK (kind IN (
|
||||
'session.launched',
|
||||
'session.ended',
|
||||
'action.allowed',
|
||||
'action.refused',
|
||||
'task.created',
|
||||
'task.assigned',
|
||||
'task.state',
|
||||
'task.closed',
|
||||
'task.changed.external',
|
||||
'task.conflict',
|
||||
'task.missing',
|
||||
'review.requested',
|
||||
'review.verdict',
|
||||
'human.input',
|
||||
'config.refused',
|
||||
'credential.expiring',
|
||||
'credential.expired',
|
||||
'credential.changed',
|
||||
'launch.revoked',
|
||||
'launch.restored',
|
||||
'digest.sent')),
|
||||
actor_role TEXT, actor_run TEXT,
|
||||
subject TEXT,
|
||||
corrects TEXT REFERENCES events(id),
|
||||
body TEXT NOT NULL CHECK (json_valid(body))
|
||||
) STRICT;
|
||||
CREATE TABLE role_claims (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL, role TEXT NOT NULL,
|
||||
op TEXT NOT NULL CHECK (op IN ('claim','release','revoke')),
|
||||
holder_run TEXT NOT NULL,
|
||||
harness TEXT NOT NULL, address TEXT,
|
||||
by TEXT NOT NULL, reason TEXT,
|
||||
decision TEXT
|
||||
) STRICT;
|
||||
CREATE TABLE decisions (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id TEXT NOT NULL UNIQUE,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL, project TEXT,
|
||||
raised_by_role TEXT NOT NULL, raised_by_run TEXT NOT NULL,
|
||||
class TEXT NOT NULL CHECK (class IN ('routine','within-role','cross-role','gated')),
|
||||
action TEXT NOT NULL,
|
||||
route_to TEXT NOT NULL,
|
||||
question TEXT NOT NULL,
|
||||
options TEXT NOT NULL CHECK (json_valid(options) AND json_array_length(options) BETWEEN 2 AND 9),
|
||||
recommendation TEXT NOT NULL,
|
||||
task_ref TEXT CHECK (task_ref IS NULL OR (task_ref GLOB 'vikunja:[1-9]*/[1-9]*' AND NOT substr(task_ref, 9) GLOB '*[^0-9/]*' AND NOT substr(task_ref, 9) GLOB '*/*/*')), requirement_ref TEXT,
|
||||
blocking INTEGER NOT NULL CHECK (blocking IN (0,1)),
|
||||
supersedes TEXT REFERENCES decisions(id)
|
||||
, spec_path TEXT, spec_commit TEXT) STRICT;
|
||||
CREATE TABLE decision_events (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
decision TEXT NOT NULL REFERENCES decisions(id),
|
||||
at TEXT NOT NULL,
|
||||
op TEXT NOT NULL CHECK (op IN ('seen','resolved','withdrawn','expired')),
|
||||
by TEXT NOT NULL,
|
||||
choice TEXT, note TEXT, via TEXT
|
||||
) STRICT;
|
||||
CREATE TABLE messages (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id TEXT NOT NULL UNIQUE,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
from_role TEXT NOT NULL, from_run TEXT NOT NULL,
|
||||
to_role TEXT NOT NULL,
|
||||
class TEXT NOT NULL,
|
||||
in_reply_to TEXT REFERENCES messages(id),
|
||||
decision TEXT REFERENCES decisions(id),
|
||||
corrects TEXT REFERENCES messages(id),
|
||||
body TEXT NOT NULL
|
||||
, to_name TEXT) STRICT;
|
||||
CREATE TABLE deliveries (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
message TEXT NOT NULL REFERENCES messages(id),
|
||||
at TEXT NOT NULL,
|
||||
op TEXT NOT NULL CHECK (op IN ('routed','delivered','failed','read')),
|
||||
holder_run TEXT, transport TEXT, address TEXT, detail TEXT
|
||||
) STRICT;
|
||||
CREATE TABLE task_snapshots (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
task_ref TEXT NOT NULL CHECK (task_ref GLOB 'vikunja:[1-9]*/[1-9]*' AND NOT substr(task_ref, 9) GLOB '*[^0-9/]*' AND NOT substr(task_ref, 9) GLOB '*/*/*'),
|
||||
updated TEXT NOT NULL,
|
||||
etag TEXT,
|
||||
digest TEXT NOT NULL CHECK (length(digest) = 64 AND NOT digest GLOB '*[^0-9a-f]*'),
|
||||
fields TEXT NOT NULL CHECK (json_valid(fields)),
|
||||
source TEXT NOT NULL CHECK (source IN ('self','poll')),
|
||||
via TEXT CHECK (via IN ('board','cursor','task','reconcile')),
|
||||
read_at TEXT,
|
||||
role TEXT, run TEXT,
|
||||
CHECK ((source = 'self') = (role IS NOT NULL AND run IS NOT NULL)),
|
||||
CHECK ((source = 'poll') = (via IS NOT NULL AND read_at IS NOT NULL)),
|
||||
CHECK (json_type(fields, '$.bucket') IS 'integer'
|
||||
OR (source IS 'poll' AND via IS 'task' AND json_type(fields, '$.gone') IS 'text'))
|
||||
) STRICT;
|
||||
CREATE INDEX task_snapshots_ref ON task_snapshots (business, task_ref, seq);
|
||||
CREATE TRIGGER decisions_resolve_once BEFORE INSERT ON decision_events
|
||||
WHEN NEW.op IN ('resolved','withdrawn','expired') AND EXISTS (
|
||||
SELECT 1 FROM decision_events WHERE decision = NEW.decision AND op IN ('resolved','withdrawn','expired'))
|
||||
BEGIN SELECT RAISE(ABORT, 'decision already closed'); END;
|
||||
CREATE TRIGGER decisions_resolved_choice BEFORE INSERT ON decision_events
|
||||
WHEN NEW.op = 'resolved' AND (NEW.choice IS NULL OR NOT EXISTS (
|
||||
SELECT 1 FROM decisions d, json_each(d.options) o WHERE d.id = NEW.decision AND json_extract(o.value,'$.key') = NEW.choice))
|
||||
BEGIN SELECT RAISE(ABORT, 'resolution must name one of the options'); END;
|
||||
CREATE TRIGGER role_one_holder BEFORE INSERT ON role_claims
|
||||
WHEN NEW.op = 'claim' AND (SELECT op FROM role_claims WHERE business = NEW.business AND role = NEW.role ORDER BY seq DESC LIMIT 1) = 'claim'
|
||||
BEGIN SELECT RAISE(ABORT, 'role already held'); END;
|
||||
CREATE TRIGGER role_release_by_holder BEFORE INSERT ON role_claims
|
||||
WHEN NEW.op IN ('release','revoke') AND COALESCE((SELECT op FROM role_claims WHERE business = NEW.business AND role = NEW.role ORDER BY seq DESC LIMIT 1),'') <> 'claim'
|
||||
BEGIN SELECT RAISE(ABORT, 'role is not held'); END;
|
||||
CREATE TRIGGER role_release_same_run BEFORE INSERT ON role_claims
|
||||
WHEN NEW.op = 'release' AND (SELECT holder_run FROM role_claims WHERE business = NEW.business AND role = NEW.role ORDER BY seq DESC LIMIT 1) <> NEW.holder_run
|
||||
BEGIN SELECT RAISE(ABORT, 'only the holder releases; others revoke'); END;
|
||||
CREATE TRIGGER role_revoke_needs_decision BEFORE INSERT ON role_claims
|
||||
WHEN NEW.op = 'revoke' AND NEW.decision IS NULL AND NEW.reason IS NULL
|
||||
BEGIN SELECT RAISE(ABORT, 'revoke needs a resolved decision or a reason'); END;
|
||||
CREATE TRIGGER meta_no_update BEFORE UPDATE ON meta BEGIN SELECT RAISE(ABORT, 'meta is append-only'); END;
|
||||
CREATE TRIGGER meta_no_delete BEFORE DELETE ON meta BEGIN SELECT RAISE(ABORT, 'meta is append-only'); END;
|
||||
CREATE TRIGGER events_no_update BEFORE UPDATE ON events BEGIN SELECT RAISE(ABORT, 'events is append-only'); END;
|
||||
CREATE TRIGGER events_no_delete BEFORE DELETE ON events BEGIN SELECT RAISE(ABORT, 'events is append-only'); END;
|
||||
CREATE TRIGGER role_claims_no_update BEFORE UPDATE ON role_claims BEGIN SELECT RAISE(ABORT, 'role_claims is append-only'); END;
|
||||
CREATE TRIGGER role_claims_no_delete BEFORE DELETE ON role_claims BEGIN SELECT RAISE(ABORT, 'role_claims is append-only'); END;
|
||||
CREATE TRIGGER decisions_no_update BEFORE UPDATE ON decisions BEGIN SELECT RAISE(ABORT, 'decisions is append-only'); END;
|
||||
CREATE TRIGGER decisions_no_delete BEFORE DELETE ON decisions BEGIN SELECT RAISE(ABORT, 'decisions is append-only'); END;
|
||||
CREATE TRIGGER decision_events_no_update BEFORE UPDATE ON decision_events BEGIN SELECT RAISE(ABORT, 'decision_events is append-only'); END;
|
||||
CREATE TRIGGER decision_events_no_delete BEFORE DELETE ON decision_events BEGIN SELECT RAISE(ABORT, 'decision_events is append-only'); END;
|
||||
CREATE TRIGGER messages_no_update BEFORE UPDATE ON messages BEGIN SELECT RAISE(ABORT, 'messages is append-only'); END;
|
||||
CREATE TRIGGER messages_no_delete BEFORE DELETE ON messages BEGIN SELECT RAISE(ABORT, 'messages is append-only'); END;
|
||||
CREATE TRIGGER deliveries_no_update BEFORE UPDATE ON deliveries BEGIN SELECT RAISE(ABORT, 'deliveries is append-only'); END;
|
||||
CREATE TRIGGER deliveries_no_delete BEFORE DELETE ON deliveries BEGIN SELECT RAISE(ABORT, 'deliveries is append-only'); END;
|
||||
CREATE TRIGGER meta_no_replace BEFORE INSERT ON meta WHEN EXISTS (SELECT 1 FROM meta WHERE key = NEW.key) BEGIN SELECT RAISE(ABORT, 'meta is append-only'); END;
|
||||
CREATE TRIGGER events_no_replace BEFORE INSERT ON events WHEN EXISTS (SELECT 1 FROM events WHERE seq = NEW.seq OR id = NEW.id) BEGIN SELECT RAISE(ABORT, 'events is append-only'); END;
|
||||
CREATE TRIGGER role_claims_no_replace BEFORE INSERT ON role_claims WHEN EXISTS (SELECT 1 FROM role_claims WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'role_claims is append-only'); END;
|
||||
CREATE TRIGGER decisions_no_replace BEFORE INSERT ON decisions WHEN EXISTS (SELECT 1 FROM decisions WHERE seq = NEW.seq OR id = NEW.id) BEGIN SELECT RAISE(ABORT, 'decisions is append-only'); END;
|
||||
CREATE TRIGGER decision_events_no_replace BEFORE INSERT ON decision_events WHEN EXISTS (SELECT 1 FROM decision_events WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'decision_events is append-only'); END;
|
||||
CREATE TRIGGER messages_no_replace BEFORE INSERT ON messages WHEN EXISTS (SELECT 1 FROM messages WHERE seq = NEW.seq OR id = NEW.id) BEGIN SELECT RAISE(ABORT, 'messages is append-only'); END;
|
||||
CREATE TRIGGER deliveries_no_replace BEFORE INSERT ON deliveries WHEN EXISTS (SELECT 1 FROM deliveries WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'deliveries is append-only'); END;
|
||||
CREATE TRIGGER task_snapshots_no_update BEFORE UPDATE ON task_snapshots BEGIN SELECT RAISE(ABORT, 'task_snapshots is append-only'); END;
|
||||
CREATE TRIGGER task_snapshots_no_delete BEFORE DELETE ON task_snapshots BEGIN SELECT RAISE(ABORT, 'task_snapshots is append-only'); END;
|
||||
CREATE TRIGGER task_snapshots_no_replace BEFORE INSERT ON task_snapshots WHEN EXISTS (SELECT 1 FROM task_snapshots WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'task_snapshots is append-only'); END;
|
||||
CREATE TRIGGER decisions_blocking_needs_task BEFORE INSERT ON decisions
|
||||
WHEN NEW.blocking = 1 AND NEW.task_ref IS NULL
|
||||
BEGIN SELECT RAISE(ABORT, 'a blocking decision cites the task it blocks'); END;
|
||||
CREATE TRIGGER events_launch_by_human BEFORE INSERT ON events
|
||||
WHEN NEW.kind IN ('launch.revoked','launch.restored') AND (NEW.actor_role IS NOT NULL OR NEW.actor_run IS NOT NULL)
|
||||
BEGIN SELECT RAISE(ABORT, 'only the human revokes or restores launching'); END;
|
||||
CREATE TRIGGER events_credential_body BEFORE INSERT ON events
|
||||
WHEN NEW.kind GLOB 'credential.*' AND (
|
||||
json_extract(NEW.body, '$.service') IS NULL OR json_extract(NEW.body, '$.service') NOT IN ('gitea','vikunja')
|
||||
OR json_extract(NEW.body, '$.instance') IS NULL)
|
||||
BEGIN SELECT RAISE(ABORT, 'credential events name a service and a role instance'); END;
|
||||
CREATE TRIGGER events_task_missing_body BEFORE INSERT ON events
|
||||
WHEN NEW.kind = 'task.missing' AND (
|
||||
json_extract(NEW.body, '$.reason') IS NULL OR json_extract(NEW.body, '$.reason') NOT IN ('moved','not-found','no-access')
|
||||
OR (json_extract(NEW.body, '$.reason') = 'moved' AND json_type(NEW.body, '$.project') IS NOT 'integer'))
|
||||
BEGIN SELECT RAISE(ABORT, 'task.missing carries a reason, and the new project when moved'); END;
|
||||
CREATE TRIGGER events_task_subject BEFORE INSERT ON events
|
||||
WHEN NEW.kind GLOB 'task.*' AND (NEW.subject IS NULL OR NOT (NEW.subject GLOB 'vikunja:[1-9]*/[1-9]*' AND NOT substr(NEW.subject, 9) GLOB '*[^0-9/]*' AND NOT substr(NEW.subject, 9) GLOB '*/*/*'))
|
||||
BEGIN SELECT RAISE(ABORT, 'a task event names its task in subject'); END;
|
||||
CREATE TRIGGER events_task_created_body BEFORE INSERT ON events
|
||||
WHEN NEW.kind = 'task.created' AND (
|
||||
json_type(NEW.body, '$.request') IS NOT 'text'
|
||||
OR NOT EXISTS (SELECT 1 FROM events WHERE id = json_extract(NEW.body, '$.request')
|
||||
AND kind = 'human.input' AND business = NEW.business)
|
||||
OR json_type(NEW.body, '$.requirement') IS NOT 'text'
|
||||
OR NOT json_extract(NEW.body, '$.requirement') GLOB 'REQ-[A-Z]*-[1-9]*'
|
||||
OR json_extract(NEW.body, '$.requirement') GLOB 'REQ-*[^A-Z0-9-]*')
|
||||
BEGIN SELECT RAISE(ABORT, 'task.created cites the human.input that asked for it and a requirement id'); END;
|
||||
CREATE VIEW launch_state AS
|
||||
SELECT business, CASE kind WHEN 'launch.revoked' THEN 'revoked' ELSE 'allowed' END AS state, at
|
||||
FROM events e WHERE kind IN ('launch.revoked','launch.restored')
|
||||
AND seq = (SELECT max(seq) FROM events WHERE business = e.business AND kind IN ('launch.revoked','launch.restored'));
|
||||
CREATE VIEW task_external_changes AS
|
||||
SELECT p.business, p.task_ref, p.seq, p.via, p.updated, p.digest, ls.digest AS self_digest
|
||||
FROM task_snapshots p
|
||||
LEFT JOIN task_snapshots ls ON ls.seq = (SELECT max(seq) FROM task_snapshots
|
||||
WHERE business = p.business AND task_ref = p.task_ref AND source = 'self')
|
||||
WHERE p.source = 'poll'
|
||||
AND p.seq = (SELECT max(seq) FROM task_snapshots WHERE business = p.business AND task_ref = p.task_ref)
|
||||
AND (ls.seq IS NULL OR (p.updated >= ls.updated AND p.read_at > ls.at AND p.digest <> ls.digest));
|
||||
CREATE VIEW task_current AS
|
||||
SELECT s.seq, s.at, s.business, s.task_ref, s.updated, s.etag, s.digest, s.fields, s.source, s.via, s.read_at, s.role, s.run
|
||||
FROM task_snapshots s
|
||||
WHERE s.seq = (SELECT max(c.seq) FROM task_snapshots c
|
||||
WHERE c.business = s.business AND c.task_ref = s.task_ref
|
||||
AND (c.source = 'self'
|
||||
OR c.read_at > coalesce((SELECT ls.at FROM task_snapshots ls
|
||||
WHERE ls.business = c.business AND ls.task_ref = c.task_ref AND ls.source = 'self'
|
||||
ORDER BY ls.seq DESC LIMIT 1), '')));
|
||||
CREATE VIEW tasks_open AS
|
||||
SELECT s.business, s.task_ref, json_extract(s.fields, '$.bucket') AS bucket, s.seq
|
||||
FROM task_current s
|
||||
WHERE json_type(s.fields, '$.gone') IS NULL
|
||||
AND json_extract(s.fields, '$.done') = 0;
|
||||
CREATE VIEW urgent_inbox AS
|
||||
SELECT d.id, d.business, d.task_ref, d.question, d.at
|
||||
FROM decisions d
|
||||
WHERE d.class = 'gated' AND d.blocking = 1
|
||||
AND NOT EXISTS (SELECT 1 FROM decision_events x WHERE x.decision = d.id AND x.op IN ('resolved','withdrawn','expired'));
|
||||
CREATE TABLE task_comment_cursors (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
business TEXT NOT NULL,
|
||||
task_id INTEGER NOT NULL CHECK (task_id > 0),
|
||||
last_comment INTEGER NOT NULL CHECK (last_comment > 0)
|
||||
) STRICT;
|
||||
CREATE INDEX task_comment_cursors_latest ON task_comment_cursors (business, task_id, seq);
|
||||
CREATE TRIGGER task_comment_cursors_no_update BEFORE UPDATE ON task_comment_cursors
|
||||
BEGIN SELECT RAISE(ABORT, 'task_comment_cursors is append-only'); END;
|
||||
CREATE TRIGGER task_comment_cursors_no_delete BEFORE DELETE ON task_comment_cursors
|
||||
BEGIN SELECT RAISE(ABORT, 'task_comment_cursors is append-only'); END;
|
||||
CREATE TRIGGER task_comment_cursors_no_replace BEFORE INSERT ON task_comment_cursors
|
||||
WHEN EXISTS (SELECT 1 FROM task_comment_cursors WHERE seq = NEW.seq)
|
||||
BEGIN SELECT RAISE(ABORT, 'task_comment_cursors is append-only'); END;
|
||||
CREATE TRIGGER task_comment_cursors_forward BEFORE INSERT ON task_comment_cursors
|
||||
WHEN NEW.last_comment <= COALESCE((SELECT last_comment FROM task_comment_cursors
|
||||
WHERE business = NEW.business AND task_id = NEW.task_id ORDER BY seq DESC LIMIT 1), 0)
|
||||
BEGIN SELECT RAISE(ABORT, 'comment cursor must advance'); END;
|
||||
CREATE TABLE projects (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id TEXT NOT NULL UNIQUE,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
repo TEXT,
|
||||
created_by TEXT NOT NULL,
|
||||
UNIQUE (business, name)
|
||||
) STRICT;
|
||||
CREATE TABLE threads (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
id TEXT NOT NULL UNIQUE,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
project TEXT NOT NULL REFERENCES projects(id),
|
||||
instance TEXT NOT NULL,
|
||||
owner TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
UNIQUE (project, name)
|
||||
) STRICT;
|
||||
CREATE TABLE thread_claims (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
thread TEXT NOT NULL REFERENCES threads(id),
|
||||
op TEXT NOT NULL CHECK (op IN ('claim','release','revoke')),
|
||||
holder_run TEXT NOT NULL,
|
||||
harness TEXT NOT NULL, address TEXT,
|
||||
by TEXT NOT NULL, reason TEXT,
|
||||
decision TEXT
|
||||
) STRICT;
|
||||
CREATE TABLE message_threads (
|
||||
message TEXT PRIMARY KEY REFERENCES messages(id),
|
||||
thread TEXT NOT NULL REFERENCES threads(id)
|
||||
) STRICT;
|
||||
CREATE TABLE thread_opens (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
at TEXT NOT NULL,
|
||||
thread TEXT NOT NULL REFERENCES threads(id),
|
||||
by TEXT NOT NULL
|
||||
) STRICT;
|
||||
CREATE INDEX thread_claims_thread ON thread_claims (thread, seq);
|
||||
CREATE INDEX message_threads_thread ON message_threads (thread);
|
||||
CREATE TRIGGER threads_project_business BEFORE INSERT ON threads
|
||||
WHEN (SELECT business FROM projects WHERE id = NEW.project) IS NOT NEW.business
|
||||
BEGIN SELECT RAISE(ABORT, 'a thread belongs to its project''s business'); END;
|
||||
CREATE TRIGGER thread_one_holder BEFORE INSERT ON thread_claims
|
||||
WHEN NEW.op = 'claim' AND (SELECT op FROM thread_claims WHERE thread = NEW.thread ORDER BY seq DESC LIMIT 1) = 'claim'
|
||||
BEGIN SELECT RAISE(ABORT, 'thread already held'); END;
|
||||
CREATE TRIGGER thread_one_per_run BEFORE INSERT ON thread_claims
|
||||
WHEN NEW.op = 'claim' AND EXISTS (SELECT 1 FROM thread_claims c WHERE c.holder_run = NEW.holder_run AND c.business = NEW.business
|
||||
AND c.seq = (SELECT max(seq) FROM thread_claims WHERE thread = c.thread) AND c.op = 'claim')
|
||||
BEGIN SELECT RAISE(ABORT, 'run already holds a thread'); END;
|
||||
CREATE TRIGGER thread_release_by_holder BEFORE INSERT ON thread_claims
|
||||
WHEN NEW.op IN ('release','revoke') AND COALESCE((SELECT op FROM thread_claims WHERE thread = NEW.thread ORDER BY seq DESC LIMIT 1),'') <> 'claim'
|
||||
BEGIN SELECT RAISE(ABORT, 'thread is not held'); END;
|
||||
CREATE TRIGGER thread_release_same_run BEFORE INSERT ON thread_claims
|
||||
WHEN NEW.op = 'release' AND (SELECT holder_run FROM thread_claims WHERE thread = NEW.thread ORDER BY seq DESC LIMIT 1) <> NEW.holder_run
|
||||
BEGIN SELECT RAISE(ABORT, 'only the holder releases; others revoke'); END;
|
||||
CREATE TRIGGER thread_revoke_needs_decision BEFORE INSERT ON thread_claims
|
||||
WHEN NEW.op = 'revoke' AND NEW.decision IS NULL AND NEW.reason IS NULL
|
||||
BEGIN SELECT RAISE(ABORT, 'revoke needs a resolved decision or a reason'); END;
|
||||
CREATE TRIGGER thread_claims_business BEFORE INSERT ON thread_claims
|
||||
WHEN (SELECT business FROM threads WHERE id = NEW.thread) IS NOT NEW.business
|
||||
BEGIN SELECT RAISE(ABORT, 'a thread claim names the thread''s business'); END;
|
||||
CREATE TRIGGER message_threads_match BEFORE INSERT ON message_threads
|
||||
WHEN NOT EXISTS (SELECT 1 FROM messages m JOIN threads t ON t.id = NEW.thread
|
||||
WHERE m.id = NEW.message AND m.business = t.business AND t.instance IN (m.to_role, m.from_role))
|
||||
BEGIN SELECT RAISE(ABORT, 'a threaded message is to or from the thread''s instance'); END;
|
||||
CREATE TRIGGER delivery_same_thread BEFORE INSERT ON deliveries
|
||||
WHEN NEW.op IN ('routed','delivered') AND (NEW.op = 'delivered' OR NEW.holder_run IS NOT NULL)
|
||||
AND EXISTS (SELECT 1 FROM message_threads mt JOIN messages m ON m.id = mt.message JOIN threads t ON t.id = mt.thread
|
||||
WHERE mt.message = NEW.message AND m.to_role = t.instance
|
||||
AND NOT EXISTS (SELECT 1 FROM thread_claims c WHERE c.seq = (SELECT max(seq) FROM thread_claims WHERE thread = t.id)
|
||||
AND c.op = 'claim' AND c.holder_run IS NEW.holder_run))
|
||||
BEGIN SELECT RAISE(ABORT, 'a threaded message goes only to its thread''s holder'); END;
|
||||
CREATE TRIGGER projects_no_update BEFORE UPDATE ON projects BEGIN SELECT RAISE(ABORT, 'projects is append-only'); END;
|
||||
CREATE TRIGGER projects_no_delete BEFORE DELETE ON projects BEGIN SELECT RAISE(ABORT, 'projects is append-only'); END;
|
||||
CREATE TRIGGER projects_no_replace BEFORE INSERT ON projects WHEN EXISTS (SELECT 1 FROM projects WHERE seq = NEW.seq OR id = NEW.id) BEGIN SELECT RAISE(ABORT, 'projects is append-only'); END;
|
||||
CREATE TRIGGER threads_no_update BEFORE UPDATE ON threads BEGIN SELECT RAISE(ABORT, 'threads is append-only'); END;
|
||||
CREATE TRIGGER threads_no_delete BEFORE DELETE ON threads BEGIN SELECT RAISE(ABORT, 'threads is append-only'); END;
|
||||
CREATE TRIGGER threads_no_replace BEFORE INSERT ON threads WHEN EXISTS (SELECT 1 FROM threads WHERE seq = NEW.seq OR id = NEW.id) BEGIN SELECT RAISE(ABORT, 'threads is append-only'); END;
|
||||
CREATE TRIGGER thread_claims_no_update BEFORE UPDATE ON thread_claims BEGIN SELECT RAISE(ABORT, 'thread_claims is append-only'); END;
|
||||
CREATE TRIGGER thread_claims_no_delete BEFORE DELETE ON thread_claims BEGIN SELECT RAISE(ABORT, 'thread_claims is append-only'); END;
|
||||
CREATE TRIGGER thread_claims_no_replace BEFORE INSERT ON thread_claims WHEN EXISTS (SELECT 1 FROM thread_claims WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'thread_claims is append-only'); END;
|
||||
CREATE TRIGGER message_threads_no_update BEFORE UPDATE ON message_threads BEGIN SELECT RAISE(ABORT, 'message_threads is append-only'); END;
|
||||
CREATE TRIGGER message_threads_no_delete BEFORE DELETE ON message_threads BEGIN SELECT RAISE(ABORT, 'message_threads is append-only'); END;
|
||||
CREATE TRIGGER message_threads_no_replace BEFORE INSERT ON message_threads WHEN EXISTS (SELECT 1 FROM message_threads WHERE message = NEW.message) BEGIN SELECT RAISE(ABORT, 'message_threads is append-only'); END;
|
||||
CREATE TRIGGER thread_opens_no_update BEFORE UPDATE ON thread_opens BEGIN SELECT RAISE(ABORT, 'thread_opens is append-only'); END;
|
||||
CREATE TRIGGER thread_opens_no_delete BEFORE DELETE ON thread_opens BEGIN SELECT RAISE(ABORT, 'thread_opens is append-only'); END;
|
||||
CREATE TRIGGER thread_opens_no_replace BEFORE INSERT ON thread_opens WHEN EXISTS (SELECT 1 FROM thread_opens WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'thread_opens is append-only'); END;
|
||||
CREATE TABLE instance_names (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
instance TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
by TEXT NOT NULL
|
||||
) STRICT;
|
||||
CREATE TRIGGER instance_names_unique BEFORE INSERT ON instance_names
|
||||
WHEN EXISTS (SELECT 1 FROM instance_names n WHERE n.business = NEW.business AND n.name = NEW.name
|
||||
AND n.instance <> NEW.instance
|
||||
AND n.seq = (SELECT max(seq) FROM instance_names WHERE business = n.business AND instance = n.instance))
|
||||
BEGIN SELECT RAISE(ABORT, 'an instance name is unique in its business'); END;
|
||||
CREATE TRIGGER instance_names_no_update BEFORE UPDATE ON instance_names BEGIN SELECT RAISE(ABORT, 'instance_names is append-only'); END;
|
||||
CREATE TRIGGER instance_names_no_delete BEFORE DELETE ON instance_names BEGIN SELECT RAISE(ABORT, 'instance_names is append-only'); END;
|
||||
CREATE TRIGGER instance_names_no_replace BEFORE INSERT ON instance_names WHEN EXISTS (SELECT 1 FROM instance_names WHERE seq = NEW.seq) BEGIN SELECT RAISE(ABORT, 'instance_names is append-only'); END;
|
||||
-- Row 124 (#1618): immutable source snapshots and turn outcomes, never transcript text.
|
||||
CREATE TABLE usage_records (
|
||||
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
at TEXT NOT NULL,
|
||||
business TEXT NOT NULL,
|
||||
run TEXT NOT NULL,
|
||||
instance TEXT NOT NULL,
|
||||
provider TEXT,
|
||||
model TEXT,
|
||||
account TEXT,
|
||||
turn TEXT NOT NULL,
|
||||
source TEXT NOT NULL,
|
||||
phase TEXT NOT NULL CHECK (phase IN ('begin','end')),
|
||||
status TEXT NOT NULL CHECK (status IN ('known','unknown')),
|
||||
code TEXT,
|
||||
cursor TEXT CHECK (cursor IS NULL OR json_valid(cursor)),
|
||||
input INTEGER,
|
||||
output INTEGER,
|
||||
cache_write INTEGER,
|
||||
cache_read INTEGER,
|
||||
UNIQUE (business,run,turn,source,phase),
|
||||
CHECK ((status='unknown' AND input IS NULL AND output IS NULL AND cache_write IS NULL AND cache_read IS NULL)
|
||||
OR (status='known' AND input >= 0 AND output >= 0 AND cache_write >= 0 AND cache_read >= 0
|
||||
AND input IS NOT NULL AND output IS NOT NULL AND cache_write IS NOT NULL AND cache_read IS NOT NULL))
|
||||
) STRICT;
|
||||
CREATE TRIGGER usage_records_no_update BEFORE UPDATE ON usage_records BEGIN SELECT RAISE(ABORT, 'usage_records is append-only'); END;
|
||||
CREATE TRIGGER usage_records_no_delete BEFORE DELETE ON usage_records BEGIN SELECT RAISE(ABORT, 'usage_records is append-only'); END;
|
||||
CREATE TRIGGER usage_records_no_replace BEFORE INSERT ON usage_records WHEN EXISTS (SELECT 1 FROM usage_records WHERE seq=NEW.seq OR (business=NEW.business AND run=NEW.run AND turn=NEW.turn AND source=NEW.source AND phase=NEW.phase)) BEGIN SELECT RAISE(ABORT, 'usage_records is append-only'); END;
|
||||
@@ -1,489 +0,0 @@
|
||||
// Row 234 (#1740, #436a row a): host enrollment through a credential.mint raise with a `grant` binding
|
||||
// (r6 E1, E2, E4, X1, X3). The keyscan is a fake that returns key lines this test makes, ssh-keygen is
|
||||
// real, and the key files go under a scratch config dir. Nothing connects to any host.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { Broker, BusError, writeGrantEvent, registrySha256 } from '../src/broker.mjs';
|
||||
import { Store } from '../src/store.mjs';
|
||||
import { hostGrant, fingerprint, grantTag, installerTag } from '../src/host-grant.mjs';
|
||||
import { grantDecision } from './host-fixtures.mjs';
|
||||
|
||||
const options = [{ key: 'yes', text: 'Yes' }, { key: 'no', text: 'No' }];
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
const keyLine = (dir, name) => {
|
||||
execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-C', 'x', '-f', join(dir, name)]);
|
||||
return readFileSync(join(dir, name + '.pub'), 'utf8').trim().split(' ').slice(0, 2).join(' ');
|
||||
};
|
||||
const refusesWith = async (p, code) => assert.rejects(Promise.resolve().then(() => p), (e) => (assert.equal(e.code, code), true));
|
||||
const refusesSync = (fn, code) => assert.throws(fn, (e) => (assert.equal(e.code, code), true));
|
||||
|
||||
function setup(t, { keygen, check, hang = false } = {}) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'g234-'));
|
||||
const store = new Store(root);
|
||||
t.after(() => {
|
||||
store.close();
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
});
|
||||
const hostKeys = [keyLine(root, 'hk1'), keyLine(root, 'hk2')];
|
||||
const scans = [];
|
||||
const scan = { lines: hostKeys };
|
||||
const configDir = join(root, 'config');
|
||||
const real = hostGrant({
|
||||
configDir,
|
||||
runRoot: join(configDir, 'secrets', 'run'),
|
||||
scan: async (address, port) => (scans.push([address, port]), scan.lines),
|
||||
...(keygen ? { keygen } : {}),
|
||||
});
|
||||
const checks = [];
|
||||
// `hang`: steps 2 and 3 run, then the call never returns, as when the child dies before step 4.
|
||||
const enroll = hang ? async (...args) => (await real.enroll(...args), new Promise(() => {})) : real.enroll;
|
||||
const hg = { ...real, enroll, check: async (...args) => (checks.push(args), check ? check(...args) : { installerFingerprint: args[2].installer_fingerprint, exit: 0 }) };
|
||||
const business = {
|
||||
id: 'demo',
|
||||
human: 'jason',
|
||||
arbiters: { technical: 'pm', delivery: 'pm' },
|
||||
roles: {
|
||||
chief: { definition: 'chief-of-staff', authority: { withinRole: ['message.send'], crossRole: [] } },
|
||||
pm: { definition: 'pm', authority: { withinRole: ['message.send'], crossRole: [] } },
|
||||
},
|
||||
vars: { 'bus.tester': true },
|
||||
};
|
||||
const make = (h = hg) => new Broker({ store, businesses: { demo: business }, hostGrant: h });
|
||||
const broker = make();
|
||||
const caps = {};
|
||||
const bind = (b) => {
|
||||
for (const role of ['chief', 'pm']) {
|
||||
caps[role] = b.bindLaunch({ business: 'demo', role, run: role + '-run-' + Math.random(), harness: 'pi', address: role });
|
||||
b.request(caps[role], { verb: 'role.claim' });
|
||||
}
|
||||
caps.human = b.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
||||
caps.tester = b.bindTester({ business: 'demo' });
|
||||
caps.reader = b.bindReader({ business: 'demo' });
|
||||
};
|
||||
bind(broker);
|
||||
const grant = (over = {}) => ({
|
||||
method: 'host-enroll',
|
||||
host: 'web1',
|
||||
address: '192.0.2.10',
|
||||
port: 22,
|
||||
user: 'jarvis',
|
||||
sudo: true,
|
||||
fingerprints: hostKeys.map(fingerprint),
|
||||
...over,
|
||||
});
|
||||
const call = (who, verb, args = {}, b = broker) => b.request(caps[who], { verb, args });
|
||||
const raise = (over = {}, who = 'chief', extra = {}) =>
|
||||
call(who, 'decision.raise', {
|
||||
action: 'credential.mint',
|
||||
question: 'Enroll web1?',
|
||||
options,
|
||||
recommendation: 'yes',
|
||||
blocking: false,
|
||||
grant: grant(over),
|
||||
...extra,
|
||||
});
|
||||
const events = () =>
|
||||
store
|
||||
.all("SELECT kind, actor_role, actor_run, body FROM events WHERE business='demo' ORDER BY seq")
|
||||
.map((e) => ({ kind: e.kind, actor_role: e.actor_role, actor_run: e.actor_run, ...JSON.parse(e.body) }));
|
||||
const grantEvents = () => events().filter((e) => e.actor_run === 'grant');
|
||||
const settle = async (decision) => {
|
||||
for (let i = 0; i < 250; i++) {
|
||||
if (grantEvents().some((e) => e.grantDecision === decision && ['grant.host.enrolled', 'grant.failed'].includes(e.action))) return;
|
||||
await sleep(20);
|
||||
}
|
||||
throw new Error('enrollment did not end');
|
||||
};
|
||||
const keyFile = (host = 'web1') => join(configDir, 'secrets', 'hosts', 'demo', host, 'installer');
|
||||
const hostRow = (host = 'web1') => store.get("SELECT * FROM hosts WHERE business='demo' AND host=?", host);
|
||||
const messages = () => store.all("SELECT from_role, to_role, class, decision, body FROM messages WHERE business='demo' ORDER BY rowid");
|
||||
return { root, store, broker, make, bind, caps, call, raise, grant, hostKeys, scan, scans, checks, events, grantEvents, settle, keyFile, hostRow, messages, configDir };
|
||||
}
|
||||
const approve = async (f, over) => {
|
||||
const d = await f.raise(over);
|
||||
const r = f.call('human', 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
await f.settle(d.id);
|
||||
return { d, r };
|
||||
};
|
||||
|
||||
test('G1, A1: only the chief raises a grant, and a refused raise stores nothing and runs no keyscan', async (t) => {
|
||||
const f = setup(t);
|
||||
await refusesWith(f.raise({}, 'pm'), 'grant-chief-only');
|
||||
await refusesWith(f.call('human', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false, grant: f.grant() }), 'agent-required');
|
||||
await refusesWith(f.call('tester', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false, grant: f.grant() }), 'tester-refused');
|
||||
assert.equal(f.scans.length, 0);
|
||||
assert.equal(f.store.get('SELECT count(*) AS n FROM decisions').n, 0);
|
||||
assert.deepEqual(f.events().filter((e) => e.kind === 'action.refused').map((e) => e.code), ['grant-chief-only', 'agent-required', 'tester-refused']);
|
||||
});
|
||||
|
||||
test('G1: grant goes only with credential.mint, row a takes only host-enroll, and E1 refuses each bad field', async (t) => {
|
||||
const f = setup(t);
|
||||
await refusesWith(f.raise({}, 'chief', { action: 'deploy' }), 'invalid-request');
|
||||
for (const over of [
|
||||
{ method: 'host' },
|
||||
{ user: 'root' },
|
||||
{ user: 'localadmin' },
|
||||
{ user: 'mosaic-installer' },
|
||||
{ user: 'Bad' },
|
||||
{ sudo: 'yes' },
|
||||
{ port: 0 },
|
||||
{ port: 65536 },
|
||||
{ host: 'Web_1' },
|
||||
{ address: '127.0.0.1' },
|
||||
{ address: 'localhost' },
|
||||
{ fingerprints: [] },
|
||||
{ fingerprints: ['SHA256:short'] },
|
||||
{ fingerprints: [f.grant().fingerprints[0], f.grant().fingerprints[0]] },
|
||||
{ extra: 1 },
|
||||
])
|
||||
await refusesWith(f.raise(over), 'invalid-request');
|
||||
const { method, ...noMethod } = f.grant();
|
||||
await refusesWith(
|
||||
f.call('chief', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false, grant: noMethod }),
|
||||
'invalid-request',
|
||||
);
|
||||
assert.equal(f.scans.length, 0);
|
||||
assert.equal(f.store.get('SELECT count(*) AS n FROM decisions').n, 0);
|
||||
});
|
||||
|
||||
test('G5, A5, A6: the scanned key set must equal the requested set, or host-key-mismatch and nothing stored', async (t) => {
|
||||
const f = setup(t);
|
||||
const other = keyLine(f.root, 'hk3');
|
||||
for (const lines of [[f.hostKeys[0]], [...f.hostKeys, other], [f.hostKeys[0], other], []]) {
|
||||
f.scan.lines = lines;
|
||||
await refusesWith(f.raise(), 'host-key-mismatch');
|
||||
}
|
||||
f.scan.lines = f.hostKeys;
|
||||
await refusesWith(f.raise({ fingerprints: [fingerprint(f.hostKeys[0])] }), 'host-key-mismatch');
|
||||
assert.deepEqual(f.scans.at(-1), ['192.0.2.10', 22]);
|
||||
assert.equal(f.store.get('SELECT count(*) AS n FROM decisions').n, 0);
|
||||
});
|
||||
|
||||
test('G4 (host-enroll block, M1): the broker appends the keys, fingerprints and sudo line, and the cap counts the block', async (t) => {
|
||||
const f = setup(t);
|
||||
const d = await f.raise();
|
||||
assert.equal(d.route_to ?? f.store.get('SELECT route_to FROM decisions WHERE id=?', d.id).route_to, 'human');
|
||||
const q = f.store.get('SELECT question FROM decisions WHERE id=?', d.id).question;
|
||||
assert.ok(q.startsWith('Enroll web1?\n\nEnroll host web1: user jarvis at 192.0.2.10 port 22.\n'));
|
||||
for (const k of f.hostKeys) assert.ok(q.includes(`\n${fingerprint(k)} ${k}`));
|
||||
assert.ok(q.endsWith('\njarvis has sudo on this host. Approving lets later grants for jarvis be installed, and section 9\'s first limit applies to jarvis.'));
|
||||
const raiseBody = f.events().find((e) => e.operation === 'decision.raise');
|
||||
assert.deepEqual(raiseBody.grant, { ...f.grant(), hostKeys: f.hostKeys });
|
||||
// A question that carries a forged block still gets the broker's block after it.
|
||||
const forged = 'x\n\nEnroll host web1: user other at 192.0.2.99 port 22.\nother has no sudo on this host.';
|
||||
const d2 = await f.raise({ host: 'web2', sudo: false }, 'chief', { question: forged });
|
||||
const q2 = f.store.get('SELECT question FROM decisions WHERE id=?', d2.id).question;
|
||||
assert.ok(q2.startsWith(forged + '\n\nEnroll host web2: user jarvis at 192.0.2.10 port 22.\n'));
|
||||
assert.ok(q2.endsWith('\njarvis has no sudo on this host.'));
|
||||
// The 4096 cap holds with the block appended.
|
||||
await refusesWith(f.raise({ host: 'web3' }, 'chief', { question: 'q'.repeat(4000) }), 'invalid-request');
|
||||
assert.equal(f.store.get("SELECT count(*) AS n FROM decisions").n, 2);
|
||||
});
|
||||
|
||||
test('G6, X1: the human\'s cli yes starts enrollment, which writes the record, the key file and the events in order', async (t) => {
|
||||
const f = setup(t);
|
||||
const { d, r } = await approve(f);
|
||||
assert.deepEqual(r, { id: d.id, op: 'resolved', grant: 'started' });
|
||||
const row = f.hostRow();
|
||||
assert.equal(row.state, 'pending-install');
|
||||
assert.equal(row.decision, d.id);
|
||||
assert.equal(row.user, 'jarvis');
|
||||
assert.equal(row.sudo, 1);
|
||||
assert.deepEqual(JSON.parse(row.host_keys), f.hostKeys);
|
||||
assert.match(row.installer_fingerprint, /^SHA256:/);
|
||||
// E2 step 3: 0600 in 0700 dirs.
|
||||
assert.equal(statSync(f.keyFile()).mode & 0o777, 0o600);
|
||||
for (const dir of [join(f.keyFile(), '..'), join(f.keyFile(), '..', '..')]) assert.equal(statSync(dir).mode & 0o777, 0o700);
|
||||
const g = f.grantEvents();
|
||||
assert.deepEqual(g.map((e) => e.operation ?? e.action), ['grant.host-enroll', 'grant.host.enroll.step', 'grant.host.enrolled']);
|
||||
for (const e of g) assert.deepEqual([e.kind, e.actor_role, e.actor_run], ['action.allowed', null, 'grant']);
|
||||
assert.deepEqual(g[0], { kind: 'action.allowed', actor_role: null, actor_run: 'grant', operation: 'grant.host-enroll', decision: d.id });
|
||||
assert.equal(g[1].grantDecision, d.id);
|
||||
assert.equal(g[1].step, 'registry');
|
||||
const enrolled = g[2];
|
||||
assert.equal('decision' in enrolled, false);
|
||||
assert.equal(enrolled.registrySha256, registrySha256({ address: '192.0.2.10', port: 22, user: 'jarvis', sudo: true, hostKeys: f.hostKeys }));
|
||||
assert.equal(enrolled.installerFingerprint, row.installer_fingerprint);
|
||||
assert.deepEqual([enrolled.user, enrolled.sudo], ['jarvis', true]);
|
||||
// E2 step 4's message to the human and the chief: the installer line, public half only.
|
||||
const tag = installerTag('demo', 'web1');
|
||||
const pub = execFileSync('ssh-keygen', ['-y', '-f', f.keyFile()], { encoding: 'utf8' }).trim().split(' ').slice(0, 2).join(' ');
|
||||
const notes = f.messages().filter((m) => m.from_role === '_bus' && m.decision === d.id);
|
||||
assert.deepEqual(notes.map((m) => [m.to_role, m.class]), [['human', 'RESULT'], ['chief', 'RESULT']]);
|
||||
for (const m of notes)
|
||||
assert.ok(m.body.includes(`\nrestrict,command="/usr/local/sbin/mosaic-keys",from="<from>" ${pub} mosaic-installer-${tag.slice(7)}\n`));
|
||||
// A7: no part of the private key reaches the store.
|
||||
const secret = readFileSync(f.keyFile(), 'utf8').split('\n').filter((l) => l.length >= 24 && !l.startsWith('-----'));
|
||||
const dump = JSON.stringify([f.store.all('SELECT body FROM events'), f.store.all('SELECT body FROM messages'), f.store.all('SELECT * FROM hosts')]);
|
||||
for (const l of secret) assert.equal(dump.includes(l), false);
|
||||
// The tmp dir under the run root is gone.
|
||||
assert.deepEqual(readdirSync(join(f.configDir, 'secrets', 'run')), []);
|
||||
});
|
||||
|
||||
test('A2, A4: a credential.mint without grant, and a no, start nothing', async (t) => {
|
||||
const f = setup(t);
|
||||
const plain = f.call('chief', 'decision.raise', { action: 'credential.mint', question: 'Hand-made key?', options, recommendation: 'yes', blocking: false });
|
||||
assert.deepEqual(f.call('human', 'decision.resolve', { id: plain.id, choice: 'yes' }), { id: plain.id, op: 'resolved' });
|
||||
const d = await f.raise();
|
||||
assert.deepEqual(f.call('human', 'decision.resolve', { id: d.id, choice: 'no' }), { id: d.id, op: 'resolved' });
|
||||
await sleep(200);
|
||||
assert.deepEqual(f.grantEvents(), []);
|
||||
assert.equal(f.hostRow(), undefined);
|
||||
});
|
||||
|
||||
test('A3, X1: a resolve by the tester or an agent starts nothing', async (t) => {
|
||||
const f = setup(t);
|
||||
const d = await f.raise();
|
||||
for (const who of ['tester', 'pm', 'chief']) {
|
||||
try {
|
||||
f.call(who, 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
} catch {}
|
||||
}
|
||||
await sleep(200);
|
||||
assert.deepEqual(f.grantEvents(), []);
|
||||
assert.equal(f.hostRow(), undefined);
|
||||
});
|
||||
|
||||
test('G6 (duckworth-0081 B3): a withdraw by the chief or the human, and an arbiter resolve, start nothing', async (t) => {
|
||||
const f = setup(t);
|
||||
for (const who of ['chief', 'human']) {
|
||||
const d = await f.raise();
|
||||
assert.deepEqual(f.call(who, 'decision.withdraw', { id: d.id }), { id: d.id, op: 'withdrawn' });
|
||||
}
|
||||
// A grant raise always routes to the human, so the fixture writes an open one routed to the pm
|
||||
// arbiter, which then resolves it yes through the verb.
|
||||
const d = { id: grantDecision(f.store, { route: 'pm', grant: f.grant(), close: null }) };
|
||||
assert.deepEqual(f.call('pm', 'decision.resolve', { id: d.id, choice: 'yes' }), { id: d.id, op: 'resolved' });
|
||||
await sleep(200);
|
||||
assert.deepEqual(f.grantEvents(), []);
|
||||
assert.equal(f.hostRow(), undefined);
|
||||
assert.deepEqual(f.broker.reconcileGrants(), []);
|
||||
assert.equal(await f.broker.runEnrollment('demo', d.id), 'not-authorized');
|
||||
assert.deepEqual(f.grantEvents(), []);
|
||||
});
|
||||
|
||||
test('G10 (duckworth-0081 B1): a second start for a spent decision refuses decision-consumed, and an unresolved or agent-resolved one not-authorized', async (t) => {
|
||||
const f = setup(t);
|
||||
const { d } = await approve(f);
|
||||
const before = { events: f.grantEvents(), row: f.hostRow(), messages: f.messages().length };
|
||||
assert.equal(await f.broker.runEnrollment('demo', d.id), 'decision-consumed');
|
||||
assert.deepEqual(f.grantEvents(), before.events);
|
||||
assert.deepEqual(f.hostRow(), before.row);
|
||||
assert.equal(f.messages().length, before.messages);
|
||||
// Unresolved, then resolved by an agent: written by SQL, since the verb refuses the agent first.
|
||||
const open = await f.raise({ host: 'web2' });
|
||||
assert.equal(await f.broker.runEnrollment('demo', open.id), 'not-authorized');
|
||||
f.store.run('INSERT INTO decision_events(decision,at,op,by,choice,via) VALUES(?,?,?,?,?,?)', open.id, new Date().toISOString(), 'resolved', 'chief', 'yes', 'broker');
|
||||
assert.equal(await f.broker.runEnrollment('demo', open.id), 'not-authorized');
|
||||
// A cli yes by someone other than the human, so the by check alone refuses it (duckworth-0083 N8, A3b).
|
||||
const other = await f.raise({ host: 'web3' });
|
||||
f.store.run('INSERT INTO decision_events(decision,at,op,by,choice,via) VALUES(?,?,?,?,?,?)', other.id, new Date().toISOString(), 'resolved', 'chief', 'yes', 'cli');
|
||||
assert.equal(await f.broker.runEnrollment('demo', other.id), 'not-authorized');
|
||||
assert.deepEqual(f.broker.reconcileGrants(), []);
|
||||
assert.deepEqual(f.grantEvents(), before.events);
|
||||
assert.equal(f.hostRow('web2'), undefined);
|
||||
assert.equal(existsSync(f.keyFile('web2')), false);
|
||||
assert.equal(f.hostRow('web3'), undefined);
|
||||
assert.equal(existsSync(f.keyFile('web3')), false);
|
||||
});
|
||||
|
||||
test('A8, S1: two approved enrollments for one host: the second ends host-enrolled and the pin stays', async (t) => {
|
||||
const f = setup(t);
|
||||
const d1 = await f.raise();
|
||||
const d2 = await f.raise({ user: 'melanie', sudo: false });
|
||||
f.call('human', 'decision.resolve', { id: d1.id, choice: 'yes' });
|
||||
await f.settle(d1.id);
|
||||
const before = f.hostRow();
|
||||
f.call('human', 'decision.resolve', { id: d2.id, choice: 'yes' });
|
||||
await f.settle(d2.id);
|
||||
assert.deepEqual(f.hostRow(), before);
|
||||
const failed = f.grantEvents().find((e) => e.grantDecision === d2.id && e.action === 'grant.failed');
|
||||
assert.equal(failed.code, 'host-enrolled');
|
||||
assert.ok(f.grantEvents().some((e) => e.operation === 'grant.host-enroll' && e.decision === d2.id));
|
||||
assert.equal(f.grantEvents().filter((e) => e.grantDecision === d2.id && e.action === 'grant.host.enroll.step').length, 0);
|
||||
// A raise for an enrolled host refuses before the keyscan.
|
||||
const scans = f.scans.length;
|
||||
await refusesWith(f.raise(), 'host-enrolled');
|
||||
assert.equal(f.scans.length, scans);
|
||||
});
|
||||
|
||||
test('A9: the hosts primary key refuses a second record for (business, host)', (t) => {
|
||||
const f = setup(t);
|
||||
const d = f.call('chief', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false });
|
||||
const insert = () =>
|
||||
f.store.run(
|
||||
"INSERT INTO hosts(business,host,address,port,user,sudo,host_keys,state,decision) VALUES('demo','web1','192.0.2.1',22,'u',0,'[\"k\"]','pending-install',?)",
|
||||
d.id,
|
||||
);
|
||||
insert();
|
||||
assert.throws(insert, /UNIQUE|PRIMARY/);
|
||||
});
|
||||
|
||||
test('X3: a failure at step 2 deletes the record again and ends grant.failed, with no key file', async (t) => {
|
||||
const f = setup(t, { keygen: '/nonexistent/ssh-keygen' });
|
||||
const { d } = await approve(f);
|
||||
assert.equal(f.hostRow(), undefined);
|
||||
assert.equal(existsSync(f.keyFile()), false);
|
||||
const failed = f.grantEvents().find((e) => e.action === 'grant.failed');
|
||||
assert.deepEqual([failed.grantDecision, failed.host, failed.code], [d.id, 'web1', 'host-failed']);
|
||||
const notes = f.messages().filter((m) => m.from_role === '_bus' && m.decision === d.id);
|
||||
assert.deepEqual(notes.map((m) => m.to_role), ['human', 'chief']);
|
||||
assert.ok(notes[0].body.includes('failed: host-failed'));
|
||||
});
|
||||
|
||||
test('A10, X3: at start a resolved, unspent enrollment is spent and ends interrupted, and never runs late', async (t) => {
|
||||
const f = setup(t);
|
||||
const d = await f.raise();
|
||||
// The resolve commits, and the child dies before step 1: the resolve row alone, written here.
|
||||
f.store.run("INSERT INTO decision_events(decision,at,op,by,choice,via) VALUES(?,?,?,?,?,?)", d.id, new Date().toISOString(), 'resolved', 'jason', 'yes', 'cli');
|
||||
const restarted = f.make();
|
||||
assert.deepEqual(restarted.reconcileGrants(), [d.id]);
|
||||
const g = f.grantEvents();
|
||||
assert.deepEqual(g.map((e) => e.operation ?? e.action), ['grant.host-enroll', 'grant.failed']);
|
||||
assert.deepEqual([g[1].code, g[1].host, g[1].tag], ['interrupted', 'web1', installerTag('demo', 'web1')]);
|
||||
assert.equal(f.hostRow(), undefined);
|
||||
assert.deepEqual(restarted.reconcileGrants(), []);
|
||||
});
|
||||
|
||||
test('X3: at start an enrollment that stopped after its registry step loses its record and key file', async (t) => {
|
||||
const f = setup(t, { hang: true });
|
||||
const d = await f.raise();
|
||||
f.call('human', 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
for (let i = 0; i < 250 && !existsSync(f.keyFile()); i++) await sleep(20);
|
||||
assert.equal(f.hostRow().state, 'pending-install');
|
||||
assert.ok(existsSync(f.keyFile()));
|
||||
const restarted = f.make();
|
||||
assert.deepEqual(restarted.reconcileGrants(), [d.id]);
|
||||
assert.equal(f.hostRow(), undefined);
|
||||
assert.equal(existsSync(f.keyFile()), false);
|
||||
const failed = f.grantEvents().find((e) => e.grantDecision === d.id && e.action === 'grant.failed');
|
||||
assert.deepEqual([failed.code, failed.host, failed.tag], ['interrupted', 'web1', installerTag('demo', 'web1')]);
|
||||
assert.deepEqual(f.messages().filter((m) => m.decision === d.id && m.from_role === '_bus').map((m) => m.to_role), ['human', 'chief']);
|
||||
assert.deepEqual(restarted.reconcileGrants(), []);
|
||||
});
|
||||
|
||||
test('G24 first sentence, M2, A12: tags are mosaic- and 32 hex, and differ by business, agent and host', () => {
|
||||
const long = 'a'.repeat(30) + '.' + '_'.repeat(2) + 'b'.repeat(31);
|
||||
assert.equal(long.length, 64);
|
||||
const tags = [grantTag('demo', long, 'web1'), grantTag('demo', long + 'x', 'web1'), grantTag('other', long, 'web1'), grantTag('demo', long, 'web2'), installerTag('demo', 'web1'), installerTag('other', 'web1')];
|
||||
for (const t of tags) assert.match(t, /^mosaic-[0-9a-f]{32}$/);
|
||||
assert.equal(new Set(tags).size, tags.length);
|
||||
});
|
||||
|
||||
test('E4: hosts.check sets the record ready and records grant.host.checked; a non-zero list leaves it pending', async (t) => {
|
||||
const exits = [1, 0];
|
||||
const f = setup(t, { check: (b, h, r) => ({ installerFingerprint: r.installer_fingerprint, exit: exits.shift() }) });
|
||||
await approve(f);
|
||||
await refusesWith(f.call('chief', 'hosts.check', { host: 'web1' }), 'host-failed');
|
||||
assert.equal(f.hostRow().state, 'pending-install');
|
||||
await refusesWith(f.call('pm', 'hosts.check', { host: 'web1' }), 'grant-chief-only');
|
||||
await refusesWith(f.call('chief', 'hosts.check', { host: 'nope' }), 'host-unknown');
|
||||
const r = await f.call('chief', 'hosts.check', { host: 'web1' });
|
||||
assert.equal(r.state, 'ready');
|
||||
assert.equal(f.hostRow().state, 'ready');
|
||||
assert.equal(f.hostRow().checked_at, r.checkedAt);
|
||||
const checked = f.grantEvents().find((e) => e.action === 'grant.host.checked');
|
||||
assert.deepEqual([checked.host, checked.by, checked.installerFingerprint], ['web1', 'chief', f.hostRow().installer_fingerprint]);
|
||||
assert.equal(checked.registrySha256, registrySha256({ address: '192.0.2.10', port: 22, user: 'jarvis', sudo: true, hostKeys: f.hostKeys }));
|
||||
const status = await f.call('human', 'hosts.status');
|
||||
assert.deepEqual(status.map((h) => [h.host, h.state, h.hostKeys, h.hostLineLeft]), [['web1', 'ready', f.hostKeys.map(fingerprint), []]]);
|
||||
});
|
||||
|
||||
test('G20 (duckworth-0081 B3): the human\'s hosts.check marks the host ready, and the reader refuses', async (t) => {
|
||||
const f = setup(t);
|
||||
await approve(f);
|
||||
await refusesWith(f.call('reader', 'hosts.check', { host: 'web1' }), 'read-only');
|
||||
const r = await f.call('human', 'hosts.check', { host: 'web1' });
|
||||
assert.equal(r.state, 'ready');
|
||||
assert.equal(f.hostRow().state, 'ready');
|
||||
const checked = f.grantEvents().filter((e) => e.action === 'grant.host.checked');
|
||||
assert.deepEqual(checked.map((e) => e.by), ['jason']);
|
||||
});
|
||||
|
||||
test('G18 (duckworth-0081 B2), broker half: a check refused host-key-mismatch leaves the host pending-install with no grant.host.checked', async (t) => {
|
||||
const f = setup(t, { check: () => { throw new BusError('host-key-mismatch'); } });
|
||||
await approve(f);
|
||||
await refusesWith(f.call('chief', 'hosts.check', { host: 'web1' }), 'host-key-mismatch');
|
||||
assert.equal(f.checks.length, 1);
|
||||
assert.equal(f.hostRow().state, 'pending-install');
|
||||
assert.equal(f.hostRow().checked_at, null);
|
||||
assert.deepEqual(f.grantEvents().filter((e) => e.action === 'grant.host.checked'), []);
|
||||
});
|
||||
|
||||
test('E4: a check whose installer fingerprint differs from the record refuses host-changed', async (t) => {
|
||||
const f = setup(t, { check: () => ({ installerFingerprint: 'SHA256:' + 'A'.repeat(43), exit: 0 }) });
|
||||
await approve(f);
|
||||
await refusesWith(f.call('tester', 'hosts.check', { host: 'web1' }), 'host-changed');
|
||||
assert.equal(f.hostRow().state, 'pending-install');
|
||||
});
|
||||
|
||||
test('E4, G21: hosts.remove is the human\'s or the tester\'s, deletes the key and the record, and records grant.host.removed', async (t) => {
|
||||
const f = setup(t);
|
||||
await approve(f);
|
||||
await refusesWith(f.call('chief', 'hosts.remove', { host: 'web1' }), 'human-required');
|
||||
await refusesWith(f.call('reader', 'hosts.remove', { host: 'web1' }), 'read-only');
|
||||
assert.deepEqual(await f.call('human', 'hosts.remove', { host: 'web1' }), { host: 'web1', removed: true });
|
||||
assert.equal(f.hostRow(), undefined);
|
||||
assert.equal(existsSync(f.keyFile()), false);
|
||||
assert.equal(existsSync(join(f.keyFile(), '..')), false);
|
||||
const removed = f.grantEvents().find((e) => e.action === 'grant.host.removed');
|
||||
assert.deepEqual([removed.host, removed.by], ['web1', 'jason']);
|
||||
await refusesWith(f.call('tester', 'hosts.remove', { host: 'web1' }), 'host-unknown');
|
||||
});
|
||||
|
||||
test('G21, F1, F2, M4, A22: hosts.remove refuses host-line-left on a guarded hostLineLeft, and ignores look-alikes', async (t) => {
|
||||
const f = setup(t);
|
||||
const { d } = await approve(f);
|
||||
const at = new Date().toISOString();
|
||||
// Look-alikes: the same body under action.refused, and under another actor of another kind.
|
||||
const lookAlike = JSON.stringify({ action: 'grant.failed', grantDecision: d.id, host: 'web1', hostLineLeft: installerTag('demo', 'web1') });
|
||||
f.store.run("INSERT INTO events(id,at,business,kind,actor_role,actor_run,subject,body) VALUES('la1',?,'demo','action.refused',NULL,'grant','web1',?)", at, lookAlike);
|
||||
f.store.run("INSERT INTO events(id,at,business,kind,actor_role,actor_run,subject,body) VALUES('la2',?,'demo','action.refused','chief','chief-run','web1',?)", at, lookAlike);
|
||||
// The trigger refuses the look-alike as an action.allowed from a session.
|
||||
assert.throws(() =>
|
||||
f.store.run("INSERT INTO events(id,at,business,kind,actor_role,actor_run,subject,body) VALUES('la3',?,'demo','action.allowed','chief','chief-run','web1',?)", at, lookAlike),
|
||||
);
|
||||
assert.equal((await f.call('human', 'hosts.status'))[0].hostLineLeft.length, 0);
|
||||
// F1: the real shape, through the grant writer. F2: any guarded body, not only grant.failed.
|
||||
writeGrantEvent(f.store, at, 'demo', { action: 'grant.revoke.closed', tag: 'mosaic-' + '0'.repeat(32), host: 'web1', hostLineLeft: 'mosaic-' + '0'.repeat(32) }, 'web1');
|
||||
assert.deepEqual((await f.call('human', 'hosts.status'))[0].hostLineLeft, ['mosaic-' + '0'.repeat(32)]);
|
||||
await refusesWith(f.call('human', 'hosts.remove', { host: 'web1' }), 'host-line-left');
|
||||
assert.ok(f.hostRow());
|
||||
assert.ok(existsSync(f.keyFile()));
|
||||
});
|
||||
|
||||
test('hosts.remove refuses host-in-use while a grant record names the host', async (t) => {
|
||||
const f = setup(t);
|
||||
const { d } = await approve(f);
|
||||
f.store.run(
|
||||
"INSERT INTO host_grants(business,agent,host,commands,rotate_by,tag,decision) VALUES('demo','pm','web1','[[\"true\"]]','2099-01-01',?,?)",
|
||||
grantTag('demo', 'pm', 'web1'),
|
||||
d.id,
|
||||
);
|
||||
await refusesWith(f.call('human', 'hosts.remove', { host: 'web1' }), 'host-in-use');
|
||||
assert.ok(f.hostRow());
|
||||
});
|
||||
|
||||
test('the grant writer refuses a body outside section 7\'s shape', (t) => {
|
||||
const f = setup(t);
|
||||
const at = new Date().toISOString();
|
||||
for (const body of [
|
||||
{ action: 'host.sudo' },
|
||||
{ action: 'grant.failed', decision: 'd' },
|
||||
{ operation: 'grant.host-enroll', decision: 'd', host: 'web1' },
|
||||
{ operation: 'grant.host-enroll' },
|
||||
{ operation: 'decision.raise', decision: 'd' },
|
||||
])
|
||||
assert.throws(() => writeGrantEvent(f.store, at, 'demo', body), /grant event shape/);
|
||||
});
|
||||
|
||||
test('recordEvent refuses reserved-event for a grant.* action or operation', (t) => {
|
||||
const f = setup(t);
|
||||
for (const body of [{ action: 'grant.failed' }, { operation: 'grant.host-enroll', decision: 'x' }])
|
||||
refusesSync(() => f.broker.recordEvent(f.caps.chief, { kind: 'action.allowed', body }), 'reserved-event');
|
||||
assert.equal(f.store.get("SELECT count(*) AS n FROM events WHERE json_extract(body,'$.action') GLOB 'grant.*'").n, 0);
|
||||
});
|
||||
@@ -1,970 +0,0 @@
|
||||
// Row 235 (#1741, #436 row b): the host grant executor (r6 X2, X3 failure table, X5) over a scratch sshd
|
||||
// on 127.0.0.1 that this test starts. The sshd logs in only as the test's own user, so the installer
|
||||
// and the granted agent share it. The installer's `list`, `add` and `remove` are stubs on the sshd's
|
||||
// PATH that edit a second authorized-keys file, so the new key's login works only once `add` has run.
|
||||
// The host writer itself is tested in host-tools.test.mjs (G16). Nothing runs as root and nothing
|
||||
// reaches another host.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync, spawn } from 'node:child_process';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { connect } from 'node:net';
|
||||
import { appendFileSync, chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir, userInfo } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { Broker, registrySha256, writeGrantEvent } from '../src/broker.mjs';
|
||||
import { Credentials, parseHostKey } from '../src/credentials.mjs';
|
||||
import { definitionSha256, fingerprint, grantKeys, grantTag, hostGrant, hostReference, sweepHostKeys } from '../src/host-grant.mjs';
|
||||
import { hostExecutor, runHost } from '../src/host-run.mjs';
|
||||
import { Store } from '../src/store.mjs';
|
||||
import { grantDecision, hostRecord } from './host-fixtures.mjs';
|
||||
|
||||
const SSHD = '/usr/bin/sshd';
|
||||
const USER = userInfo().username;
|
||||
const AT = '2026-10-21T00:00:00.000Z';
|
||||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
||||
const sha256 = (x) => createHash('sha256').update(x).digest('hex');
|
||||
const dayFrom = (n) => new Date(Date.now() + n * 86400000).toISOString().slice(0, 10);
|
||||
const keygen = (file) => execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-C', 'test', '-f', file]);
|
||||
const pubLine = (file) => readFileSync(file + '.pub', 'utf8').trim().split(' ').slice(0, 2).join(' ');
|
||||
const readOr = (file, fallback) => (existsSync(file) ? readFileSync(file, 'utf8') : fallback);
|
||||
const options = [{ key: 'yes', text: 'Yes' }, { key: 'no', text: 'No' }];
|
||||
const none = { authority: { withinRole: ['message.send'], crossRole: [] } };
|
||||
const DEFINITIONS = {
|
||||
'chief-of-staff': { roleVersion: 2, credentials: [] },
|
||||
pm: { roleVersion: 2, credentials: [] },
|
||||
ops: { roleVersion: 2, credentials: [{ service: 'host' }] },
|
||||
};
|
||||
const listening = (port) =>
|
||||
new Promise((resolve) => {
|
||||
const s = connect(port, '127.0.0.1');
|
||||
s.on('connect', () => (s.destroy(), resolve(true)));
|
||||
s.on('error', () => resolve(false));
|
||||
});
|
||||
async function until(fn, ms = 10000) {
|
||||
const end = Date.now() + ms;
|
||||
while (!fn()) {
|
||||
if (Date.now() > end) throw new Error('timed out');
|
||||
await sleep(20);
|
||||
}
|
||||
}
|
||||
|
||||
// The stubs read flag files in the test dir: fail-<verb> exits 1, noop-add exits 0 and writes nothing,
|
||||
// hold-add waits for `release` (then exits 1 if `skip` is there), and hold-remove waits for `release`.
|
||||
// wrap.sh logs every request. The sudo stub logs its arguments to sudo.log and runs the command as the
|
||||
// test's user.
|
||||
async function sshd(t, dir) {
|
||||
if (!existsSync(SSHD)) throw new Error(`${SSHD} is missing: the executor tests need it and fail, never skip`);
|
||||
keygen(join(dir, 'hostkey'));
|
||||
keygen(join(dir, 'installer'));
|
||||
writeFileSync(join(dir, 'authorized_keys'), readFileSync(join(dir, 'installer.pub')), { mode: 0o600 });
|
||||
mkdirSync(join(dir, 'fake'));
|
||||
const stub = (name, body) => writeFileSync(join(dir, 'fake', name), `#!/bin/sh\nD='${dir}'\n${body}\n`, { mode: 0o755 });
|
||||
stub('list', '[ -e "$D/fail-list" ] && exit 1\n[ -e "$D/granted" ] && grep " mosaic-[0-9a-f]*$" "$D/granted"\nexit 0');
|
||||
stub(
|
||||
'add',
|
||||
'if [ -e "$D/hold-add" ]; then : > "$D/holding"; while [ ! -e "$D/release" ]; do sleep 0.05; done; [ -e "$D/skip" ] && exit 1; fi\n' +
|
||||
'[ -e "$D/fail-add" ] && exit 1\n[ -e "$D/noop-add" ] && exit 0\n' +
|
||||
'grep -q " $4\\$" "$D/granted" 2>/dev/null && exit 0\necho "restrict $2 $3 $4" >> "$D/granted"',
|
||||
);
|
||||
stub('sudo', 'printf "%s\\n" "$*" >> "$D/sudo.log"\nshift 2\nexec "$@"');
|
||||
stub('remove', 'if [ -e "$D/hold-remove" ]; then : > "$D/holding-remove"; while [ ! -e "$D/release" ]; do sleep 0.05; done; fi\n' +
|
||||
'[ -e "$D/fail-remove" ] && exit 1\n[ -e "$D/granted" ] || exit 0\ngrep -v " $2\\$" "$D/granted" > "$D/granted.tmp"\nmv "$D/granted.tmp" "$D/granted"');
|
||||
writeFileSync(
|
||||
join(dir, 'wrap.sh'),
|
||||
`#!/bin/sh\nprintf '%s\\n' "$SSH_ORIGINAL_COMMAND" >> '${dir}/requests.log'\nPATH=${dir}/fake:/usr/bin:/bin; export PATH\nexec /bin/sh -c "$SSH_ORIGINAL_COMMAND"\n`,
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
for (let attempt = 0; attempt < 5; attempt++) {
|
||||
const port = 20000 + Math.floor(Math.random() * 20000);
|
||||
writeFileSync(
|
||||
join(dir, 'sshd_config'),
|
||||
[`Port ${port}`, 'ListenAddress 127.0.0.1', `HostKey ${dir}/hostkey`, `AuthorizedKeysFile ${dir}/authorized_keys ${dir}/granted`,
|
||||
`PidFile ${dir}/sshd.pid`, 'UsePAM no', 'StrictModes no', 'PasswordAuthentication no', 'KbdInteractiveAuthentication no',
|
||||
`ForceCommand ${dir}/wrap.sh`, ''].join('\n'),
|
||||
);
|
||||
const daemon = spawn(SSHD, ['-D', '-f', join(dir, 'sshd_config'), '-E', join(dir, 'sshd.log')], { stdio: 'ignore' });
|
||||
t.after(() => daemon.kill('SIGKILL'));
|
||||
const deadline = Date.now() + 3000;
|
||||
while (Date.now() < deadline && daemon.exitCode === null) {
|
||||
if (await listening(port)) return port;
|
||||
await sleep(30);
|
||||
}
|
||||
daemon.kill('SIGKILL');
|
||||
}
|
||||
throw new Error('scratch sshd did not start');
|
||||
}
|
||||
|
||||
async function setup(t, opts = {}) {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'g235x-'));
|
||||
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
||||
const port = await sshd(t, dir);
|
||||
const configDir = join(dir, 'cfg');
|
||||
const keyDir = join(configDir, 'secrets', 'hosts', 'demo', 'web1');
|
||||
mkdirSync(keyDir, { recursive: true, mode: 0o700 });
|
||||
for (const d of [configDir, join(configDir, 'secrets'), join(configDir, 'secrets', 'hosts'), join(configDir, 'secrets', 'hosts', 'demo'), keyDir]) chmodSync(d, 0o700);
|
||||
// opts.enroll: no host record and no installer key, so the test enrolls the host itself (G22). opts.wrap
|
||||
// changes the host API the broker gets.
|
||||
if (!opts.enroll) writeFileSync(join(keyDir, 'installer'), readFileSync(join(dir, 'installer')), { mode: 0o600 });
|
||||
const runRoot = join(configDir, 'secrets', 'run');
|
||||
const storeRoot = join(configDir, 'secrets', 'agents');
|
||||
mkdirSync(join(dir, 'data'), { mode: 0o700 });
|
||||
const store = new Store(join(dir, 'data'));
|
||||
const credentials = new Credentials({ references: {}, storeRoot, dataRoot: join(dir, 'data') });
|
||||
t.after(() => {
|
||||
credentials.close();
|
||||
store.close();
|
||||
});
|
||||
const business = {
|
||||
id: 'demo',
|
||||
human: 'jason',
|
||||
arbiters: { technical: 'pm', delivery: 'pm' },
|
||||
roles: {
|
||||
chief: { definition: 'chief-of-staff', ...none }, pm: { definition: 'pm', ...none }, ops: { definition: 'ops', ...none },
|
||||
...(opts.assistant ? { assistant: { definition: 'assistant', ...none } } : {}),
|
||||
},
|
||||
definitions: { ...structuredClone(DEFINITIONS), ...(opts.assistant ? { assistant: { roleVersion: 2, credentials: [] } } : {}) },
|
||||
vars: { 'bus.tester': true },
|
||||
};
|
||||
const broker = new Broker({
|
||||
store,
|
||||
businesses: { demo: business },
|
||||
secretCheck: (value) => credentials.assertClean(value),
|
||||
hostGrant: (opts.wrap ?? ((h) => h))(hostGrant({ configDir, runRoot, installerUser: USER, scan: async () => [pubLine(join(dir, 'hostkey'))] })),
|
||||
hostKeys: grantKeys({ credentials, storeRoot }),
|
||||
});
|
||||
const caps = {};
|
||||
for (const role of ['chief', 'pm']) {
|
||||
caps[role] = broker.bindLaunch({ business: 'demo', role, run: role + '-run', harness: 'pi', address: role });
|
||||
broker.request(caps[role], { verb: 'role.claim' });
|
||||
}
|
||||
caps.human = broker.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
||||
const entry = { address: '127.0.0.1', port, user: USER, hostKeys: [pubLine(join(dir, 'hostkey'))] };
|
||||
if (!opts.enroll) hostRecord(store, { host: 'web1', entry });
|
||||
const call = (who, verb, args = {}) => broker.request(caps[who], { verb, args });
|
||||
const raise = (grant = {}) =>
|
||||
call('chief', 'decision.raise', {
|
||||
action: 'credential.mint', question: 'Grant ops web1?', options, recommendation: 'yes', blocking: false,
|
||||
grant: { method: 'host', agent: 'ops', host: 'web1', commands: [['systemctl', 'status']], rotateBy: dayFrom(30), ...grant },
|
||||
});
|
||||
const grantEvents = () =>
|
||||
store
|
||||
.all("SELECT body FROM events WHERE business='demo' AND kind='action.allowed' AND actor_run='grant' ORDER BY seq")
|
||||
.map((e) => JSON.parse(e.body))
|
||||
.filter((b) => b.action?.startsWith('grant.'));
|
||||
const ended = (decision) => grantEvents().find((e) => e.grantDecision === decision && ['grant.applied', 'grant.failed'].includes(e.action));
|
||||
// The human's cli yes starts the executor; this waits for its end.
|
||||
const approve = async (grant) => {
|
||||
const d = await raise(grant);
|
||||
call('human', 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
await until(() => ended(d.id));
|
||||
return { id: d.id, end: ended(d.id) };
|
||||
};
|
||||
// A decision put in by SQL, with R4's body built here so one field can be broken.
|
||||
const fixtureGrant = (over = {}, close) => {
|
||||
const commands = over.commands ?? [['uptime']];
|
||||
const grant = {
|
||||
method: 'host', agent: 'ops', host: 'web1', commands, commandsSha256: sha256(JSON.stringify(commands)), rotateBy: dayFrom(30),
|
||||
registrySha256: registrySha256({ ...entry, sudo: true }), definitionSha256: definitionSha256(DEFINITIONS.ops), ...over,
|
||||
};
|
||||
return grantDecision(store, { grant, ...(close !== undefined ? { close } : {}) });
|
||||
};
|
||||
const tag = grantTag('demo', 'ops', 'web1');
|
||||
const keyFile = join(storeRoot, 'demo', 'ops', 'host.web1');
|
||||
const record = () => store.get("SELECT * FROM host_grants WHERE business='demo' AND agent='ops' AND host='web1'");
|
||||
const requests = () => readOr(join(dir, 'requests.log'), '').split('\n').filter(Boolean);
|
||||
const granted = () => readOr(join(dir, 'granted'), '').split('\n').filter(Boolean);
|
||||
const state = () => credentials.status().find((e) => e.instance === 'demo/ops' && e.service === 'host.web1')?.state;
|
||||
// The executor's notices, apart from the close notice the resolve sends the chief.
|
||||
const messages = (decision) =>
|
||||
store.all("SELECT to_role, body FROM messages WHERE business=? AND decision=? AND from_role='_bus' AND instr(body, ?) ORDER BY rowid", 'demo', decision, `(decision ${decision})`);
|
||||
const flag = (name) => writeFileSync(join(dir, name), '');
|
||||
return { caps, dir, port, entry, store, broker, credentials, call, raise, approve, fixtureGrant, grantEvents, ended, tag, keyFile, record, requests, granted, state, messages, flag, runRoot, storeRoot, configDir, business };
|
||||
}
|
||||
|
||||
// A restart as runtime.mjs does it, on the same store: the key sweep, Credentials with a reference per
|
||||
// record, a new broker, reconcileGrants before the socket opens, then reconcileHosts. `busy` is the
|
||||
// slot between the two.
|
||||
async function restart(t, f, business = f.business) {
|
||||
const granted = new Set();
|
||||
const references = {};
|
||||
for (const g of f.store.all('SELECT business, agent, host, rotate_by FROM host_grants')) {
|
||||
granted.add(`${g.business}/${g.agent}/${g.host}`);
|
||||
(references[`${g.business}/${g.agent}`] ??= {})['host.' + g.host] = hostReference(f.storeRoot, g.business, g.agent, g.host, g.rotate_by);
|
||||
}
|
||||
const swept = sweepHostKeys(f.storeRoot, ['demo'], granted);
|
||||
const credentials = new Credentials({ references, storeRoot: f.storeRoot, dataRoot: join(f.dir, 'data') });
|
||||
t.after(() => credentials.close());
|
||||
const broker = new Broker({
|
||||
store: f.store,
|
||||
businesses: { demo: business },
|
||||
secretCheck: (value) => credentials.assertClean(value),
|
||||
hostGrant: hostGrant({ configDir: f.configDir, runRoot: f.runRoot, installerUser: USER }),
|
||||
hostKeys: grantKeys({ credentials, storeRoot: f.storeRoot }),
|
||||
});
|
||||
const now = broker.reconcileGrants();
|
||||
const busy = credentials.busy('demo/ops', 'host.web1');
|
||||
const later = await broker.reconcileHosts();
|
||||
const state = credentials.status().find((e) => e.instance === 'demo/ops' && e.service === 'host.web1')?.state;
|
||||
return { swept, credentials, broker, now, busy, later, state };
|
||||
}
|
||||
|
||||
// The business after the human moved ops's instance to the creative `research` definition, which has
|
||||
// ops's content, so the grant's definitionSha256 still matches and only the creative check refuses.
|
||||
const creativeOps = (business) => ({
|
||||
...structuredClone(business),
|
||||
roles: { ...structuredClone(business.roles), ops: { ...structuredClone(business.roles.ops), definition: 'research' } },
|
||||
definitions: { ...structuredClone(business.definitions), research: structuredClone(DEFINITIONS.ops) },
|
||||
});
|
||||
|
||||
// A decision the human approved and a killed bus child spent, with its grant.step events up to `steps`.
|
||||
function interrupted(f, steps, over = {}) {
|
||||
const id = f.fixtureGrant(over);
|
||||
writeGrantEvent(f.store, AT, 'demo', { operation: 'grant.host', decision: id }, id);
|
||||
for (const [step, extra = {}] of steps)
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.step', grantDecision: id, agent: 'ops', host: 'web1', user: USER, tag: f.tag, step, ...extra }, 'web1');
|
||||
return id;
|
||||
}
|
||||
|
||||
// The line an interrupted add left: a key nobody holds, under the grant's tag.
|
||||
function leftLine(f) {
|
||||
keygen(join(f.dir, 'orphan'));
|
||||
writeFileSync(join(f.dir, 'granted'), `restrict ${pubLine(join(f.dir, 'orphan'))} ${f.tag}\n`);
|
||||
}
|
||||
|
||||
test('G7: an Approve installs the tagged line, logs in with the new key, and writes the key file, record and grant.applied', async (t) => {
|
||||
const f = await setup(t);
|
||||
const { id, end } = await f.approve();
|
||||
assert.equal(end.action, 'grant.applied');
|
||||
const key = parseHostKey(readFileSync(f.keyFile, 'utf8'));
|
||||
assert.deepEqual(end, {
|
||||
action: 'grant.applied', grantDecision: id, agent: 'ops', host: 'web1', user: USER, tag: f.tag,
|
||||
fingerprint: key.fingerprint, commandsSha256: sha256(JSON.stringify([['systemctl', 'status']])),
|
||||
});
|
||||
assert.equal(f.tag.length, 39);
|
||||
assert.deepEqual(f.requests(), [`list ${USER}`, `add ${USER} ${key.publicLine} ${f.tag}`, 'true']);
|
||||
assert.deepEqual(f.granted(), [`restrict ${key.publicLine} ${f.tag}`]);
|
||||
assert.equal(statSync(f.keyFile).mode & 0o777, 0o600);
|
||||
assert.deepEqual({ ...f.record() }, {
|
||||
business: 'demo', agent: 'ops', host: 'web1', commands: '[["systemctl","status"]]', rotate_by: dayFrom(30), tag: f.tag, decision: id,
|
||||
});
|
||||
assert.equal(f.state(), 'valid');
|
||||
assert.deepEqual(
|
||||
f.grantEvents().filter((e) => e.grantDecision === id).map((e) => e.action + (e.step ? ' ' + e.step : '')),
|
||||
['grant.step install', 'grant.step commit', 'grant.applied'],
|
||||
);
|
||||
assert.equal(f.grantEvents().find((e) => e.step === 'commit').previous, null);
|
||||
assert.deepEqual(f.messages(id).map((m) => m.to_role), ['human', 'chief']);
|
||||
// The key file logs in as the user, and the slot is free again.
|
||||
const out = await runHost({ root: f.runRoot, hostId: 'web1', entry: f.entry, key, timeout: 10, command: 'true' });
|
||||
assert.equal(out.exit, 0);
|
||||
f.credentials.release('demo/ops', 'host.web1', f.credentials.claim('demo/ops', 'host.web1'));
|
||||
});
|
||||
|
||||
test('G7: a commands change on a live grant updates the record in one transaction and keeps the key and line', async (t) => {
|
||||
const f = await setup(t);
|
||||
const first = await f.approve();
|
||||
const before = readFileSync(f.keyFile, 'utf8');
|
||||
const asked = f.requests().length;
|
||||
const { id, end } = await f.approve({ commands: [['uptime'], ['systemctl', 'status']] });
|
||||
assert.equal(end.action, 'grant.applied');
|
||||
assert.equal(end.fingerprint, null);
|
||||
assert.equal(f.requests().length, asked);
|
||||
assert.equal(readFileSync(f.keyFile, 'utf8'), before);
|
||||
assert.equal(f.record().commands, '[["uptime"],["systemctl","status"]]');
|
||||
assert.equal(f.record().decision, id);
|
||||
assert.deepEqual(f.grantEvents().find((e) => e.grantDecision === id && e.step === 'commit').previous, [['systemctl', 'status']]);
|
||||
assert.equal(f.grantEvents().some((e) => e.grantDecision === id && e.step === 'install'), false);
|
||||
assert.equal(f.state(), 'valid');
|
||||
assert.notEqual(first.id, id);
|
||||
});
|
||||
|
||||
test('G8: a failure at install or verify removes the line and leaves no record, key file or reference', async (t) => {
|
||||
for (const flag of ['fail-list', 'fail-add', 'noop-add']) {
|
||||
const f = await setup(t);
|
||||
f.flag(flag);
|
||||
const { id, end } = await f.approve();
|
||||
assert.equal(end.code, 'host-failed', flag);
|
||||
assert.equal(end.tag, f.tag);
|
||||
assert.equal('hostLineLeft' in end, false);
|
||||
assert.equal(f.requests().at(-1), `remove ${USER} ${f.tag}`, flag);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.equal(f.state(), undefined);
|
||||
assert.deepEqual(f.grantEvents().filter((e) => e.grantDecision === id).map((e) => e.action), ['grant.step', 'grant.failed']);
|
||||
assert.match(f.messages(id)[0].body, /failed: host-failed\.$/);
|
||||
}
|
||||
});
|
||||
|
||||
test('G8: a failed remove adds hostLineLeft and tells the human to sweep', async (t) => {
|
||||
const f = await setup(t);
|
||||
f.flag('noop-add');
|
||||
f.flag('fail-remove');
|
||||
const { id, end } = await f.approve();
|
||||
assert.equal(end.code, 'host-failed');
|
||||
assert.equal(end.hostLineLeft, f.tag);
|
||||
assert.match(f.messages(id)[0].body, new RegExp(`tagged ${f.tag} may be left on the host\\. Run: mosaic hosts sweep web1$`));
|
||||
});
|
||||
|
||||
test('G8: a failure in step 5 before commit unlinks the key file, drops the reference and removes the line', async (t) => {
|
||||
const f = await setup(t);
|
||||
// A file where the agent's store dir goes makes issue refuse credential-file.
|
||||
mkdirSync(f.storeRoot, { recursive: true, mode: 0o700 });
|
||||
writeFileSync(join(f.storeRoot, 'demo'), '');
|
||||
const { id, end } = await f.approve();
|
||||
assert.equal(end.code, 'credential-file');
|
||||
assert.equal(f.requests().at(-1), `remove ${USER} ${f.tag}`);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(f.state(), undefined);
|
||||
assert.deepEqual(f.grantEvents().filter((e) => e.grantDecision === id).map((e) => e.action + (e.step ? ' ' + e.step : '')), [
|
||||
'grant.step install', 'grant.step commit', 'grant.failed',
|
||||
]);
|
||||
});
|
||||
|
||||
// A store fault at commit (a full disk, an I/O error, a busy timeout): the record's INSERT throws once,
|
||||
// after issue wrote the key file. The undo unlinks it, drops the reference and removes the line.
|
||||
test('G8: a store fault in the commit transaction ends host-failed with no record, key file, reference or line', async (t) => {
|
||||
const f = await setup(t);
|
||||
const run = f.store.run.bind(f.store);
|
||||
let faults = 0;
|
||||
f.store.run = (sql, ...args) => {
|
||||
if (sql.startsWith('INSERT INTO host_grants') && faults++ === 0) throw Object.assign(new Error('database or disk is full'), { code: 'SQLITE_FULL' });
|
||||
return run(sql, ...args);
|
||||
};
|
||||
const { id, end } = await f.approve();
|
||||
assert.equal(faults, 1);
|
||||
assert.equal(end.code, 'host-failed');
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.equal(f.state(), undefined);
|
||||
assert.equal(f.requests().at(-1), `remove ${USER} ${f.tag}`);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.deepEqual(f.grantEvents().filter((e) => e.grantDecision === id).map((e) => e.action + (e.step ? ' ' + e.step : '')), [
|
||||
'grant.step install', 'grant.step commit', 'grant.failed',
|
||||
]);
|
||||
});
|
||||
|
||||
test('G8: a failed step 1 check spends the decision and runs nothing remote', async (t) => {
|
||||
const f = await setup(t);
|
||||
const d = await f.raise();
|
||||
f.store.run("UPDATE hosts SET state='pending-install' WHERE business='demo' AND host='web1'");
|
||||
f.call('human', 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
await until(() => f.ended(d.id));
|
||||
assert.equal(f.ended(d.id).code, 'host-not-ready');
|
||||
assert.deepEqual(f.requests(), []);
|
||||
assert.equal(await f.broker.runHostGrant('demo', d.id), 'decision-consumed');
|
||||
});
|
||||
|
||||
test('G9: a registry, definition or commands change between raise and Approve ends decision-mismatch before any remote step', async (t) => {
|
||||
const f = await setup(t);
|
||||
for (const over of [
|
||||
{ registrySha256: registrySha256({ ...f.entry, port: f.entry.port + 1, sudo: true }) },
|
||||
{ registrySha256: registrySha256({ ...f.entry, sudo: false }) },
|
||||
{ definitionSha256: definitionSha256({ ...DEFINITIONS.ops, roleVersion: 3 }) },
|
||||
{ commandsSha256: sha256(JSON.stringify([['uptime'], ['reboot']])) },
|
||||
]) {
|
||||
const id = f.fixtureGrant(over);
|
||||
assert.equal(await f.broker.runHostGrant('demo', id), 'decision-mismatch');
|
||||
assert.equal(f.ended(id).code, 'decision-mismatch');
|
||||
}
|
||||
// The control passes step 1 and goes remote.
|
||||
const id = f.fixtureGrant();
|
||||
assert.equal(await f.broker.runHostGrant('demo', id), 'applied');
|
||||
assert.deepEqual(f.requests().slice(0, 1), [`list ${USER}`]);
|
||||
assert.equal(f.requests().length, 3);
|
||||
});
|
||||
|
||||
test('G9: an agent no longer a role or no longer declaring host ends with its code, spent', async (t) => {
|
||||
const f = await setup(t);
|
||||
for (const [over, code] of [[{ agent: 'nobody' }, 'unknown-role'], [{ agent: 'pm' }, 'host-not-declared'], [{ host: 'web9' }, 'host-unknown']]) {
|
||||
const id = f.fixtureGrant(over);
|
||||
assert.equal(await f.broker.runHostGrant('demo', id), code);
|
||||
assert.equal(f.ended(id).code, code);
|
||||
assert.equal(await f.broker.runHostGrant('demo', id), 'decision-consumed');
|
||||
}
|
||||
assert.deepEqual(f.requests(), []);
|
||||
});
|
||||
|
||||
test('G10: a second start refuses decision-consumed, and an unresolved or agent-resolved decision not-authorized, writing nothing', async (t) => {
|
||||
const f = await setup(t);
|
||||
const { id } = await f.approve();
|
||||
const count = () => f.store.get("SELECT count(*) AS n FROM events WHERE business='demo'").n;
|
||||
// Each fixture decision writes one events row of its own, so the count starts after both.
|
||||
const fixtures = count();
|
||||
const open = f.fixtureGrant({}, null);
|
||||
const byAgent = f.fixtureGrant({}, { op: 'resolved', by: 'pm', choice: 'yes', via: 'broker' });
|
||||
assert.equal(count(), fixtures + 2);
|
||||
const before = count();
|
||||
assert.equal(await f.broker.runHostGrant('demo', id), 'decision-consumed');
|
||||
assert.equal(await f.broker.runHostGrant('demo', open), 'not-authorized');
|
||||
assert.equal(await f.broker.runHostGrant('demo', byAgent), 'not-authorized');
|
||||
assert.equal(count(), before);
|
||||
// The enrollment executor won't take a host grant either.
|
||||
assert.equal(await f.broker.runEnrollment('demo', f.fixtureGrant()), 'not-authorized');
|
||||
});
|
||||
|
||||
test('G15: no event, message or decision holds the private key', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
const pem = readFileSync(f.keyFile, 'utf8');
|
||||
const body = pem.split('\n').slice(1, -2).join('');
|
||||
const text = [
|
||||
...f.store.all('SELECT body FROM events').map((r) => r.body),
|
||||
...f.store.all('SELECT body FROM messages').map((r) => r.body),
|
||||
...f.store.all('SELECT question FROM decisions').map((r) => r.question),
|
||||
].join('\n');
|
||||
assert.ok(body.length > 64);
|
||||
for (const line of pem.split('\n').slice(1, -2).filter((l) => l.length >= 20)) assert.equal(text.includes(line), false);
|
||||
assert.equal(text.includes('PRIVATE KEY'), false);
|
||||
assert.equal(readOr(join(f.dir, 'requests.log'), '').includes('PRIVATE KEY'), false);
|
||||
});
|
||||
|
||||
test('G23: a revoke during install ends grant.failed revoked with no key file, no grant and no line', async (t) => {
|
||||
const f = await setup(t);
|
||||
f.flag('hold-add');
|
||||
const d = await f.raise();
|
||||
f.call('human', 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
await until(() => existsSync(join(f.dir, 'holding')));
|
||||
assert.deepEqual(f.credentials.abortClaim('demo/ops', 'host.web1'), { pending: true });
|
||||
await until(() => f.ended(d.id));
|
||||
// The held add then exits without writing, as a killed session's would.
|
||||
f.flag('skip');
|
||||
f.flag('release');
|
||||
assert.equal(f.ended(d.id).code, 'revoked');
|
||||
assert.equal(f.requests().at(-1), `remove ${USER} ${f.tag}`);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.equal(f.state(), undefined);
|
||||
assert.equal(f.credentials.busy('demo/ops', 'host.web1'), false);
|
||||
});
|
||||
|
||||
test('G23: a revoke recorded after the raise and before the start ends step 1 revoked, and a held slot ends host-busy', async (t) => {
|
||||
const f = await setup(t);
|
||||
const revoked = f.fixtureGrant();
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.revoked', agent: 'ops', host: 'web1', tag: f.tag, hostLine: 'pending', by: 'jason' }, 'web1');
|
||||
assert.equal(await f.broker.runHostGrant('demo', revoked), 'revoked');
|
||||
// A revoke of another agent or host doesn't count, and one before the raise doesn't either.
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.revoked', agent: 'pm', host: 'web1', tag: f.tag, hostLine: 'pending', by: 'jason' }, 'web1');
|
||||
const busy = f.fixtureGrant();
|
||||
const signal = f.credentials.claim('demo/ops', 'host.web1');
|
||||
assert.equal(await f.broker.runHostGrant('demo', busy), 'host-busy');
|
||||
assert.equal(f.ended(busy).code, 'host-busy');
|
||||
assert.match(f.messages(busy)[0].body, /failed: host-busy\.$/);
|
||||
assert.equal(await f.broker.runHostGrant('demo', busy), 'decision-consumed');
|
||||
f.credentials.release('demo/ops', 'host.web1', signal);
|
||||
assert.deepEqual(f.requests(), []);
|
||||
assert.equal(await f.broker.runHostGrant('demo', f.fixtureGrant()), 'applied');
|
||||
});
|
||||
|
||||
test('G24: names at 64 characters with . and _ give distinct tags of the fixed length', () => {
|
||||
const long = (c) => ('a' + c).repeat(32);
|
||||
const tags = [
|
||||
grantTag('demo', long('.'), 'web1'),
|
||||
grantTag('demo', long('_'), 'web1'),
|
||||
grantTag('demo.' + 'x'.repeat(59), 'ops', 'web1'),
|
||||
grantTag('demo', 'ops', 'web1'),
|
||||
grantTag('demo', 'ops', 'web2'),
|
||||
grantTag('other', 'ops', 'web1'),
|
||||
];
|
||||
assert.equal(new Set(tags).size, tags.length);
|
||||
for (const tag of tags) assert.match(tag, /^mosaic-[0-9a-f]{32}$/);
|
||||
});
|
||||
|
||||
test('G11: a restart after install removes the line, then ends interrupted with the tag, holding the slot until then', async (t) => {
|
||||
const f = await setup(t);
|
||||
const id = interrupted(f, [['install']]);
|
||||
leftLine(f);
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual(r.now, []);
|
||||
assert.equal(r.busy, true);
|
||||
assert.deepEqual(r.later, [id]);
|
||||
assert.equal(r.credentials.busy('demo/ops', 'host.web1'), false);
|
||||
assert.deepEqual(f.requests(), [`remove ${USER} ${f.tag}`]);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.deepEqual(f.ended(id), { action: 'grant.failed', grantDecision: id, agent: 'ops', host: 'web1', code: 'interrupted', tag: f.tag });
|
||||
assert.deepEqual(f.messages(id).map((m) => m.to_role), ['human', 'chief']);
|
||||
assert.match(f.messages(id)[0].body, /failed: interrupted\.$/);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(r.state, undefined);
|
||||
// It never runs late, and a second start finds it ended.
|
||||
assert.equal(await r.broker.runHostGrant('demo', id), 'decision-consumed');
|
||||
const again = await restart(t, f);
|
||||
assert.deepEqual([again.now, again.later], [[], []]);
|
||||
});
|
||||
|
||||
test('G11: a restart after a new key\'s commit, with the key file written, ends with no key file, record, reference or line', async (t) => {
|
||||
const f = await setup(t);
|
||||
const id = interrupted(f, [['install'], ['commit', { previous: null }]]);
|
||||
leftLine(f);
|
||||
mkdirSync(join(f.storeRoot, 'demo', 'ops'), { recursive: true, mode: 0o700 });
|
||||
chmodSync(f.storeRoot, 0o700);
|
||||
chmodSync(join(f.storeRoot, 'demo'), 0o700);
|
||||
keygen(f.keyFile);
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual(r.swept, [{ instance: 'demo/ops', service: 'host.web1' }]);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
// ssh-keygen's .pub isn't a host.<id> name, so the sweep leaves it.
|
||||
assert.equal(existsSync(f.keyFile + '.pub'), true);
|
||||
assert.deepEqual(r.later, [id]);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(r.state, undefined);
|
||||
assert.equal(f.ended(id).code, 'interrupted');
|
||||
});
|
||||
|
||||
test('G11: a restart after a commands change\'s commit leaves the record as it was and asks nothing of the host', async (t) => {
|
||||
const f = await setup(t);
|
||||
const first = await f.approve();
|
||||
const before = { record: { ...f.record() }, key: readFileSync(f.keyFile, 'utf8'), granted: f.granted(), asked: f.requests().length };
|
||||
const id = interrupted(f, [['commit', { previous: [['systemctl', 'status']] }]], { commands: [['uptime']] });
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual(r.now, [id]);
|
||||
assert.equal(r.busy, false);
|
||||
assert.deepEqual(r.later, []);
|
||||
assert.deepEqual({ ...f.record() }, before.record);
|
||||
assert.equal(f.record().decision, first.id);
|
||||
assert.equal(readFileSync(f.keyFile, 'utf8'), before.key);
|
||||
assert.deepEqual(f.granted(), before.granted);
|
||||
assert.equal(f.requests().length, before.asked);
|
||||
assert.equal(r.state, 'valid');
|
||||
assert.deepEqual(f.ended(id), { action: 'grant.failed', grantDecision: id, agent: 'ops', host: 'web1', code: 'interrupted', tag: f.tag });
|
||||
// The applied grant isn't touched.
|
||||
assert.equal(f.ended(first.id).action, 'grant.applied');
|
||||
});
|
||||
|
||||
test('G11 (B2): a restart before step 1, spent or not yet spent, ends interrupted and nothing runs later', async (t) => {
|
||||
const f = await setup(t);
|
||||
const spent = interrupted(f, []);
|
||||
const open = f.fixtureGrant();
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual(r.now, [spent, open]);
|
||||
assert.deepEqual(r.later, []);
|
||||
assert.deepEqual(f.requests(), []);
|
||||
for (const id of [spent, open]) {
|
||||
assert.equal(f.ended(id).code, 'interrupted');
|
||||
assert.equal(f.ended(id).tag, f.tag);
|
||||
assert.equal(f.messages(id).length, 2);
|
||||
assert.equal(await r.broker.runHostGrant('demo', id), 'decision-consumed');
|
||||
}
|
||||
// The open one was spent once, by the reconcile.
|
||||
assert.equal(f.store.get("SELECT count(*) AS n FROM events WHERE kind='action.allowed' AND actor_run='grant' AND json_extract(body,'$.operation')='grant.host' AND json_extract(body,'$.decision')=?", open).n, 1);
|
||||
assert.equal(f.record(), undefined);
|
||||
});
|
||||
|
||||
test('G11: a remote undo that fails ends interrupted with hostLineLeft and the sweep hint', async (t) => {
|
||||
const f = await setup(t);
|
||||
const id = interrupted(f, [['install']]);
|
||||
leftLine(f);
|
||||
f.flag('fail-remove');
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual(r.later, [id]);
|
||||
assert.deepEqual(f.ended(id), { action: 'grant.failed', grantDecision: id, agent: 'ops', host: 'web1', code: 'interrupted', tag: f.tag, hostLineLeft: f.tag });
|
||||
assert.match(f.messages(id)[0].body, new RegExp(`tagged ${f.tag} may be left on the host\\. Run: mosaic hosts sweep web1$`));
|
||||
assert.equal(f.granted().length, 1);
|
||||
assert.equal(r.credentials.busy('demo/ops', 'host.web1'), false);
|
||||
// The same with the host record gone: nothing to reach, so the line is left.
|
||||
const g = await setup(t);
|
||||
const id2 = interrupted(g, [['install']]);
|
||||
g.store.transaction(() => {
|
||||
g.store.run("DELETE FROM hosts WHERE business='demo' AND host='web1'");
|
||||
writeGrantEvent(g.store, AT, 'demo', { action: 'grant.host.removed', host: 'web1', by: 'jason' }, 'web1');
|
||||
});
|
||||
const r2 = await restart(t, g);
|
||||
assert.deepEqual(r2.later, [id2]);
|
||||
assert.equal(g.ended(id2).hostLineLeft, g.tag);
|
||||
assert.deepEqual(g.requests(), []);
|
||||
});
|
||||
|
||||
test('G11: a restart leaves a finished grant alone, and the reconcile adds nothing for it', async (t) => {
|
||||
const f = await setup(t);
|
||||
const { id } = await f.approve();
|
||||
const events = f.grantEvents().length;
|
||||
const asked = f.requests().length;
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual([r.swept, r.now, r.later], [[], [], []]);
|
||||
assert.equal(f.grantEvents().length, events);
|
||||
assert.equal(f.requests().length, asked);
|
||||
assert.equal(existsSync(f.keyFile), true);
|
||||
assert.equal(r.state, 'valid');
|
||||
assert.equal(f.ended(id).action, 'grant.applied');
|
||||
});
|
||||
|
||||
test('N1 (G27): the start sweep unlinks host.<id> files with no record in loaded businesses only, and refuses a store dir that is not private', (t) => {
|
||||
const root = mkdtempSync(join(tmpdir(), 'g235s-'));
|
||||
t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||
const storeRoot = join(root, 'agents');
|
||||
assert.deepEqual(sweepHostKeys(storeRoot, ['demo'], new Set()), []);
|
||||
assert.deepEqual(sweepHostKeys(null, ['demo'], new Set()), []);
|
||||
const put = (business, agent, name) => {
|
||||
const d = join(storeRoot, business, agent);
|
||||
mkdirSync(d, { recursive: true, mode: 0o700 });
|
||||
for (const x of [storeRoot, join(storeRoot, business), d]) chmodSync(x, 0o700);
|
||||
writeFileSync(join(d, name), 'k', { mode: 0o600 });
|
||||
return join(d, name);
|
||||
};
|
||||
const kept = put('demo', 'ops', 'host.web1');
|
||||
const gone = put('demo', 'ops', 'host.web2');
|
||||
const goneToo = put('demo', 'pm', 'host.web1');
|
||||
const other = [put('demo', 'ops', 'gitea'), put('demo', 'ops', 'host.Web3'), put('demo', 'ops', 'host.'), put('other', 'ops', 'host.web1')];
|
||||
const swept = sweepHostKeys(storeRoot, ['demo'], new Set(['demo/ops/web1']));
|
||||
assert.deepEqual(swept.sort((a, b) => a.instance.localeCompare(b.instance) || a.service.localeCompare(b.service)), [
|
||||
{ instance: 'demo/ops', service: 'host.web2' },
|
||||
{ instance: 'demo/pm', service: 'host.web1' },
|
||||
]);
|
||||
assert.equal(existsSync(kept), true);
|
||||
assert.equal(existsSync(gone), false);
|
||||
assert.equal(existsSync(goneToo), false);
|
||||
for (const file of other) assert.equal(existsSync(file), true, file);
|
||||
chmodSync(join(storeRoot, 'demo', 'ops'), 0o750);
|
||||
assert.throws(() => sweepHostKeys(storeRoot, ['demo'], new Set()), /credential-file/);
|
||||
assert.equal(existsSync(kept), true);
|
||||
});
|
||||
|
||||
// Row 235 step 5 (r6 section 6): an assistant thread in the business, for G26.
|
||||
function assistant(f) {
|
||||
const project = f.call('human', 'project.create', { name: 'hosts' }).id;
|
||||
const thread = f.call('human', 'thread.create', { project, name: 'main' }).id;
|
||||
f.caps.assistant = f.broker.bindLaunch({ business: 'demo', role: 'assistant', run: 'a-run', harness: 'pi', thread });
|
||||
f.broker.request(f.caps.assistant, { verb: 'role.claim' });
|
||||
}
|
||||
const refusesWith = async (p, code) => assert.rejects(Promise.resolve().then(() => p), (e) => (assert.equal(e.code, code), true));
|
||||
const revokeBodies = (f) => f.grantEvents().filter((e) => ['grant.revoked', 'grant.revoke.closed'].includes(e.action));
|
||||
|
||||
test('G12: the human\'s hosts.revoke deletes the record, the key file, the reference and the line, with a closed marker', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
const asked = f.requests().length;
|
||||
const r = await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'done' });
|
||||
assert.deepEqual(r, { agent: 'ops', host: 'web1', tag: f.tag, granted: true, keyFile: 'removed', hostLine: 'removed' });
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.notEqual(f.state(), 'valid');
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.deepEqual(f.requests().slice(asked), [`remove ${USER} ${f.tag}`]);
|
||||
const [open, closed] = revokeBodies(f);
|
||||
assert.equal(typeof open.revoke, 'string');
|
||||
assert.deepEqual(open, { action: 'grant.revoked', revoke: open.revoke, agent: 'ops', host: 'web1', tag: f.tag, hostLine: 'pending', granted: true, reason: 'done', by: 'jason' });
|
||||
assert.deepEqual(closed, { action: 'grant.revoke.closed', revoke: open.revoke, agent: 'ops', host: 'web1', tag: f.tag, hostLine: 'removed', by: 'jason' });
|
||||
const [row] = await f.call('human', 'hosts.status');
|
||||
assert.deepEqual([row.revoking, row.hostLineLeft], [[], []]);
|
||||
// A restart finds the revoke closed and does nothing for it.
|
||||
const again = await restart(t, f);
|
||||
assert.deepEqual([again.swept, again.now, again.later], [[], [], []]);
|
||||
assert.equal(again.state, undefined);
|
||||
});
|
||||
|
||||
test('G12 (N4): a revoke with no record still removes the computed tag\'s line, with granted false; bad args refuse', async (t) => {
|
||||
const f = await setup(t);
|
||||
leftLine(f);
|
||||
const r = await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'stale line' });
|
||||
assert.deepEqual(r, { agent: 'ops', host: 'web1', tag: f.tag, granted: false, keyFile: 'removed', hostLine: 'removed' });
|
||||
assert.deepEqual(f.granted(), []);
|
||||
for (const args of [{ agent: 'ops', host: 'web1' }, { agent: 'ops', host: 'web1', reason: '' }, { agent: 'ops', host: 'web1', reason: 'x'.repeat(501) },
|
||||
{ agent: 'Ops!', host: 'web1', reason: 'r' }, { agent: 'ops', host: 'Web1', reason: 'r' }, { agent: 'ops', host: 'web1', reason: 'r', extra: 1 }])
|
||||
await refusesWith(f.call('human', 'hosts.revoke', args), 'invalid-request');
|
||||
await refusesWith(f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web9', reason: 'r' }), 'host-unknown');
|
||||
assert.equal(revokeBodies(f).length, 2);
|
||||
});
|
||||
|
||||
test('G13: a revoke during install aborts the executor, which ends revoked, and the line goes', async (t) => {
|
||||
const f = await setup(t);
|
||||
f.flag('hold-add');
|
||||
const d = await f.raise();
|
||||
f.call('human', 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
await until(() => existsSync(join(f.dir, 'holding')));
|
||||
const r = await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'stop' });
|
||||
assert.equal(r.granted, false);
|
||||
await until(() => f.ended(d.id));
|
||||
f.flag('skip');
|
||||
f.flag('release');
|
||||
assert.equal(f.ended(d.id).code, 'revoked');
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.equal(f.credentials.busy('demo/ops', 'host.web1'), false);
|
||||
// A decision raised before the revoke and started after it ends revoked at step 1.
|
||||
const late = await f.raise();
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.revoked', revoke: 'x', agent: 'ops', host: 'web1', tag: f.tag, hostLine: 'pending', by: 'jason' }, 'web1');
|
||||
f.call('human', 'decision.resolve', { id: late.id, choice: 'yes' });
|
||||
await until(() => f.ended(late.id));
|
||||
assert.equal(f.ended(late.id).code, 'revoked');
|
||||
});
|
||||
|
||||
test('G26: the human, the assistant and the tester revoke; the chief and a pm refuse; sweep is the human\'s or the tester\'s', async (t) => {
|
||||
const f = await setup(t, { assistant: true });
|
||||
assistant(f);
|
||||
f.caps.tester = f.broker.bindTester({ business: 'demo' });
|
||||
f.caps.reader = f.broker.bindReader({ business: 'demo' });
|
||||
const args = { agent: 'ops', host: 'web1', reason: 'r' };
|
||||
await refusesWith(f.call('chief', 'hosts.revoke', args), 'revoke-refused');
|
||||
await refusesWith(f.call('pm', 'hosts.revoke', args), 'revoke-refused');
|
||||
await refusesWith(f.call('reader', 'hosts.revoke', args), 'read-only');
|
||||
for (const who of ['chief', 'pm', 'assistant']) await refusesWith(f.call(who, 'hosts.sweep', { host: 'web1' }), 'human-required');
|
||||
assert.equal(revokeBodies(f).length, 0);
|
||||
assert.equal((await f.call('assistant', 'hosts.revoke', args)).agent, 'ops');
|
||||
assert.equal((await f.call('tester', 'hosts.revoke', args)).agent, 'ops');
|
||||
assert.deepEqual(revokeBodies(f).filter((e) => e.action === 'grant.revoked').map((e) => e.by), ['assistant', 'tester']);
|
||||
assert.deepEqual((await f.call('tester', 'hosts.sweep', { host: 'web1' })).removed, []);
|
||||
});
|
||||
|
||||
test('G27: a restart after step 1 sweeps the key file and runs step 3 once the bus is up; status shows the revoke until then', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
const revoke = 'b6d0f0c4-6c3e-4c35-9d55-1f3c2b8f0a11';
|
||||
// Step 1 as hosts.revoke writes it, then the bus dies.
|
||||
f.store.transaction(() => {
|
||||
f.store.run("DELETE FROM host_grants WHERE business='demo' AND agent='ops' AND host='web1'");
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.revoked', revoke, agent: 'ops', host: 'web1', tag: f.tag, hostLine: 'pending', granted: true, reason: 'r', by: 'jason' }, 'web1');
|
||||
});
|
||||
assert.deepEqual((await f.call('human', 'hosts.status'))[0].revoking, [f.tag]);
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual(r.swept, [{ instance: 'demo/ops', service: 'host.web1' }]);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.deepEqual(r.now, []);
|
||||
assert.deepEqual(r.later, [revoke]);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.equal(r.state, undefined);
|
||||
assert.deepEqual(revokeBodies(f).at(-1), { action: 'grant.revoke.closed', revoke, agent: 'ops', host: 'web1', tag: f.tag, hostLine: 'removed', by: 'jason' });
|
||||
assert.deepEqual((await r.broker.request(r.broker.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true }), { verb: 'hosts.status', args: {} }))[0].revoking, []);
|
||||
const again = await restart(t, f);
|
||||
assert.deepEqual([again.swept, again.later], [[], []]);
|
||||
});
|
||||
|
||||
test('G27: after step 2 with the host down, the restart closes the marker with hostLineLeft; a marker without a revoke id is not reopened', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
const revoke = 'c1d2e3f4-0000-4000-8000-000000000001';
|
||||
f.store.transaction(() => {
|
||||
f.store.run("DELETE FROM host_grants WHERE business='demo' AND agent='ops' AND host='web1'");
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.revoked', revoke, agent: 'ops', host: 'web1', tag: f.tag, hostLine: 'pending', granted: true, reason: 'r', by: 'jason' }, 'web1');
|
||||
});
|
||||
rmSync(f.keyFile);
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.revoked', agent: 'pm', host: 'web1', tag: f.tag, hostLine: 'pending', by: 'jason' }, 'web1');
|
||||
f.flag('fail-remove');
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual(r.swept, []);
|
||||
assert.deepEqual(r.later, [revoke]);
|
||||
assert.equal(revokeBodies(f).at(-1).hostLineLeft, f.tag);
|
||||
assert.equal(f.granted().length, 1);
|
||||
const human = r.broker.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
||||
assert.deepEqual((await r.broker.request(human, { verb: 'hosts.status', args: {} }))[0].hostLineLeft, [f.tag]);
|
||||
// The sweep then removes it and clears the left line.
|
||||
rmSync(join(f.dir, 'fail-remove'));
|
||||
assert.deepEqual(await r.broker.request(human, { verb: 'hosts.sweep', args: { host: 'web1' } }), { host: 'web1', removed: [f.tag], hostLineLeft: [] });
|
||||
assert.deepEqual(f.granted(), []);
|
||||
assert.deepEqual((await r.broker.request(human, { verb: 'hosts.status', args: {} }))[0].hostLineLeft, []);
|
||||
});
|
||||
|
||||
test('G27: a key file a revoke could not unlink is reported left and goes at the next start', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
const agentDir = join(f.storeRoot, 'demo', 'ops');
|
||||
// setup's t.after removes the scratch dir before any hook added here runs, so the body restores the mode.
|
||||
chmodSync(agentDir, 0o500);
|
||||
try {
|
||||
const r = await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'r' });
|
||||
assert.equal(r.keyFile, 'left');
|
||||
assert.equal(r.hostLine, 'removed');
|
||||
assert.equal(existsSync(f.keyFile), true);
|
||||
assert.notEqual(f.state(), 'valid');
|
||||
} finally {
|
||||
chmodSync(agentDir, 0o700);
|
||||
}
|
||||
const again = await restart(t, f);
|
||||
assert.deepEqual(again.swept, [{ instance: 'demo/ops', service: 'host.web1' }]);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.deepEqual(again.later, []);
|
||||
});
|
||||
|
||||
test('G28: a commands change, then a revoke, then a restart leave no record, key, reference or line', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
await f.approve({ commands: [['uptime']] });
|
||||
assert.equal(f.record().commands, '[["uptime"]]');
|
||||
await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'r' });
|
||||
const r = await restart(t, f);
|
||||
assert.deepEqual([r.swept, r.now, r.later], [[], [], []]);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.equal(r.state, undefined);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
});
|
||||
|
||||
test('G24 (B4): hosts.sweep removes only this business\'s recorded tags no live grant holds, and records what it left', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
const live = f.granted();
|
||||
const pmTag = grantTag('demo', 'pm', 'web1');
|
||||
const otherTag = grantTag('other', 'ops', 'web1');
|
||||
const unrecorded = 'mosaic-' + 'f'.repeat(32);
|
||||
keygen(join(f.dir, 'k2'));
|
||||
const line = (tag) => `restrict ${pubLine(join(f.dir, 'k2'))} ${tag}`;
|
||||
writeFileSync(join(f.dir, 'granted'), [...live, line(pmTag), line(otherTag), line(unrecorded), ''].join('\n'));
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.step', grantDecision: 'x', agent: 'pm', host: 'web1', user: USER, tag: pmTag, step: 'install' }, 'web1');
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.failed', grantDecision: 'x', agent: 'pm', host: 'web1', code: 'host-failed', tag: pmTag, hostLineLeft: pmTag }, 'web1');
|
||||
// A left tag no longer on the host drops out at the sweep.
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.failed', grantDecision: 'y', agent: 'pm', host: 'web1', code: 'host-failed', tag: 'mosaic-' + '1'.repeat(32), hostLineLeft: 'mosaic-' + '1'.repeat(32) }, 'web1');
|
||||
assert.equal((await f.call('human', 'hosts.status'))[0].hostLineLeft.length, 2);
|
||||
f.flag('fail-list');
|
||||
await refusesWith(f.call('human', 'hosts.sweep', { host: 'web1' }), 'host-failed');
|
||||
assert.equal(f.grantEvents().some((e) => e.action === 'grant.host.swept'), false);
|
||||
rmSync(join(f.dir, 'fail-list'));
|
||||
await refusesWith(f.call('human', 'hosts.sweep', { host: 'web9' }), 'host-unknown');
|
||||
const asked = f.requests().length;
|
||||
assert.deepEqual(await f.call('human', 'hosts.sweep', { host: 'web1' }), { host: 'web1', removed: [pmTag], hostLineLeft: [] });
|
||||
assert.deepEqual(f.requests().slice(asked), [`list ${USER}`, `remove ${USER} ${pmTag}`]);
|
||||
assert.deepEqual(f.granted(), [...live, line(otherTag), line(unrecorded)]);
|
||||
assert.deepEqual(f.grantEvents().at(-1), { action: 'grant.host.swept', host: 'web1', removed: [pmTag], left: [], by: 'jason' });
|
||||
assert.deepEqual((await f.call('human', 'hosts.status'))[0].hostLineLeft, []);
|
||||
// A later failure adds to the cleared list.
|
||||
writeGrantEvent(f.store, AT, 'demo', { action: 'grant.failed', grantDecision: 'z', agent: 'pm', host: 'web1', code: 'host-failed', tag: pmTag, hostLineLeft: pmTag }, 'web1');
|
||||
assert.deepEqual((await f.call('human', 'hosts.status'))[0].hostLineLeft, [pmTag]);
|
||||
assert.equal(f.state(), 'valid');
|
||||
});
|
||||
|
||||
test('G12: the local steps finish before the host step, so a host that hangs leaves the agent no access', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
f.flag('hold-remove');
|
||||
const revoking = f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'r' });
|
||||
await until(() => existsSync(join(f.dir, 'holding-remove')));
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.notEqual(f.state(), 'valid');
|
||||
assert.deepEqual((await f.call('human', 'hosts.status'))[0].revoking, [f.tag]);
|
||||
f.flag('release');
|
||||
assert.equal((await revoking).hostLine, 'removed');
|
||||
assert.deepEqual(f.granted(), []);
|
||||
});
|
||||
|
||||
// X5: the executor claims the slot in the same tick as its spend, so a revoke right after the start
|
||||
// call returns finds the claim and aborts it.
|
||||
test('G23 (X5): a revoke right after the spend reaches the executor\'s claim, so the grant ends revoked', async (t) => {
|
||||
const f = await setup(t);
|
||||
const id = f.fixtureGrant();
|
||||
const run = f.broker.runHostGrant('demo', id);
|
||||
const r = await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'r' });
|
||||
assert.equal(r.granted, false);
|
||||
assert.equal(await run, 'revoked');
|
||||
assert.equal(f.ended(id).code, 'revoked');
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.deepEqual(f.requests(), [`remove ${USER} ${f.tag}`]);
|
||||
});
|
||||
|
||||
// X5: the abort check after verify. The revoke lands once the login has worked and before the commit,
|
||||
// so only that check stops the record and key file.
|
||||
test('G23 (X5): a revoke that lands as verify returns ends revoked with no record, key file or line', async (t) => {
|
||||
let revoking;
|
||||
const f = await setup(t, {
|
||||
wrap: (hg) => ({
|
||||
...hg,
|
||||
verify: async (...args) => {
|
||||
const out = await hg.verify(...args);
|
||||
revoking = f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'r' });
|
||||
return out;
|
||||
},
|
||||
}),
|
||||
});
|
||||
const { id, end } = await f.approve();
|
||||
assert.equal(end.code, 'revoked');
|
||||
assert.equal((await revoking).granted, false);
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.equal(f.state(), undefined);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
// The check stops the grant before step 5, so no commit step is logged.
|
||||
assert.deepEqual(f.grantEvents().filter((e) => e.grantDecision === id && e.action === 'grant.step').map((e) => e.step), ['install']);
|
||||
});
|
||||
|
||||
test('G13: a revoke whose host remove fails still drops the record and key, and reports the line left for a sweep', async (t) => {
|
||||
const f = await setup(t);
|
||||
await f.approve();
|
||||
f.flag('fail-remove');
|
||||
const r = await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'r' });
|
||||
assert.deepEqual(r, { agent: 'ops', host: 'web1', tag: f.tag, granted: true, keyFile: 'removed', hostLineLeft: f.tag });
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.notEqual(f.state(), 'valid');
|
||||
assert.equal(f.granted().length, 1);
|
||||
assert.equal(revokeBodies(f).at(-1).hostLineLeft, f.tag);
|
||||
const [row] = await f.call('human', 'hosts.status');
|
||||
assert.deepEqual([row.revoking, row.hostLineLeft], [[], [f.tag]]);
|
||||
// The marker is closed, so a restart doesn't run step 3 again.
|
||||
const again = await restart(t, f);
|
||||
assert.deepEqual(again.later, []);
|
||||
});
|
||||
|
||||
// G22 (B1) on one bus with no restart. Enrollment refuses this machine's address, so the chief enrolls
|
||||
// 192.0.2.10 through the fake keyscan. The test then points the record at the scratch sshd and lets the
|
||||
// enrolled installer key log in there. Everything after that is the real path.
|
||||
test('G22: enroll, check, grant, host.run, a commands change the next host.run uses, and a revoke that kills a run in flight', async (t) => {
|
||||
const f = await setup(t, { enroll: true });
|
||||
const enroll = await f.call('chief', 'decision.raise', {
|
||||
action: 'credential.mint', question: 'Enroll web1?', options, recommendation: 'yes', blocking: false,
|
||||
grant: { method: 'host-enroll', host: 'web1', address: '192.0.2.10', port: 22, user: USER, sudo: true, fingerprints: [fingerprint(pubLine(join(f.dir, 'hostkey')))] },
|
||||
});
|
||||
f.call('human', 'decision.resolve', { id: enroll.id, choice: 'yes' });
|
||||
const enrolled = () => f.grantEvents().find((e) => e.grantDecision === enroll.id && ['grant.host.enrolled', 'grant.failed'].includes(e.action));
|
||||
await until(enrolled);
|
||||
assert.equal(enrolled().action, 'grant.host.enrolled');
|
||||
const installer = parseHostKey(readFileSync(join(f.configDir, 'secrets', 'hosts', 'demo', 'web1', 'installer'), 'utf8'));
|
||||
appendFileSync(join(f.dir, 'authorized_keys'), installer.publicLine + '\n');
|
||||
f.store.run("UPDATE hosts SET address='127.0.0.1', port=? WHERE business='demo' AND host='web1'", f.port);
|
||||
await refusesWith(f.raise(), 'host-not-ready');
|
||||
assert.equal((await f.call('chief', 'hosts.check', { host: 'web1' })).state, 'ready');
|
||||
assert.equal((await f.approve({ commands: [['echo']] })).end.action, 'grant.applied');
|
||||
f.caps.ops = f.broker.bindLaunch({ business: 'demo', role: 'ops', run: 'ops-run', harness: 'pi', address: 'ops' });
|
||||
f.broker.request(f.caps.ops, { verb: 'role.claim' });
|
||||
const executor = hostExecutor({ credentials: f.credentials, root: join(f.dir, 'host-run') });
|
||||
const run = async (argv) => {
|
||||
const d = await f.call('ops', 'decision.raise', { action: 'host.sudo', target: 'web1', argv, question: 'Run it?', options, recommendation: 'yes', blocking: false });
|
||||
f.call('human', 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
return f.broker.requestHost(f.caps.ops, { verb: 'host.run', args: { host: 'web1', argv, decision: d.id } }, executor);
|
||||
};
|
||||
const out = await run(['echo', 'hi']);
|
||||
assert.deepEqual([out.exit, out.stdout], [0, 'hi\n']);
|
||||
await refusesWith(run(['sleep', '30']), 'command-not-granted');
|
||||
assert.equal((await f.approve({ commands: [['echo'], ['sleep']] })).end.action, 'grant.applied');
|
||||
// The handler goes on at creation: the revoke rejects the run while the test still awaits the revoke.
|
||||
const slow = refusesWith(run(['sleep', '30']), 'credential-unavailable');
|
||||
await until(() => readOr(join(f.dir, 'sudo.log'), '').includes('sleep 30'));
|
||||
const r = await f.call('human', 'hosts.revoke', { agent: 'ops', host: 'web1', reason: 'done' });
|
||||
assert.deepEqual([r.granted, r.keyFile, r.hostLine], [true, 'removed', 'removed']);
|
||||
await slow;
|
||||
// The record goes at step 1, so the next call refuses at the record check, before the key (B1 names
|
||||
// credential-unavailable; BUILD.md records the difference).
|
||||
await refusesWith(f.broker.requestHost(f.caps.ops, { verb: 'host.run', args: { host: 'web1', argv: ['echo', 'hi'] } }, executor), 'host-not-granted');
|
||||
assert.equal(f.record(), undefined);
|
||||
assert.equal(existsSync(f.keyFile), false);
|
||||
assert.deepEqual(f.granted(), []);
|
||||
});
|
||||
|
||||
// The decision goes in after the restart, so the reconcile doesn't end it first.
|
||||
test('mos-1163: a grant whose agent became a creative role after the raise ends host-creative-role at step 1, spent, with nothing remote', async (t) => {
|
||||
const f = await setup(t);
|
||||
const r = await restart(t, f, creativeOps(f.business));
|
||||
const id = f.fixtureGrant();
|
||||
assert.equal(await r.broker.runHostGrant('demo', id), 'host-creative-role');
|
||||
assert.equal(f.ended(id).code, 'host-creative-role');
|
||||
assert.equal(await r.broker.runHostGrant('demo', id), 'decision-consumed');
|
||||
assert.deepEqual(f.requests(), []);
|
||||
assert.equal(f.record(), undefined);
|
||||
});
|
||||
|
||||
test('sage-1908: once the agent of an applied grant is a creative role, host.run refuses host-creative-role, runs nothing remote and keeps the record', async (t) => {
|
||||
const f = await setup(t);
|
||||
assert.equal((await f.approve()).end.action, 'grant.applied');
|
||||
const r = await restart(t, f, creativeOps(f.business));
|
||||
const cap = r.broker.bindLaunch({ business: 'demo', role: 'ops', run: 'ops-run', harness: 'pi', address: 'ops' });
|
||||
r.broker.request(cap, { verb: 'role.claim' });
|
||||
const executor = hostExecutor({ credentials: r.credentials, root: join(f.dir, 'host-run') });
|
||||
const before = f.requests().length;
|
||||
await refusesWith(r.broker.requestHost(cap, { verb: 'host.run', args: { host: 'web1', argv: ['systemctl', 'status'] } }, executor), 'host-creative-role');
|
||||
assert.equal(f.requests().length, before);
|
||||
assert.equal(readOr(join(f.dir, 'sudo.log'), '').includes('systemctl'), false);
|
||||
assert.notEqual(f.record(), undefined);
|
||||
});
|
||||
@@ -1,228 +0,0 @@
|
||||
// Row 235 (#1741, #436 row b): the host grant raise (r6 R1-R4). A credential.mint raise whose `grant`
|
||||
// has method `host` binds an agent, an enrolled host, argv prefixes and a rotate date. The host record
|
||||
// comes from the fixture, and nothing here connects to any host.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { Broker, registrySha256 } from '../src/broker.mjs';
|
||||
import { Store } from '../src/store.mjs';
|
||||
import { hostGrant, definitionSha256 } from '../src/host-grant.mjs';
|
||||
import { hostRecord, hostGrantRecord } from './host-fixtures.mjs';
|
||||
import { canonicalJson } from '../../business/src/util.mjs';
|
||||
|
||||
const options = [{ key: 'yes', text: 'Yes' }, { key: 'no', text: 'No' }];
|
||||
const refusesWith = async (p, code) => assert.rejects(Promise.resolve().then(() => p), (e) => (assert.equal(e.code, code), true));
|
||||
const dayFrom = (n) => new Date(Date.now() + n * 86400000).toISOString().slice(0, 10);
|
||||
const ENTRY = { address: '192.0.2.10', port: 22, user: 'jarvis', hostKeys: ['ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHostKeyForTests'] };
|
||||
const none = { authority: { withinRole: ['message.send'], crossRole: [] } };
|
||||
const DEFINITIONS = {
|
||||
'chief-of-staff': { roleVersion: 2, credentials: [] },
|
||||
pm: { roleVersion: 2, credentials: [] },
|
||||
ops: { roleVersion: 2, credentials: [{ service: 'gitea', scopes: ['read:repository'] }, { service: 'host' }] },
|
||||
};
|
||||
|
||||
function setup(t) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'g235-'));
|
||||
const store = new Store(root);
|
||||
t.after(() => {
|
||||
store.close();
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
});
|
||||
const configDir = join(root, 'config');
|
||||
const business = {
|
||||
id: 'demo',
|
||||
human: 'jason',
|
||||
arbiters: { technical: 'pm', delivery: 'pm' },
|
||||
roles: {
|
||||
chief: { definition: 'chief-of-staff', ...none },
|
||||
pm: { definition: 'pm', ...none },
|
||||
ops: { definition: 'ops', ...none },
|
||||
odd: { definition: 'constructor', ...none },
|
||||
// A creative role whose definition declares host, so only the creative check refuses it.
|
||||
muse: { definition: 'research', ...none },
|
||||
},
|
||||
definitions: { ...structuredClone(DEFINITIONS), research: structuredClone(DEFINITIONS.ops) },
|
||||
vars: { 'bus.tester': true },
|
||||
};
|
||||
const broker = new Broker({ store, businesses: { demo: business }, hostGrant: hostGrant({ configDir, runRoot: join(configDir, 'secrets', 'run') }) });
|
||||
const caps = {};
|
||||
for (const role of ['chief', 'pm']) {
|
||||
caps[role] = broker.bindLaunch({ business: 'demo', role, run: role + '-run', harness: 'pi', address: role });
|
||||
broker.request(caps[role], { verb: 'role.claim' });
|
||||
}
|
||||
caps.human = broker.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
||||
caps.tester = broker.bindTester({ business: 'demo' });
|
||||
hostRecord(store, { host: 'web1', entry: ENTRY });
|
||||
const grant = (over = {}) => ({ method: 'host', agent: 'ops', host: 'web1', commands: [['systemctl', 'status']], rotateBy: dayFrom(30), ...over });
|
||||
const call = (who, verb, args = {}) => broker.request(caps[who], { verb, args });
|
||||
const raise = (over = {}, who = 'chief', extra = {}) =>
|
||||
call(who, 'decision.raise', { action: 'credential.mint', question: 'Grant ops web1?', options, recommendation: 'yes', blocking: false, grant: grant(over), ...extra });
|
||||
const decisions = () => store.get('SELECT count(*) AS n FROM decisions').n;
|
||||
const question = (id) => store.get('SELECT question FROM decisions WHERE id=?', id).question;
|
||||
const raiseBody = (id) =>
|
||||
JSON.parse(store.get("SELECT body FROM events WHERE kind='action.allowed' AND json_extract(body,'$.operation')='decision.raise' AND json_extract(body,'$.decision')=?", id).body);
|
||||
const refusals = () => store.all("SELECT body FROM events WHERE business='demo' AND kind='action.refused' ORDER BY seq").map((e) => JSON.parse(e.body).code);
|
||||
return { store, broker, caps, call, raise, grant, decisions, question, raiseBody, refusals };
|
||||
}
|
||||
|
||||
test('G1 (host): only the chief raises a host grant, a grant on any other action refuses, and nothing is stored', async (t) => {
|
||||
const f = setup(t);
|
||||
const before = f.decisions();
|
||||
await refusesWith(f.raise({}, 'pm'), 'grant-chief-only');
|
||||
await refusesWith(f.raise({}, 'chief', { action: 'deploy' }), 'invalid-request');
|
||||
await refusesWith(f.raise({}, 'tester'), 'tester-refused');
|
||||
assert.equal(f.decisions(), before);
|
||||
assert.deepEqual(f.refusals(), ['grant-chief-only', 'invalid-request', 'tester-refused']);
|
||||
});
|
||||
|
||||
test('G1, R4: the grant takes exactly method, agent, host, commands and rotateBy, and an unknown method refuses', async (t) => {
|
||||
const f = setup(t);
|
||||
const before = f.decisions();
|
||||
const g = f.grant();
|
||||
const { rotateBy, ...noRotate } = g;
|
||||
for (const bad of [
|
||||
noRotate,
|
||||
{ ...g, extra: 1 },
|
||||
{ ...g, method: 'gitea' },
|
||||
{ ...g, method: 'Host' },
|
||||
{ ...g, agent: 'Ops' },
|
||||
{ ...g, agent: '' },
|
||||
{ ...g, agent: 7 },
|
||||
{ ...g, host: 'Web_1' },
|
||||
{ ...g, host: 'a'.repeat(33) },
|
||||
])
|
||||
await refusesWith(f.call('chief', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false, grant: bad }), 'invalid-request');
|
||||
for (const bad of [null, [], 'host'])
|
||||
await refusesWith(f.call('chief', 'decision.raise', { action: 'credential.mint', question: 'q', options, recommendation: 'yes', blocking: false, grant: bad }), 'invalid-request');
|
||||
assert.equal(f.decisions(), before);
|
||||
assert.ok(rotateBy);
|
||||
});
|
||||
|
||||
test('G2: an agent whose definition lacks host refuses host-not-declared, and an unknown agent unknown-role', async (t) => {
|
||||
const f = setup(t);
|
||||
const before = f.decisions();
|
||||
await refusesWith(f.raise({ agent: 'pm' }), 'host-not-declared');
|
||||
await refusesWith(f.raise({ agent: 'chief' }), 'host-not-declared');
|
||||
await refusesWith(f.raise({ agent: 'nobody' }), 'unknown-role');
|
||||
// An inherited name is not a definition.
|
||||
await refusesWith(f.raise({ agent: 'odd' }), 'host-not-declared');
|
||||
assert.equal(f.decisions(), before);
|
||||
});
|
||||
|
||||
test('mos-1163: a grant whose agent is a creative role refuses host-creative-role, even when its definition declares host', async (t) => {
|
||||
const f = setup(t);
|
||||
const before = f.decisions();
|
||||
await refusesWith(f.raise({ agent: 'muse' }), 'host-creative-role');
|
||||
assert.equal(f.decisions(), before);
|
||||
});
|
||||
|
||||
test('G3: wildcard, shell, empty and other 210 D6 argv prefixes refuse invalid-request', async (t) => {
|
||||
const f = setup(t);
|
||||
const before = f.decisions();
|
||||
for (const commands of [
|
||||
'any',
|
||||
'*',
|
||||
{},
|
||||
[],
|
||||
[[]],
|
||||
[['*']],
|
||||
[['systemctl', 'status*']],
|
||||
[['ls', '[a]']],
|
||||
[['bash']],
|
||||
[['/bin/sh', '-c']],
|
||||
[['sudo', 'ls']],
|
||||
[['python3']],
|
||||
[['env', 'ls']],
|
||||
[['bin/ls']],
|
||||
[['']],
|
||||
[['ls', 'a\0b']],
|
||||
[['ls', 3]],
|
||||
[['ls'], ['ls']],
|
||||
[Array.from({ length: 257 }, () => 'x')],
|
||||
])
|
||||
await refusesWith(f.raise({ commands }), 'invalid-request');
|
||||
assert.equal(f.decisions(), before);
|
||||
});
|
||||
|
||||
test('R4 rotateBy (sage-1782): a real calendar day after today UTC, or invalid-request', async (t) => {
|
||||
const f = setup(t);
|
||||
const before = f.decisions();
|
||||
for (const rotateBy of [dayFrom(0), dayFrom(-1), '2026-02-30', '2026-13-01', '20991231', '2099-1-01', 20991231, null])
|
||||
await refusesWith(f.raise({ rotateBy }), 'invalid-request');
|
||||
assert.equal(f.decisions(), before);
|
||||
await f.raise({ rotateBy: dayFrom(1) });
|
||||
await f.raise({ rotateBy: '2999-12-31' });
|
||||
assert.equal(f.decisions(), before + 2);
|
||||
});
|
||||
|
||||
test('G19: a grant naming a host that is pending-install refuses host-not-ready, and an unknown host host-unknown', async (t) => {
|
||||
const f = setup(t);
|
||||
hostRecord(f.store, { host: 'web2', entry: ENTRY });
|
||||
f.store.run("UPDATE hosts SET state='pending-install' WHERE business='demo' AND host='web2'");
|
||||
const before = f.decisions();
|
||||
await refusesWith(f.raise({ host: 'web2' }), 'host-not-ready');
|
||||
await refusesWith(f.raise({ host: 'web9' }), 'host-unknown');
|
||||
assert.equal(f.decisions(), before);
|
||||
});
|
||||
|
||||
test('R4, G5: the raise routes to the human and its event body binds the eight fields with their hashes', async (t) => {
|
||||
const f = setup(t);
|
||||
const commands = [['systemctl', 'status'], ['/usr/bin/journalctl', '-u', 'nginx']];
|
||||
const d = await f.raise({ commands });
|
||||
const row = f.store.get('SELECT action, class, route_to FROM decisions WHERE id=?', d.id);
|
||||
assert.deepEqual({ ...row }, { action: 'credential.mint', class: 'gated', route_to: 'human' });
|
||||
const body = f.raiseBody(d.id);
|
||||
assert.deepEqual(Object.keys(body.grant), ['method', 'agent', 'host', 'commands', 'commandsSha256', 'rotateBy', 'registrySha256', 'definitionSha256']);
|
||||
assert.deepEqual(body.grant, {
|
||||
method: 'host',
|
||||
agent: 'ops',
|
||||
host: 'web1',
|
||||
commands,
|
||||
commandsSha256: createHash('sha256').update(JSON.stringify(commands)).digest('hex'),
|
||||
rotateBy: f.grant().rotateBy,
|
||||
registrySha256: registrySha256({ ...ENTRY, sudo: true }),
|
||||
definitionSha256: createHash('sha256').update(canonicalJson(DEFINITIONS.ops)).digest('hex'),
|
||||
});
|
||||
// Key order in the definition doesn't change the hash, and a field change does.
|
||||
const reordered = { credentials: DEFINITIONS.ops.credentials, roleVersion: 2 };
|
||||
assert.equal(definitionSha256(reordered), body.grant.definitionSha256);
|
||||
assert.notEqual(definitionSha256({ ...DEFINITIONS.ops, credentials: [{ service: 'host' }] }), body.grant.definitionSha256);
|
||||
assert.deepEqual(f.call('human', 'inbox').map((x) => x.id), [d.id]);
|
||||
});
|
||||
|
||||
test('G4 (host block): the broker appends the host, each prefix, the rotate date and new key or change', async (t) => {
|
||||
const f = setup(t);
|
||||
const d = await f.raise({ commands: [['systemctl', 'status'], ['echo', 'a b"c']] });
|
||||
const rotateBy = f.grant().rotateBy;
|
||||
assert.equal(
|
||||
f.question(d.id),
|
||||
'Grant ops web1?' +
|
||||
'\n\nGrant ops access to host web1: user jarvis at 192.0.2.10 port 22.' +
|
||||
'\njarvis has sudo on this host.' +
|
||||
'\nCommands, each an argv prefix:' +
|
||||
'\n"systemctl" "status"' +
|
||||
'\n"echo" "a b\\"c"' +
|
||||
`\nRotate by ${rotateBy}.` +
|
||||
'\nThis makes a new key for ops on web1.',
|
||||
);
|
||||
// A host without sudo, and an agent with a grant record already: the block says so.
|
||||
hostRecord(f.store, { host: 'web2', entry: ENTRY, sudo: false });
|
||||
hostGrantRecord(f.store, { agent: 'ops', host: 'web2', commands: [['uptime']] });
|
||||
const d2 = await f.raise({ host: 'web2' });
|
||||
const q2 = f.question(d2.id);
|
||||
assert.ok(q2.includes('\njarvis has no sudo on this host.\n'));
|
||||
assert.ok(q2.endsWith("\nThis changes the commands of ops's grant on web2. The key stays."));
|
||||
// A forged block in the chief's question still gets the broker's block after it.
|
||||
const forged = 'x\n\nGrant ops access to host web1: user other at 192.0.2.99 port 22.\nCommands, each an argv prefix:\n"bash"';
|
||||
const d3 = await f.raise({}, 'chief', { question: forged });
|
||||
assert.ok(f.question(d3.id).startsWith(forged + '\n\nGrant ops access to host web1: user jarvis at 192.0.2.10 port 22.\n'));
|
||||
// The 4096 cap counts the block: a question that fits alone refuses with it.
|
||||
const before = f.decisions();
|
||||
await refusesWith(f.raise({}, 'chief', { question: 'q'.repeat(4000) }), 'invalid-request');
|
||||
const long = Array.from({ length: 64 }, (_, i) => ['/usr/bin/tool' + i, 'x'.repeat(60)]);
|
||||
await refusesWith(f.raise({ commands: long }), 'invalid-request');
|
||||
assert.equal(f.decisions(), before);
|
||||
});
|
||||
@@ -1,212 +0,0 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { createHash } from 'node:crypto';
|
||||
import { DatabaseSync } from 'node:sqlite';
|
||||
import { Store, schemaDigest } from '../src/store.mjs';
|
||||
import { Broker } from '../src/broker.mjs';
|
||||
// Row 234 (#1740, #436a row a): the 3i→3j step adds the hosts and host_grants tables and the grant
|
||||
// event guard (#436b section 7 at fa5658941). It runs on a 3i store built here from the pinned 3i
|
||||
// schema (8fede5fc6's schema.sql) and fixture rows. No live store is read or copied.
|
||||
const AT = '2026-10-21T00:00:00.000Z';
|
||||
const TAG = 'mosaic-' + 'a'.repeat(32);
|
||||
const ddl3i = readFileSync(new URL('./fixtures/schema-3i.sql', import.meta.url), 'utf8');
|
||||
const here = (p) => new URL(p, import.meta.url);
|
||||
const NEW = ['hosts', 'host_grants', 'events_grant_actor', 'sqlite_autoindex_hosts_1', 'sqlite_autoindex_host_grants_1'];
|
||||
function source3i(t) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'grant-migrate-'));
|
||||
t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||
mkdirSync(join(root, 'bus'), { mode: 0o700 });
|
||||
const path = join(root, 'bus/bus.sqlite'), db = new DatabaseSync(path);
|
||||
assert.equal(createHash('sha256').update(ddl3i).digest('hex'), '6cde5232c57ac04dc6073112c0830c89cfc5e953d7a5727e7716263747fe8737');
|
||||
db.exec(ddl3i);
|
||||
const run = (sql, ...args) => db.prepare(sql).run(...args);
|
||||
run('INSERT INTO meta VALUES (?,?)', 'schema_version', '3i');
|
||||
run('INSERT INTO meta VALUES (?,?)', 'schema_digest', schemaDigest(db));
|
||||
run('INSERT INTO meta VALUES (?,?)', 'comment_cursor_epoch', AT);
|
||||
run('INSERT INTO events(id,at,business,kind,actor_role,actor_run,body) VALUES(?,?,?,?,?,?,?)', 'e1', AT, 'demo', 'action.allowed', 'coder', 'run1', '{"action":"host.sudo"}');
|
||||
run('INSERT INTO events(id,at,business,kind,body) VALUES(?,?,?,?,?)', 'e2', AT, 'demo', 'action.allowed', '{}');
|
||||
db.close(); chmodSync(path, 0o600);
|
||||
return { root, path };
|
||||
}
|
||||
function rows(path) {
|
||||
const db = new DatabaseSync(path, { readOnly: true });
|
||||
try {
|
||||
return Object.fromEntries(db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT IN ('hosts','host_grants')").all()
|
||||
.map(({ name }) => [name, db.prepare(`SELECT * FROM ${name} ORDER BY rowid`).all()
|
||||
.filter(r => name !== 'meta' || !['schema_version', 'schema_digest'].includes(r.key)).map(r => ({ ...r }))]));
|
||||
} finally { db.close(); }
|
||||
}
|
||||
function master(path) {
|
||||
const db = new DatabaseSync(path, { readOnly: true });
|
||||
try {
|
||||
return db.prepare('SELECT type,name,tbl_name,sql FROM sqlite_master ORDER BY type,name').all().map(r => ({ ...r }));
|
||||
} finally { db.close(); }
|
||||
}
|
||||
const version = (path) => {
|
||||
const db = new DatabaseSync(path, { readOnly: true });
|
||||
try { return db.prepare("SELECT value FROM meta WHERE key='schema_version'").get().value; } finally { db.close(); }
|
||||
};
|
||||
// A copy of the bus module whose store.mjs, schema.sql and 3i→3j step the caller edits.
|
||||
async function engine(root, name, { store, schema, step = (s) => s }) {
|
||||
const moduleRoot = join(root, name);
|
||||
mkdirSync(join(moduleRoot, 'src/migrations'), { recursive: true });
|
||||
const source = readFileSync(here('../src/store.mjs'), 'utf8'), edited = store ? store(source) : source;
|
||||
if (store) assert.notEqual(edited, source);
|
||||
writeFileSync(join(moduleRoot, 'src/store.mjs'), edited);
|
||||
writeFileSync(join(moduleRoot, 'schema.sql'), schema ?? readFileSync(here('../schema.sql'), 'utf8'));
|
||||
for (const file of ['3b.sql', '3b-3c.sql', '3c-3d.sql', '3d-3e.sql', '3e-3f.sql', '3f-3g.sql', '3g-3h.sql', '3h-3i.sql'])
|
||||
copyFileSync(here('../src/migrations/' + file), join(moduleRoot, 'src/migrations', file));
|
||||
writeFileSync(join(moduleRoot, 'src/migrations/3i-3j.sql'), step(readFileSync(here('../src/migrations/3i-3j.sql'), 'utf8')));
|
||||
return (await import(pathToFileURL(join(moduleRoot, 'src/store.mjs')))).Store;
|
||||
}
|
||||
function fresh(t) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'grant-store-'));
|
||||
const store = new Store(root);
|
||||
t.after(() => { store.close(); rmSync(root, { recursive: true, force: true }); });
|
||||
store.run(`INSERT INTO decisions(id,at,business,raised_by_role,raised_by_run,class,action,route_to,question,options,recommendation,blocking)
|
||||
VALUES('d1',?,'demo','chief','run1','gated','credential.mint','human','q','["yes","no"]','yes',0)`, AT);
|
||||
return store;
|
||||
}
|
||||
const event = (store, actor, body, kind = 'action.allowed') => store.run(
|
||||
'INSERT INTO events(id,at,business,kind,actor_role,actor_run,body) VALUES(?,?,?,?,?,?,?)',
|
||||
'e' + Math.random().toString(16).slice(2), AT, 'demo', kind, actor[0], actor[1], JSON.stringify(body));
|
||||
const host = (store, values = {}) => store.run(
|
||||
`INSERT INTO hosts(business,host,address,port,user,sudo,host_keys,installer_fingerprint,state,decision,checked_at)
|
||||
VALUES(:business,:host,:address,:port,:user,:sudo,:host_keys,:fp,:state,:decision,:checked)`,
|
||||
{ business: 'demo', host: 'web1', address: '192.0.2.10', port: 22, user: 'deploy', sudo: 0,
|
||||
host_keys: '["ssh-ed25519 AAAA"]', fp: null, state: 'pending-install', decision: 'd1', checked: null, ...values });
|
||||
|
||||
test('3i copy migrates to 3j: every row kept, and sqlite_master gains only the two tables, their keys and the guard', t => {
|
||||
const { root, path } = source3i(t), before = rows(path), was = master(path);
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
new Store(root, { migrateSchema: true }).close();
|
||||
assert.equal(version(path), '3j');
|
||||
assert.deepEqual(rows(path), before);
|
||||
const now = master(path);
|
||||
assert.deepEqual(now.filter(r => !NEW.includes(r.name)), was);
|
||||
assert.deepEqual(now.filter(r => NEW.includes(r.name)).map(r => r.name).sort(), [...NEW].sort());
|
||||
const store = new Store(root);
|
||||
try {
|
||||
assert.equal(store.get('PRAGMA quick_check').quick_check, 'ok');
|
||||
assert.deepEqual(store.all('PRAGMA foreign_key_check'), []);
|
||||
assert.equal(store.get('SELECT count(*) AS n FROM hosts').n, 0);
|
||||
// An event row 210 wrote before the step stays, and a session can still write host.sudo.
|
||||
event(store, ['coder', 'run2'], { action: 'host.sudo', phase: 'requested' });
|
||||
} finally { store.close(); }
|
||||
});
|
||||
|
||||
test('a 3i→3j step that fails partway leaves the store at 3i with every row and the schema intact', async t => {
|
||||
const { root, path } = source3i(t), before = rows(path), was = master(path);
|
||||
// The real step plus a statement that fails only when events has a row, so the empty replay at
|
||||
// import passes and the store's run fails after both tables and the trigger exist.
|
||||
const Failing = await engine(root, 'engine-failing', { step: (sql) => sql + 'INSERT INTO events SELECT * FROM events LIMIT 1;\n' });
|
||||
assert.throws(() => new Failing(root, { migrateSchema: true }), /events is append-only/);
|
||||
assert.equal(version(path), '3i');
|
||||
assert.deepEqual(master(path), was);
|
||||
assert.deepEqual(rows(path), before);
|
||||
new Store(root, { migrateSchema: true }).close();
|
||||
assert.equal(version(path), '3j');
|
||||
});
|
||||
|
||||
test('the 3i engine refuses a 3j store, migrating or not, and leaves it at 3j', async t => {
|
||||
const { root, path } = source3i(t);
|
||||
new Store(root, { migrateSchema: true }).close();
|
||||
const after = rows(path), was = master(path);
|
||||
const Store3i = await engine(root, 'engine-3i', {
|
||||
schema: ddl3i,
|
||||
store: (source) => source
|
||||
.replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${createHash('sha256').update(ddl3i).digest('hex')}';`)
|
||||
.replace("export const SCHEMA_VERSION = '3j';", "export const SCHEMA_VERSION = '3i';")
|
||||
.replace(/\}, \{\n {2}\/\/ Row 234 \(#1740\)[\s\S]*?\}\];\nconst timedTables/, '}];\nconst timedTables'),
|
||||
});
|
||||
const pinned = readFileSync(join(root, 'engine-3i/src/store.mjs'), 'utf8');
|
||||
assert.ok(pinned.includes("export const SCHEMA_VERSION = '3i';") && !pinned.includes('3i-3j'), 'the 3i engine has no 3i→3j step');
|
||||
assert.throws(() => new Store3i(root), /schema-mismatch/);
|
||||
assert.throws(() => new Store3i(root, { migrateSchema: true }), /schema-mismatch/);
|
||||
assert.equal(version(path), '3j');
|
||||
assert.deepEqual(master(path), was);
|
||||
assert.deepEqual(rows(path), after);
|
||||
});
|
||||
|
||||
test('A22b, sage-1703: a session-written grant.* row from before the step survives it, and the grant readers ignore it', async t => {
|
||||
// The step adds the guard but leaves old rows. At 3i recordEvent had no reserved-event refusal, so a
|
||||
// session could write these, and after the step only GRANT_EVIDENCE's actor filter keeps them out.
|
||||
const { root, path } = source3i(t);
|
||||
const db = new DatabaseSync(path);
|
||||
const run = (sql, ...args) => db.prepare(sql).run(...args);
|
||||
run(`INSERT INTO decisions(id,at,business,raised_by_role,raised_by_run,class,action,route_to,question,options,recommendation,blocking)
|
||||
VALUES('d1',?,'demo','chief','run1','gated','credential.mint','human','q','["yes","no"]','yes',0)`, AT);
|
||||
const legacy = [{ action: 'grant.host.removed', host: 'web1', hostLineLeft: TAG }, { operation: 'grant.host-enroll', decision: 'd1' }];
|
||||
for (const [i, body] of legacy.entries())
|
||||
run('INSERT INTO events(id,at,business,kind,actor_role,actor_run,body) VALUES(?,?,?,?,?,?,?)', 'old' + i, AT, 'demo', 'action.allowed', 'chief', 'run1', JSON.stringify(body));
|
||||
db.close();
|
||||
new Store(root, { migrateSchema: true }).close();
|
||||
const store = new Store(root);
|
||||
t.after(() => store.close());
|
||||
assert.equal(store.get("SELECT count(*) AS n FROM events WHERE id IN ('old0','old1')").n, 2);
|
||||
host(store);
|
||||
const business = {
|
||||
id: 'demo',
|
||||
human: 'jason',
|
||||
arbiters: { technical: 'pm', delivery: 'pm' },
|
||||
roles: {
|
||||
chief: { definition: 'chief-of-staff', authority: { withinRole: ['message.send'], crossRole: [] } },
|
||||
pm: { definition: 'pm', authority: { withinRole: ['message.send'], crossRole: [] } },
|
||||
},
|
||||
vars: {},
|
||||
};
|
||||
const unenrolled = [];
|
||||
const broker = new Broker({ store, businesses: { demo: business }, hostGrant: { unenroll: (b, h) => unenrolled.push([b, h]), installerTag: () => null } });
|
||||
// The enrollment look-alike is not a spent decision, so nothing ends interrupted.
|
||||
assert.deepEqual(broker.reconcileGrants(), []);
|
||||
assert.equal(store.get("SELECT count(*) AS n FROM events WHERE actor_run='grant'").n, 0);
|
||||
// The hostLineLeft look-alike is not a line left on the host.
|
||||
const human = broker.bindHuman({ business: 'demo', human: 'jason', via: 'cli', outsideAgent: true });
|
||||
assert.deepEqual(await broker.request(human, { verb: 'hosts.remove', args: { host: 'web1' } }), { host: 'web1', removed: true });
|
||||
assert.deepEqual(unenrolled, [['demo', 'web1']]);
|
||||
});
|
||||
|
||||
test('the guard: a grant.* action or operation on action.allowed needs the (NULL, grant) actor', t => {
|
||||
const store = fresh(t);
|
||||
const refused = /only the grant writer records grant events/;
|
||||
for (const body of [{ action: 'grant.step' }, { action: 'grant.host.enrolled' }, { operation: 'grant.host-enroll', decision: 'd1' }]) {
|
||||
assert.throws(() => event(store, ['chief', 'run1'], body), refused, JSON.stringify(body));
|
||||
assert.throws(() => event(store, ['tester', 'run1'], body), refused);
|
||||
assert.throws(() => event(store, [null, null], body), refused, 'the human and session-less pair is not the grant actor');
|
||||
assert.throws(() => event(store, [null, 'run1'], body), refused);
|
||||
assert.throws(() => event(store, ['grant', 'grant'], body), refused);
|
||||
event(store, [null, 'grant'], body);
|
||||
}
|
||||
// Row 210's host.sudo and host.run stay outside the namespace, and so does any other kind.
|
||||
event(store, ['coder', 'run1'], { action: 'host.sudo', phase: 'completed' });
|
||||
event(store, ['coder', 'run1'], { action: 'grant.step' }, 'action.refused');
|
||||
event(store, ['coder', 'run1'], { action: 'granted.step', operation: 'grantx' });
|
||||
assert.equal(store.get("SELECT count(*) AS n FROM events WHERE actor_run='grant'").n, 3);
|
||||
});
|
||||
|
||||
test('hosts: one record per business and host, a ready host has its installer and check, grants need the host', t => {
|
||||
const store = fresh(t);
|
||||
host(store);
|
||||
assert.throws(() => host(store, { address: '192.0.2.11' }), /UNIQUE constraint failed: hosts\.business, hosts\.host/);
|
||||
host(store, { business: 'other' });
|
||||
assert.throws(() => host(store, { host: 'web2', state: 'ready' }), /CHECK constraint failed/);
|
||||
assert.throws(() => host(store, { host: 'web2', state: 'ready', fp: 'SHA256:x' }), /CHECK constraint failed/);
|
||||
host(store, { host: 'web2', state: 'ready', fp: 'SHA256:x', checked: AT });
|
||||
assert.throws(() => host(store, { host: 'web3', state: 'live' }), /CHECK constraint failed/);
|
||||
assert.throws(() => host(store, { host: 'web3', host_keys: '[]' }), /CHECK constraint failed/);
|
||||
assert.throws(() => host(store, { host: 'web3', decision: 'nope' }), /FOREIGN KEY constraint failed/);
|
||||
const grant = (values = {}) => store.run(
|
||||
'INSERT INTO host_grants(business,agent,host,commands,rotate_by,tag,decision) VALUES(:business,:agent,:host,:commands,:rotate,:tag,:decision)',
|
||||
{ business: 'demo', agent: 'coder', host: 'web2', commands: '[["true"]]', rotate: '2026-12-01', tag: TAG, decision: 'd1', ...values });
|
||||
assert.throws(() => grant({ host: 'web9' }), /FOREIGN KEY constraint failed/);
|
||||
for (const tag of ['mosaic-' + 'A'.repeat(32), 'mosaic-' + 'a'.repeat(31), 'mosaix-' + 'a'.repeat(32), 'mosaic-' + 'a'.repeat(31) + 'g'])
|
||||
assert.throws(() => grant({ tag }), /CHECK constraint failed/, tag);
|
||||
assert.throws(() => grant({ commands: '[]' }), /CHECK constraint failed/);
|
||||
grant();
|
||||
assert.throws(() => grant({ tag: 'mosaic-' + 'b'.repeat(32) }), /UNIQUE constraint failed/);
|
||||
assert.throws(() => store.run("DELETE FROM hosts WHERE business='demo' AND host='web2'"), /FOREIGN KEY constraint failed/);
|
||||
});
|
||||
@@ -7,7 +7,6 @@ import { Store } from '../src/store.mjs';
|
||||
import { Broker, ACTIONS, HARD_WAITS } from '../src/broker.mjs';
|
||||
import { ACTIONS as VOCABULARY, GATED_ONLY } from '../../business/src/vocabulary.mjs';
|
||||
import { fixture } from './spec-fixtures.mjs';
|
||||
import { hostGrantRecord, hostRecord } from './host-fixtures.mjs';
|
||||
|
||||
// PRD 1.5 REQ-WAIT-1, REQ-WAIT-2 and REQ-DEC-2 (row 139, #1633).
|
||||
const WAITS = ['spend', 'data.delete', 'network.expose', 'account.create', 'credential.mint', 'message.external',
|
||||
@@ -38,11 +37,10 @@ test('REQ-WAIT-2: a business granting a hard wait at either class is refused; th
|
||||
|
||||
test('REQ-DEC-2: every hard wait goes to the human, cited or not, and the arbiter cannot resolve it', async t => {
|
||||
const f = await fixture(t, { roles: { coder: { definition: 'coder',
|
||||
authority: { withinRole: ['message.send', 'record.write', 'git.push.working'], crossRole: [] } } } });
|
||||
// Row 210: a host.sudo raise names a registered host the raiser is granted and an argv its grant allows.
|
||||
// Row 234 (#1740): both are store records.
|
||||
hostRecord(f.store, { host: 'web1', entry: { address: '10.0.0.5', port: 22, user: 'admin', hostKeys: ['ssh-ed25519 AAAA'] } });
|
||||
hostGrantRecord(f.store, { agent: 'coder', host: 'web1', commands: [['systemctl', 'status']] });
|
||||
authority: { withinRole: ['message.send', 'record.write', 'git.push.working'], crossRole: [] },
|
||||
hosts: { web1: { commands: [['systemctl', 'status']] } } } },
|
||||
// Row 210: a host.sudo raise names a registered host the raiser is granted and an argv its grant allows.
|
||||
hosts: { web1: { address: '10.0.0.5', port: 22, user: 'admin', hostKeys: ['ssh-ed25519 AAAA'] } } });
|
||||
// Row 199: a git.push.remote raise binds the task's latest push, so the task has one.
|
||||
f.broker.recordPush(f.coder, { task_ref: 'vikunja:1/2', project: 'stack', branch: 'feat', ref: 'work/vikunja-stack-2',
|
||||
commit: 'a'.repeat(40), previous: null });
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
// Row 234 (#1740, r6 X4): host and grant store records for tests. Row a has no way to make a host_grants
|
||||
// record outside a fixture, because row b's grant executor writes them. The decision, its raise event and
|
||||
// its close go in by SQL. The grant evidence goes through writeGrantEvent (F1), so the trigger sees the
|
||||
// real shape.
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { registrySha256, writeGrantEvent } from '../src/broker.mjs';
|
||||
import { grantTag } from '../src/host-grant.mjs';
|
||||
|
||||
const AT = '2026-10-21T00:00:00.000Z';
|
||||
const OPTIONS = JSON.stringify([{ key: 'yes', text: 'Yes' }, { key: 'no', text: 'No' }]);
|
||||
export const HUMAN_YES = { op: 'resolved', by: 'jason', choice: 'yes', via: 'cli' };
|
||||
|
||||
// A credential.mint decision with `grant` in its raise body. `close` is the decision_events row, or null
|
||||
// for an open decision.
|
||||
export function grantDecision(store, { business = 'demo', action = 'credential.mint', route = 'human', grant, close = HUMAN_YES }) {
|
||||
const id = randomUUID();
|
||||
store.run(
|
||||
'INSERT INTO decisions(id,at,business,raised_by_role,raised_by_run,class,action,route_to,question,options,recommendation,blocking) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)',
|
||||
id, AT, business, 'chief', 'chief-run', 'gated', action, route, 'Grant?', OPTIONS, 'yes', 0,
|
||||
);
|
||||
store.run(
|
||||
"INSERT INTO events(id,at,business,kind,actor_role,actor_run,subject,body) VALUES(?,?,?,'action.allowed',?,?,?,?)",
|
||||
randomUUID(), AT, business, 'chief', 'chief-run', id,
|
||||
JSON.stringify({ decision: id, action, operation: 'decision.raise', approvalChoice: 'yes', ...(grant ? { grant } : {}) }),
|
||||
);
|
||||
if (close)
|
||||
store.run('INSERT INTO decision_events(decision,at,op,by,choice,via) VALUES(?,?,?,?,?,?)', id, AT, close.op, close.by, close.choice ?? null, close.via ?? null);
|
||||
return id;
|
||||
}
|
||||
|
||||
// A ready host record from an approved, spent and finished enrollment. grant.host.enrolled keeps the
|
||||
// start reconcile from reading the enrollment as interrupted.
|
||||
export function hostRecord(store, { business = 'demo', host = 'web1', entry, sudo = true }) {
|
||||
const grant = { method: 'host-enroll', host, address: entry.address, port: entry.port, user: entry.user, sudo, fingerprints: [] };
|
||||
const decision = grantDecision(store, { business, grant });
|
||||
writeGrantEvent(store, AT, business, { operation: 'grant.host-enroll', decision }, decision);
|
||||
const installerFingerprint = 'SHA256:' + 'A'.repeat(43);
|
||||
writeGrantEvent(store, AT, business, {
|
||||
action: 'grant.host.enrolled', grantDecision: decision, host, installerFingerprint, user: entry.user, sudo,
|
||||
registrySha256: registrySha256({ ...entry, sudo }),
|
||||
}, decision);
|
||||
store.run(
|
||||
'INSERT INTO hosts(business,host,address,port,user,sudo,host_keys,installer_fingerprint,state,decision,checked_at) VALUES(?,?,?,?,?,?,?,?,?,?,?)',
|
||||
business, host, entry.address, entry.port, entry.user, sudo ? 1 : 0, JSON.stringify(entry.hostKeys), installerFingerprint, 'ready', decision, AT,
|
||||
);
|
||||
return decision;
|
||||
}
|
||||
|
||||
// One agent's grant record on a host. By default its decision is a `host` grant for the same agent and
|
||||
// host, resolved yes by the human via cli and spent as grant.host. Each option breaks one part.
|
||||
export function hostGrantRecord(store, { business = 'demo', agent, host = 'web1', commands, rotateBy = '2099-01-01', grant = {}, close = HUMAN_YES, spend = 'grant.host', action }) {
|
||||
const decision = grantDecision(store, {
|
||||
business, close, action,
|
||||
grant: grant === null ? undefined : { method: 'host', agent, host, commands, rotateBy, ...grant },
|
||||
});
|
||||
if (spend) writeGrantEvent(store, AT, business, { operation: spend, decision }, decision);
|
||||
// Row 235: the executor commits each record with its grant.applied (r6 X2 step 5), so the start
|
||||
// reconcile reads a fixture record as a finished grant.
|
||||
if (spend === 'grant.host')
|
||||
writeGrantEvent(store, AT, business, { action: 'grant.applied', grantDecision: decision, agent, host, tag: grantTag(business, agent, host) }, host);
|
||||
store.run(
|
||||
'INSERT INTO host_grants(business,agent,host,commands,rotate_by,tag,decision) VALUES(?,?,?,?,?,?,?)',
|
||||
business, agent, host, JSON.stringify(commands), rotateBy, grantTag(business, agent, host), decision,
|
||||
);
|
||||
return decision;
|
||||
}
|
||||
@@ -12,10 +12,8 @@ import { fileURLToPath } from 'node:url';
|
||||
import { Credentials, parseHostKey } from '../src/credentials.mjs';
|
||||
import { addKey, hostExecutor, runHost, sshArgs, startTime, sweepRunDir, quote, remoteCommand } from '../src/host-run.mjs';
|
||||
import { fixture } from './spec-fixtures.mjs';
|
||||
import { HUMAN_YES, hostGrantRecord, hostRecord } from './host-fixtures.mjs';
|
||||
import { Broker, ORGANIZATION_KEYS } from '../src/broker.mjs';
|
||||
import { Store } from '../src/store.mjs';
|
||||
import { hostGrant } from '../src/host-grant.mjs';
|
||||
import { startBroker } from '../src/runtime.mjs';
|
||||
import { businessDoc, rolesCopy, systemFor, writeJson } from '../../business/tests/helpers.mjs';
|
||||
|
||||
@@ -110,12 +108,13 @@ async function hostFixture(t, { commands = GRANT, reviewerHosts, wrongHostKey =
|
||||
const executor = hostExecutor({ credentials, root });
|
||||
const entry = { address: '127.0.0.1', port, user: USER, hostKeys: [pubLine(join(dir, wrongHostKey ? 'otherhost' : 'hostkey'))] };
|
||||
const authority = { withinRole: ['message.send', 'record.write'], crossRole: [] };
|
||||
const f = await fixture(t, { roles: { coder: { definition: 'coder', authority } } });
|
||||
// Row 234 (#1740, r6 X4): host.run reads store records, so the hosts and grants are fixtures there.
|
||||
for (const host of ['web1', 'web2']) hostRecord(f.store, { host, entry });
|
||||
hostGrantRecord(f.store, { agent: 'coder', host: 'web1', commands });
|
||||
if (coderWeb2) hostGrantRecord(f.store, { agent: 'coder', host: 'web2', commands });
|
||||
for (const [host, g] of Object.entries(reviewerHosts ?? {})) hostGrantRecord(f.store, { agent: 'reviewer', host, commands: g.commands });
|
||||
const f = await fixture(t, {
|
||||
roles: {
|
||||
coder: { definition: 'coder', authority, hosts: { web1: { commands }, ...(coderWeb2 ? { web2: { commands } } : {}) } },
|
||||
reviewer: { definition: 'reviewer', authority: { withinRole: ['message.send'], crossRole: [] }, ...(reviewerHosts ? { hosts: reviewerHosts } : {}) },
|
||||
},
|
||||
hosts: { web1: entry, web2: { ...entry } },
|
||||
});
|
||||
const approve = async (argv, stdin, host = 'web1') => {
|
||||
const d = await f.raise({ action: 'host.sudo', target: host, argv, ...(stdin !== undefined ? { stdin } : {}) });
|
||||
f.call(f.human, 'decision.resolve', { id: d.id, choice: 'yes' });
|
||||
@@ -292,26 +291,6 @@ test('T14: a host key not in the registry refuses and nothing runs', async (t) =
|
||||
assert.deepEqual(f.argvSeen(), []);
|
||||
});
|
||||
|
||||
// Row 234 (#1740, r6 G18, duckworth-0081 B2): hosts.check's `list` goes through runHost with the record's
|
||||
// pinned keys. A stub `list` on the scratch sshd's PATH records each run.
|
||||
test('G18: hosts.check with a wrong pin refuses host-key-mismatch and runs nothing on the host', async (t) => {
|
||||
const f = await hostFixture(t);
|
||||
writeFileSync(join(f.dir, 'fake', 'list'), `#!/bin/sh\necho "$@" >> '${f.dir}/list.log'\n`, { mode: 0o755 });
|
||||
const configDir = join(f.dir, 'cfg');
|
||||
const keyDir = join(configDir, 'secrets', 'hosts', 'demo', 'web1');
|
||||
mkdirSync(keyDir, { recursive: true, mode: 0o700 });
|
||||
for (const d of [join(configDir, 'secrets'), join(configDir, 'secrets', 'hosts'), join(configDir, 'secrets', 'hosts', 'demo'), keyDir]) chmodSync(d, 0o700);
|
||||
writeFileSync(join(keyDir, 'installer'), readFileSync(f.keyFile), { mode: 0o600 });
|
||||
const hg = hostGrant({ configDir, runRoot: f.root });
|
||||
const record = { address: '127.0.0.1', port: f.port, user: 'jarvis', hostKeys: [pubLine(join(f.dir, 'otherhost'))] };
|
||||
await refusesWith(hg.check('demo', 'web1', record), 'host-key-mismatch');
|
||||
assert.equal(existsSync(join(f.dir, 'list.log')), false);
|
||||
// Control: with the right pin the same command reaches the stub.
|
||||
const out = await runHost({ root: f.root, hostId: 'web1', entry: f.entry, key: f.key, timeout: 10, command: 'list jarvis' });
|
||||
assert.equal(out.exit, 0);
|
||||
assert.equal(readFileSync(join(f.dir, 'list.log'), 'utf8'), 'jarvis\n');
|
||||
});
|
||||
|
||||
test('N3: a remote exit 255 that prints the pin refusal text is the command result, and an ssh failure keeps its message', async (t) => {
|
||||
const f = await hostFixture(t, { commands: [['fail255']] });
|
||||
const out = await f.call(['fail255']);
|
||||
@@ -553,90 +532,3 @@ test('T27: the bus start sweeps <configDir>/secrets/run before it listens, and a
|
||||
// A bus that starts anyway is closed, so a failure here ends the file instead of holding it open.
|
||||
await assert.rejects(async () => { const again = await start(); await again.close(); }, /credential-file/);
|
||||
});
|
||||
|
||||
// Row 234 (#1740, duckworth-0079 M3, r6 X4 first bullet): host.run takes a grant record only behind the
|
||||
// Approve record check. Each case breaks one part of it. The refusals come before the executor, so none
|
||||
// needs sshd. The control passes the check and stops at host-not-configured.
|
||||
test('M3: host.run refuses host-not-granted unless the grant record has an approved, spent host grant', async (t) => {
|
||||
const f = await fixture(t, { roles: { coder: { definition: 'coder', authority: { withinRole: ['message.send'], crossRole: [] } } } });
|
||||
const entry = { address: '10.0.0.5', port: 22, user: 'admin', hostKeys: ['ssh-ed25519 AAAA'] };
|
||||
for (const host of ['web1', 'web2']) hostRecord(f.store, { host, entry });
|
||||
const run = (cap = f.coder, host = 'web1') => f.broker.requestHost(cap, { verb: 'host.run', args: { host, argv: ['true'] } }, null);
|
||||
const commands = [['true']];
|
||||
const cases = {
|
||||
'no record': null,
|
||||
unresolved: { close: null },
|
||||
'resolved no': { close: { ...HUMAN_YES, choice: 'no' } },
|
||||
withdrawn: { close: { op: 'withdrawn', by: 'jason', via: 'cli' } },
|
||||
'an arbiter': { close: { ...HUMAN_YES, by: 'reviewer', via: 'broker' } },
|
||||
'the tester': { close: { ...HUMAN_YES, by: 'tester' } },
|
||||
'an agent': { close: { ...HUMAN_YES, by: 'coder', via: 'broker' } },
|
||||
'not via cli': { close: { ...HUMAN_YES, via: 'web' } },
|
||||
'consumed as grant.host-enroll': { spend: 'grant.host-enroll' },
|
||||
unspent: { spend: null },
|
||||
'not a credential.mint': { action: 'deploy' },
|
||||
'no grant in the raise': { grant: null },
|
||||
'a host-enroll grant': { grant: { method: 'host-enroll' } },
|
||||
'a grant for another agent': { grant: { agent: 'reviewer' } },
|
||||
'a grant for another host': { grant: { host: 'web2' } },
|
||||
};
|
||||
for (const [name, opts] of Object.entries(cases)) {
|
||||
f.store.run('DELETE FROM host_grants');
|
||||
if (opts) hostGrantRecord(f.store, { agent: 'coder', host: 'web1', commands, ...opts });
|
||||
await refusesWith(run(), 'host-not-granted').catch((e) => assert.fail(`${name}: ${e.message}`));
|
||||
}
|
||||
f.store.run('DELETE FROM host_grants');
|
||||
hostGrantRecord(f.store, { agent: 'coder', host: 'web1', commands });
|
||||
await refusesWith(run(), 'host-not-configured');
|
||||
// The record is per agent: the reviewer holds none on web1, and web9 has no host record.
|
||||
await refusesWith(run(f.reviewer), 'host-not-granted');
|
||||
await refusesWith(run(f.coder, 'web9'), 'host-unknown');
|
||||
// The host.sudo raise takes the same check (N1).
|
||||
f.store.run('DELETE FROM host_grants');
|
||||
hostGrantRecord(f.store, { agent: 'coder', host: 'web1', commands, spend: null });
|
||||
assert.throws(() => f.raise({ action: 'host.sudo', target: 'web1', argv: ['true'] }), /host-not-granted/);
|
||||
});
|
||||
|
||||
// Row 234 (#1740, M3, r6 X4 third bullet): at start each host_grants record gives Credentials a store
|
||||
// reference to host.<id>, so a restart finds the key the grant executor wrote.
|
||||
test('M3: a host_grants record gives Credentials a store reference at start, and a restart reads its key', async (t) => {
|
||||
const root = mkdtempSync(join(tmpdir(), 'h234-'));
|
||||
t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||
const rolesDir = rolesCopy(root);
|
||||
mkdirSync(join(root, 'data'), { mode: 0o700 });
|
||||
mkdirSync(join(root, 'secrets', 'agents'), { recursive: true, mode: 0o700 });
|
||||
chmodSync(join(root, 'secrets'), 0o700);
|
||||
const demo = {
|
||||
id: 'demo', human: 'jason', arbiters: { technical: 'coder', delivery: 'coder' },
|
||||
roles: { coder: { authority: { withinRole: ['message.send'], crossRole: [] }, credentials: {} } },
|
||||
};
|
||||
const start = () => startBroker({ dataRoot: join(root, 'data'), businesses: { demo }, organization: { dir: root, rolesDir, system: systemFor(root) } });
|
||||
const hostKeys = (bus) => bus.credentials.status().filter((c) => c.service.startsWith('host.'));
|
||||
let bus = await start();
|
||||
assert.deepEqual(hostKeys(bus), []);
|
||||
await bus.close();
|
||||
const store = new Store(join(root, 'data'));
|
||||
hostRecord(store, { host: 'web1', entry: { address: '10.0.0.5', port: 22, user: 'admin', hostKeys: ['ssh-ed25519 AAAA'] } });
|
||||
hostGrantRecord(store, { agent: 'coder', host: 'web1', commands: [['true']], rotateBy: '2099-02-03' });
|
||||
store.close();
|
||||
bus = await start();
|
||||
try {
|
||||
assert.deepEqual(hostKeys(bus).map(({ instance, service, date, state }) => ({ instance, service, date, state })), [
|
||||
{ instance: 'demo/coder', service: 'host.web1', date: '2099-02-03', state: 'not-issued' },
|
||||
]);
|
||||
} finally {
|
||||
await bus.close();
|
||||
}
|
||||
const dir = join(root, 'secrets', 'agents', 'demo', 'coder');
|
||||
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
||||
chmodSync(join(root, 'secrets', 'agents', 'demo'), 0o700);
|
||||
keygen(join(dir, 'host.web1'));
|
||||
bus = await start();
|
||||
try {
|
||||
const [key] = hostKeys(bus);
|
||||
assert.equal(key.publicKey, pubLine(join(dir, 'host.web1')));
|
||||
assert.notEqual(key.state, 'not-issued');
|
||||
} finally {
|
||||
await bus.close();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,358 +0,0 @@
|
||||
// Row 234 (#1740, #436a row a), design r6 E3: the four host files in tools/host, as G16 and G25.
|
||||
// The writer runs as the test user through a harness that loads it by path and passes its own dirs,
|
||||
// owner uid and user, group and sudo lookups, so nothing runs as root and nothing under /etc is read.
|
||||
// mosaic-keys runs from a copy whose sudo and logger paths point at stubs in a scratch dir.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync, spawnSync } from 'node:child_process';
|
||||
import { createHash, randomBytes } from 'node:crypto';
|
||||
import {
|
||||
chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync,
|
||||
writeFileSync,
|
||||
} from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const REPO = fileURLToPath(new URL('../../../', import.meta.url));
|
||||
const TOOLS = join(REPO, 'tools', 'host');
|
||||
const WRITER = join(TOOLS, 'mosaic-keys-write');
|
||||
const REFUSED_GROUPS = ['sudo', 'admin', 'wheel', 'docker', 'lxd', 'disk', 'libvirt', 'incus-admin'];
|
||||
const tag = (n) => 'mosaic-' + createHash('sha256').update(String(n)).digest('hex').slice(0, 32);
|
||||
const u32 = (n) => {
|
||||
const b = Buffer.alloc(4);
|
||||
b.writeUInt32BE(n);
|
||||
return b;
|
||||
};
|
||||
const keyBlob = () => Buffer.concat([u32(11), Buffer.from('ssh-ed25519'), u32(32), randomBytes(32)]).toString('base64');
|
||||
const fingerprint = (b64) => 'SHA256:' + createHash('sha256').update(Buffer.from(b64, 'base64')).digest('base64').replace(/=+$/, '');
|
||||
const notAllowed = (u) => `User ${u} is not allowed to run sudo on testhost.\n`;
|
||||
|
||||
const HARNESS = `import importlib.machinery, importlib.util, json, os, sys
|
||||
sys.dont_write_bytecode = True
|
||||
cfg = json.loads(sys.argv[1])
|
||||
loader = importlib.machinery.SourceFileLoader('mosaic_keys_write', cfg['writer'])
|
||||
m = importlib.util.module_from_spec(importlib.util.spec_from_loader('mosaic_keys_write', loader))
|
||||
loader.exec_module(m)
|
||||
users = cfg['users']
|
||||
def log(msg):
|
||||
with open(cfg['log'], 'a') as f:
|
||||
f.write(msg + '\\n')
|
||||
def sudo(u):
|
||||
with open(cfg['sudoLog'], 'a') as f:
|
||||
f.write(u + '\\n')
|
||||
return users[u]['sudo'] if 'sudo' in users[u] else 'User %s is not allowed to run sudo on testhost.\\n' % u
|
||||
host = m.Host(key_dir=cfg['keyDir'], conf_dir=cfg['confDir'], owner=os.getuid(),
|
||||
passwd=lambda u: users[u]['uid'] if u in users else None,
|
||||
groups=lambda u: users[u].get('groups', []), sudo=sudo, hostname='testhost', log=log)
|
||||
sys.exit(m.main(sys.argv[2:], host))
|
||||
`;
|
||||
|
||||
// The users the harness's lookups know. users lists all of them but dave and eve. bob and dave are
|
||||
// privileged. carol has a sudo line. Each gX is in one refused group.
|
||||
function userTable() {
|
||||
const users = {
|
||||
alice: { uid: 1500 },
|
||||
bob: { uid: 1501, groups: ['sudo', 'docker'], sudo: 'User bob may run the following commands on testhost:\n (ALL) ALL\n' },
|
||||
carol: { uid: 1502, sudo: 'User carol may run the following commands on testhost:\n (root) /usr/bin/true\n' },
|
||||
dave: { uid: 1503 },
|
||||
eve: { uid: 1504 },
|
||||
frank: { uid: 1505, groups: ['users', 'adm'] },
|
||||
'../x': { uid: 1506 },
|
||||
root: { uid: 0 },
|
||||
toor: { uid: 0 },
|
||||
daemon2: { uid: 999 },
|
||||
localadmin: { uid: 1000 },
|
||||
'mosaic-installer': { uid: 1001 },
|
||||
};
|
||||
for (const [i, g] of REFUSED_GROUPS.entries()) users['g' + g] = { uid: 1600 + i, groups: ['users', g] };
|
||||
return users;
|
||||
}
|
||||
|
||||
function hostDirs() {
|
||||
const root = mkdtempSync(join(tmpdir(), 'hk234-'));
|
||||
const keyDir = join(root, 'keys');
|
||||
const confDir = join(root, 'conf');
|
||||
mkdirSync(keyDir, { mode: 0o755 });
|
||||
mkdirSync(confDir, { mode: 0o755 });
|
||||
chmodSync(keyDir, 0o755);
|
||||
const users = userTable();
|
||||
const conf = (name, text) => {
|
||||
writeFileSync(join(confDir, name), text, { mode: 0o644 });
|
||||
chmodSync(join(confDir, name), 0o644);
|
||||
};
|
||||
conf('users', '# users the writer may touch\n' + Object.keys(users).filter((u) => !['dave', 'eve'].includes(u)).join('\n') + '\n');
|
||||
conf('privileged', 'bob\ndave\n');
|
||||
conf('from', '10.1.2.3/32\n');
|
||||
const harness = join(root, 'harness.py');
|
||||
writeFileSync(harness, HARNESS);
|
||||
const cfg = { writer: WRITER, keyDir, confDir, users, log: join(root, 'syslog'), sudoLog: join(root, 'sudo.log') };
|
||||
const run = (...args) => {
|
||||
const r = spawnSync('python3', ['-B', '-I', harness, JSON.stringify(cfg), ...args], { encoding: 'utf8' });
|
||||
return { status: r.status, stdout: r.stdout, stderr: r.stderr };
|
||||
};
|
||||
const read = (file) => readFileSync(join(keyDir, file), 'utf8');
|
||||
const lastLog = () => readFileSync(cfg.log, 'utf8').trim().split('\n').at(-1);
|
||||
const sudoCalls = () => (existsSync(cfg.sudoLog) ? readFileSync(cfg.sudoLog, 'utf8').trim().split('\n') : []);
|
||||
return { root, keyDir, confDir, conf, run, read, lastLog, sudoCalls, done: () => rmSync(root, { recursive: true, force: true }) };
|
||||
}
|
||||
|
||||
const refused = (r, code) => {
|
||||
assert.equal(r.status, 1, r.stderr);
|
||||
assert.equal(r.stderr, `mosaic-keys-write: refused ${code}\n`);
|
||||
};
|
||||
|
||||
test('G16: the writer refuses each user, tag and key the design names, before any key file', () => {
|
||||
const h = hostDirs();
|
||||
try {
|
||||
const key = keyBlob();
|
||||
const t = tag(1);
|
||||
const add = (user) => h.run('add', user, 'ssh-ed25519', key, t);
|
||||
// The user pattern stops `../x` before any path, though the lookups and users know it.
|
||||
for (const user of ['../x', 'Alice', 'a'.repeat(33), '1alice', 'al ice', '']) {
|
||||
refused(add(user), 'user-pattern');
|
||||
refused(h.run('list', user), 'user-pattern');
|
||||
}
|
||||
// users is always required: privileged alone allows nothing.
|
||||
refused(add('dave'), 'user-not-listed');
|
||||
refused(add('eve'), 'user-not-listed');
|
||||
for (const user of ['root', 'localadmin', 'mosaic-installer']) refused(add(user), 'user-not-listed');
|
||||
refused(add('toor'), 'user-system');
|
||||
refused(add('daemon2'), 'user-system');
|
||||
refused(add('ghost'), 'user-not-listed');
|
||||
for (const g of REFUSED_GROUPS) {
|
||||
refused(add('g' + g), 'user-group');
|
||||
refused(h.run('remove', 'g' + g, t), 'user-group');
|
||||
}
|
||||
refused(add('carol'), 'user-sudo');
|
||||
refused(h.run('list', 'carol'), 'user-sudo');
|
||||
assert.equal(h.lastLog(), 'result=refused user-sudo user=carol');
|
||||
for (const bad of ['mosaic-' + 'a'.repeat(31), 'mosaic-' + 'A'.repeat(32), 'mosaic-installer-' + 'a'.repeat(32), 'mosaic-' + 'g'.repeat(32)]) {
|
||||
refused(h.run('add', 'alice', 'ssh-ed25519', key, bad), 'tag-pattern');
|
||||
refused(h.run('remove', 'alice', bad), 'tag-pattern');
|
||||
}
|
||||
refused(h.run('add', 'alice', 'ssh-dss', key, t), 'key-format');
|
||||
refused(h.run('add', 'alice', 'ssh-ed25519', key.slice(0, -2) + '!!', t), 'key-format');
|
||||
refused(h.run('add', 'alice', 'ssh-ed25519', 'A', t), 'key-format');
|
||||
refused(h.run('add', 'alice', 'ssh-ed25519', key + ' x', t), 'key-format');
|
||||
for (const args of [[], ['list'], ['list', 'alice', 'bob'], ['add', 'alice', 'ssh-ed25519', key], ['remove', 'alice'], ['rm', 'alice', t]])
|
||||
refused(h.run(...args), 'request');
|
||||
// No refusal reached the key dir, so not even the lock exists.
|
||||
assert.deepEqual(readdirSync(h.keyDir), []);
|
||||
// Only users past the groups check reach sudo -l, and the privileged never do.
|
||||
assert.deepEqual([...new Set(h.sudoCalls())], ['carol']);
|
||||
} finally {
|
||||
h.done();
|
||||
}
|
||||
});
|
||||
|
||||
test('G16: from= comes from the host file, a privileged user skips the group and sudo checks, and the line is exact', () => {
|
||||
const h = hostDirs();
|
||||
try {
|
||||
const k1 = keyBlob();
|
||||
const k2 = keyBlob();
|
||||
assert.equal(h.run('add', 'alice', 'ssh-ed25519', k1, tag(1)).status, 0);
|
||||
assert.equal(h.lastLog(), `result=added user=alice tag=${tag(1)} key=${fingerprint(k1)}`);
|
||||
h.conf('from', '# the stack host\n10.9.9.9,192.168.1.0/24\n');
|
||||
assert.equal(h.run('add', 'alice', 'ssh-ed25519', k2, tag(2)).status, 0);
|
||||
assert.equal(
|
||||
h.read('alice'),
|
||||
`from="10.1.2.3/32",restrict ssh-ed25519 ${k1} ${tag(1)}\nfrom="10.9.9.9,192.168.1.0/24",restrict ssh-ed25519 ${k2} ${tag(2)}\n`,
|
||||
);
|
||||
// A tag already there changes nothing and exits 0.
|
||||
assert.equal(h.run('add', 'alice', 'ssh-ed25519', k2, tag(1)).status, 0);
|
||||
assert.equal(h.lastLog(), `result=present user=alice tag=${tag(1)} key=${fingerprint(k2)}`);
|
||||
assert.equal(h.read('alice').split('\n').length, 3);
|
||||
// bob is in sudo and docker with a sudo line, and privileged.
|
||||
assert.equal(h.run('add', 'bob', 'ssh-ed25519', k1, tag(3)).status, 0);
|
||||
// frank's groups are none of the refused ones.
|
||||
assert.equal(h.run('add', 'frank', 'ssh-ed25519', k1, tag(4)).status, 0);
|
||||
assert.deepEqual(h.sudoCalls(), ['alice', 'alice', 'alice', 'frank']);
|
||||
// A from value that could close the quote, two values, or none, refuses and writes nothing.
|
||||
for (const text of ['10.0.0.1",command="/bin/sh\n', '10.0.0.1\n10.0.0.2\n', '# none\n', '10.0.0.1 10.0.0.2\n']) {
|
||||
h.conf('from', text);
|
||||
refused(h.run('add', 'frank', 'ssh-ed25519', k2, tag(5)), 'config-from');
|
||||
}
|
||||
rmSync(join(h.confDir, 'from'));
|
||||
refused(h.run('add', 'frank', 'ssh-ed25519', k2, tag(5)), 'config-from');
|
||||
assert.ok(!h.read('frank').includes(tag(5)));
|
||||
// list and remove don't need from.
|
||||
assert.equal(h.run('list', 'frank').stdout, `from="10.9.9.9,192.168.1.0/24",restrict ssh-ed25519 ${k1} ${tag(4)}\n`);
|
||||
for (const name of ['users', 'privileged']) {
|
||||
chmodSync(join(h.confDir, name), 0o664);
|
||||
refused(h.run('list', 'alice'), 'not-root-owned');
|
||||
chmodSync(join(h.confDir, name), 0o644);
|
||||
}
|
||||
rmSync(join(h.confDir, 'users'));
|
||||
refused(h.run('list', 'alice'), 'config-users');
|
||||
} finally {
|
||||
h.done();
|
||||
}
|
||||
});
|
||||
|
||||
test('G16: list shows tagged lines only, and add and remove never touch a line outside the tag pattern', () => {
|
||||
const h = hostDirs();
|
||||
try {
|
||||
const k = keyBlob();
|
||||
const hand = [
|
||||
'# written by hand',
|
||||
`ssh-ed25519 ${k} mosaic-installer-${'a'.repeat(32)}`,
|
||||
'',
|
||||
`ssh-ed25519 ${k} ${tag(9).toUpperCase()}`,
|
||||
`ssh-ed25519 ${k} ${tag(1)} trailing`,
|
||||
];
|
||||
const tagged = `from="10.1.2.3/32",restrict ssh-ed25519 ${k} ${tag(7)}`;
|
||||
writeFileSync(join(h.keyDir, 'alice'), [hand[0], tagged, ...hand.slice(1)].join('\n') + '\n', { mode: 0o644 });
|
||||
assert.equal(h.run('list', 'alice').stdout, tagged + '\n');
|
||||
// The last field is the tag, so `... mosaic-<1> trailing` isn't tag 1.
|
||||
assert.equal(h.run('remove', 'alice', tag(1)).status, 0);
|
||||
assert.equal(h.lastLog(), `result=absent user=alice tag=${tag(1)}`);
|
||||
assert.equal(h.run('add', 'alice', 'ssh-ed25519', k, tag(8)).status, 0);
|
||||
assert.equal(h.run('remove', 'alice', tag(7)).status, 0);
|
||||
assert.equal(h.lastLog(), `result=removed user=alice tag=${tag(7)}`);
|
||||
assert.equal(h.read('alice'), [...hand, `from="10.1.2.3/32",restrict ssh-ed25519 ${k} ${tag(8)}`].join('\n') + '\n');
|
||||
assert.equal(h.run('remove', 'alice', tag(8)).status, 0);
|
||||
assert.equal(h.read('alice'), hand.join('\n') + '\n');
|
||||
// A missing file lists nothing and a remove there changes nothing.
|
||||
assert.equal(h.run('list', 'frank').stdout, '');
|
||||
assert.equal(h.run('remove', 'frank', tag(1)).status, 0);
|
||||
assert.ok(!existsSync(join(h.keyDir, 'frank')));
|
||||
} finally {
|
||||
h.done();
|
||||
}
|
||||
});
|
||||
|
||||
test('G25: the writer refuses a symlinked dir or user file, a group-writable dir and an odd tmp, and writes 0644', () => {
|
||||
const h = hostDirs();
|
||||
try {
|
||||
const k = keyBlob();
|
||||
const add = (n, user = 'alice') => h.run('add', user, 'ssh-ed25519', k, tag(n));
|
||||
// A first add creates the file, regular, 0644, owned by the owner uid, with no tmp left.
|
||||
assert.equal(add(1).status, 0);
|
||||
const st = statSync(join(h.keyDir, 'alice'));
|
||||
assert.equal(st.mode & 0o777, 0o644);
|
||||
assert.equal(st.uid, process.getuid());
|
||||
assert.deepEqual(readdirSync(h.keyDir).sort(), ['.lock', 'alice']);
|
||||
// A leftover regular tmp is unlinked and the write goes ahead.
|
||||
writeFileSync(join(h.keyDir, '.alice.tmp'), 'half a write');
|
||||
assert.equal(add(2).status, 0);
|
||||
assert.ok(h.read('alice').includes(tag(2)));
|
||||
assert.ok(!existsSync(join(h.keyDir, '.alice.tmp')));
|
||||
// A tmp that is a symlink, a dir or a fifo refuses, and nothing is written.
|
||||
const decoy = join(h.root, 'decoy');
|
||||
writeFileSync(decoy, 'decoy\n');
|
||||
const before = h.read('alice');
|
||||
for (const make of [
|
||||
(p) => symlinkSync(decoy, p),
|
||||
(p) => mkdirSync(p),
|
||||
(p) => execFileSync('mkfifo', [p]),
|
||||
]) {
|
||||
make(join(h.keyDir, '.alice.tmp'));
|
||||
refused(add(3), 'tmp-file');
|
||||
assert.equal(h.read('alice'), before);
|
||||
assert.equal(readFileSync(decoy, 'utf8'), 'decoy\n');
|
||||
rmSync(join(h.keyDir, '.alice.tmp'), { recursive: true });
|
||||
}
|
||||
// A symlinked user file refuses, though its target is a regular file the owner owns.
|
||||
symlinkSync(decoy, join(h.keyDir, 'frank'));
|
||||
refused(add(4, 'frank'), 'user-file');
|
||||
refused(h.run('list', 'frank'), 'user-file');
|
||||
assert.equal(readFileSync(decoy, 'utf8'), 'decoy\n');
|
||||
assert.ok(lstatSync(join(h.keyDir, 'frank')).isSymbolicLink());
|
||||
// A user "file" that is a dir refuses.
|
||||
mkdirSync(join(h.keyDir, 'bob'));
|
||||
refused(add(5, 'bob'), 'not-root-owned');
|
||||
// A group-writable dir refuses.
|
||||
chmodSync(h.keyDir, 0o775);
|
||||
refused(add(6), 'not-root-owned');
|
||||
chmodSync(h.keyDir, 0o755);
|
||||
// A symlinked key dir refuses, and its target is untouched.
|
||||
const real = join(h.root, 'real-keys');
|
||||
mkdirSync(real, { mode: 0o755 });
|
||||
rmSync(h.keyDir, { recursive: true });
|
||||
symlinkSync(real, h.keyDir);
|
||||
refused(add(7), 'key-dir');
|
||||
assert.deepEqual(readdirSync(real), []);
|
||||
} finally {
|
||||
h.done();
|
||||
}
|
||||
});
|
||||
|
||||
// mosaic-keys from a copy with its sudo and logger paths on stubs. The stub sudo records its argv,
|
||||
// prints a line and exits 3, so the test sees the exit and output pass through.
|
||||
function forcedCommand() {
|
||||
const root = mkdtempSync(join(tmpdir(), 'hk234-'));
|
||||
const sudo = join(root, 'sudo');
|
||||
const logger = join(root, 'logger');
|
||||
writeFileSync(sudo, `#!/bin/bash\nprintf '%s\\n' "$@" > ${root}/sudo.argv\necho from-writer\nexit 3\n`, { mode: 0o755 });
|
||||
writeFileSync(logger, `#!/bin/bash\nprintf '%s\\n' "$*" >> ${root}/logger.log\n`, { mode: 0o755 });
|
||||
const source = readFileSync(join(TOOLS, 'mosaic-keys'), 'utf8');
|
||||
assert.equal(source.split('/usr/bin/sudo').length, 2);
|
||||
assert.equal(source.split('/usr/bin/logger').length, 2);
|
||||
const copy = join(root, 'mosaic-keys');
|
||||
writeFileSync(copy, source.replace('/usr/bin/sudo', sudo).replace('/usr/bin/logger', logger), { mode: 0o755 });
|
||||
const run = (request) => {
|
||||
rmSync(join(root, 'sudo.argv'), { force: true });
|
||||
const env = { PATH: '/usr/bin:/bin', SSH_CONNECTION: '10.1.2.3 50000 10.1.2.9 22' };
|
||||
if (request !== undefined) env.SSH_ORIGINAL_COMMAND = request;
|
||||
const r = spawnSync(copy, [], { encoding: 'utf8', env });
|
||||
const argv = existsSync(join(root, 'sudo.argv')) ? readFileSync(join(root, 'sudo.argv'), 'utf8').trim().split('\n') : null;
|
||||
return { status: r.status, stdout: r.stdout, stderr: r.stderr, argv };
|
||||
};
|
||||
const logged = () => readFileSync(join(root, 'logger.log'), 'utf8').trim().split('\n');
|
||||
return { run, logged, done: () => rmSync(root, { recursive: true, force: true }) };
|
||||
}
|
||||
|
||||
test('G16: mosaic-keys passes the three requests to the writer through sudo and refuses anything else without it', () => {
|
||||
const f = forcedCommand();
|
||||
try {
|
||||
const k = keyBlob();
|
||||
const t = tag(1);
|
||||
const writer = ['-n', '/usr/local/sbin/mosaic-keys-write'];
|
||||
for (const words of [['list', 'alice'], ['add', 'alice', 'ssh-ed25519', k, t], ['add', 'alice', 'ecdsa-sha2-nistp256', 'AAAA', t], ['remove', 'alice', t]]) {
|
||||
const r = f.run(words.join(' '));
|
||||
assert.deepEqual(r.argv, [...writer, ...words]);
|
||||
assert.equal(r.status, 3);
|
||||
assert.equal(r.stdout, 'from-writer\n');
|
||||
}
|
||||
const bad = [
|
||||
undefined, '', 'list', 'list ../x', 'list Alice', 'list alice;id', 'list alice ', ' list alice', 'list alice', 'list\talice',
|
||||
'list alice\nlist bob', 'list $(id)', 'list alice`id`', 'list *', 'rm alice', 'list ' + 'a'.repeat(33),
|
||||
`add alice ssh-dss ${k} ${t}`, `add alice ssh-ed25519 ${k}! ${t}`, `add alice ssh-ed25519 ${k}`, `add alice ssh-ed25519 ${k} ${t} x`,
|
||||
`remove alice mosaic-${'a'.repeat(31)}`, `remove alice ${t.toUpperCase()}`, `remove alice ${t}\n`, `remove alice ${t}; rm -rf /`,
|
||||
];
|
||||
for (const request of bad) {
|
||||
const r = f.run(request);
|
||||
assert.equal(r.argv, null, JSON.stringify(request));
|
||||
assert.equal(r.status, 1);
|
||||
assert.equal(r.stderr, 'mosaic-keys: refused\n');
|
||||
}
|
||||
// Two bad requests hold a newline, so count the logger calls, not the lines.
|
||||
const logged = f.logged().filter((l) => l.startsWith('-t mosaic-keys -- '));
|
||||
assert.equal(logged.length, 4 + bad.length);
|
||||
assert.equal(logged[0], '-t mosaic-keys -- connection=10.1.2.3 50000 10.1.2.9 22 request=list alice');
|
||||
} finally {
|
||||
f.done();
|
||||
}
|
||||
});
|
||||
|
||||
test('E3: the sudoers line and the sshd drop-in are the design lines and parse', () => {
|
||||
const lines = (file) => readFileSync(join(TOOLS, file), 'utf8').split('\n').filter((l) => l && !l.startsWith('#'));
|
||||
assert.deepEqual(lines('mosaic-keys.sudoers'), ['mosaic-installer ALL=(root) NOPASSWD: /usr/local/sbin/mosaic-keys-write']);
|
||||
assert.deepEqual(lines('mosaic-keys.sshd.conf'), ['AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 /etc/ssh/mosaic-keys/%u']);
|
||||
assert.ok(existsSync('/usr/bin/visudo'), 'visudo on the test host');
|
||||
execFileSync('/usr/bin/visudo', ['-c', '-q', '-f', join(TOOLS, 'mosaic-keys.sudoers')]);
|
||||
const dir = mkdtempSync(join(tmpdir(), 'hk234-'));
|
||||
try {
|
||||
execFileSync('ssh-keygen', ['-q', '-t', 'ed25519', '-N', '', '-f', join(dir, 'hk')]);
|
||||
writeFileSync(join(dir, 'cfg'), `HostKey ${join(dir, 'hk')}\nInclude ${join(TOOLS, 'mosaic-keys.sshd.conf')}\n`);
|
||||
const out = execFileSync('/usr/bin/sshd', ['-T', '-f', join(dir, 'cfg'), '-C', 'user=alice,host=x,addr=127.0.0.1'], { encoding: 'utf8' });
|
||||
// sshd -T prints this key as AuthorizedKeysFile, unlike most.
|
||||
const line = out.split('\n').filter((l) => /^authorizedkeysfile /i.test(l));
|
||||
assert.deepEqual(line.map((l) => l.split(' ').slice(1).join(' ')), ['.ssh/authorized_keys .ssh/authorized_keys2 /etc/ssh/mosaic-keys/%u']);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
for (const file of ['mosaic-keys', 'mosaic-keys-write']) assert.equal(statSync(join(TOOLS, file)).mode & 0o111, 0o111, file);
|
||||
assert.equal(readFileSync(WRITER, 'utf8').split('\n')[0], '#!/usr/bin/python3 -I');
|
||||
});
|
||||
@@ -55,7 +55,7 @@ test('3f copy migrates to 3g preserving every old column/row, with an empty inst
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
const store = new Store(root, { migrateSchema: true });
|
||||
try {
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3j');
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3i');
|
||||
assert.deepEqual({ ...store.get('SELECT to_name FROM messages') }, { to_name: null });
|
||||
assert.equal(store.get('SELECT count(*) AS n FROM instance_names').n, 0);
|
||||
assert.deepEqual({ ...store.get('SELECT spec_path,spec_commit FROM decisions') }, { spec_path: 'docs/spec.md', spec_commit: 'c'.repeat(40) });
|
||||
|
||||
@@ -25,9 +25,7 @@ test('Broker keeps the sandbox client import closure: only the listed imports, n
|
||||
// RUNNER_FILES and imports nothing. Row 155 (#1649) reads THREAD_DEFINITION and END_PROTECTED
|
||||
// from it too. Row 199 (#1697) reads the D9c fork parse, forkProblem and forkUrl, from it.
|
||||
// Row 210 (#1707) reads credentialKind and the D6 argv check, validArgv and commandAllowed, from it.
|
||||
// Row 234 (#1740) reads HOST_ID for the hosts verbs.
|
||||
// Row 213 (#1714) reads CREATIVE_DEFINITIONS for the creative raise refusal (M6).
|
||||
"import { ID_PATTERN, THREAD_DEFINITION, END_PROTECTED, forkProblem, forkUrl, credentialKind, validArgv, commandAllowed, HOST_ID, CREATIVE_DEFINITIONS } from '../../business/src/vocabulary.mjs';",
|
||||
"import { ID_PATTERN, THREAD_DEFINITION, END_PROTECTED, forkProblem, forkUrl, credentialKind, validArgv, commandAllowed } from '../../business/src/vocabulary.mjs';",
|
||||
]);
|
||||
assert.doesNotMatch(source, /\bimport\s*\(/);
|
||||
assert.doesNotMatch(readFileSync(new URL('../src/landing.mjs', import.meta.url), 'utf8'), /\bimport\b/);
|
||||
|
||||
@@ -519,8 +519,7 @@ test('v3b prototype refusals, views and append-only mutations', (t) => {
|
||||
// Row 121 (#1615) adds 5 tables and 24 triggers for projects and threads; threads.test.mjs tests them.
|
||||
// Row 141 (#1635) adds instance_names and its 4 triggers; names.test.mjs tests them.
|
||||
// Row 124 adds usage_records and its three append-only triggers.
|
||||
// Row 234 (#1740) adds hosts, host_grants and the events_grant_actor guard; grant-migration.test.mjs tests them.
|
||||
assert.equal(count('table') - 1, 18);
|
||||
assert.equal(count('trigger'), 71);
|
||||
assert.equal(count('table') - 1, 16);
|
||||
assert.equal(count('trigger'), 70);
|
||||
assert.equal(count('view'), 5);
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Broker } from '../src/broker.mjs';
|
||||
import { initProject, readSpec, writeRecord, listProjectFiles, readProjectFile, writeHumanFile, ProjectError } from '../../project/src/index.mjs';
|
||||
export const git = (repo, ...args) => execFileSync('git', ['-c', 'core.hooksPath=/dev/null', '-C', repo, ...args], { encoding: 'utf8' }).trim();
|
||||
const options = [{ key: 'yes', text: 'Yes' }, { key: 'no', text: 'No' }];
|
||||
export async function fixture(t, { adapter = true, roles = {}, arbiters = { technical: 'reviewer', delivery: 'reviewer' } } = {}) {
|
||||
export async function fixture(t, { adapter = true, roles = {}, arbiters = { technical: 'reviewer', delivery: 'reviewer' }, hosts } = {}) {
|
||||
const root = mkdtempSync(join(tmpdir(), 'bus-spec-'));
|
||||
const store = new Store(root);
|
||||
t.after(() => { store.close(); rmSync(root, { recursive: true, force: true }); });
|
||||
@@ -17,7 +17,7 @@ export async function fixture(t, { adapter = true, roles = {}, arbiters = { tech
|
||||
coder: { definition: 'coder', authority: authority(['message.send', 'record.write']) },
|
||||
reviewer: { definition: 'reviewer', authority: authority(['message.send']) },
|
||||
...roles,
|
||||
} };
|
||||
}, ...(hosts ? { hosts } : {}) };
|
||||
const { repo, commit } = await initProject({ business, project: 'stack', dataRoot: root });
|
||||
const broker = new Broker({ store, businesses: { demo: business }, project: adapter ? {
|
||||
readSpec: context => readSpec({ ...context, dataRoot: root }),
|
||||
|
||||
@@ -53,7 +53,7 @@ test('3e copy migrates through 3f to 3g preserving every old column/row and addi
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
const store = new Store(root, { migrateSchema: true });
|
||||
try {
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3j');
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3i');
|
||||
assert.deepEqual({ ...store.get('SELECT spec_path,spec_commit FROM decisions') }, { spec_path: null, spec_commit: null });
|
||||
assert.equal(store.get('PRAGMA quick_check').quick_check, 'ok');
|
||||
assert.deepEqual(store.all('PRAGMA foreign_key_check'), []);
|
||||
|
||||
@@ -49,7 +49,7 @@ async function database3d(t) {
|
||||
const source = readFileSync(here('../src/store.mjs'), 'utf8');
|
||||
const pinned = source
|
||||
.replace(/export const SCHEMA_SHA256 = '[a-f0-9]+';/, `export const SCHEMA_SHA256 = '${createHash('sha256').update(ddl3d).digest('hex')}';`)
|
||||
.replace("export const SCHEMA_VERSION = '3j';", "export const SCHEMA_VERSION = '3d';")
|
||||
.replace("export const SCHEMA_VERSION = '3i';", "export const SCHEMA_VERSION = '3d';")
|
||||
.replace(/\}, \{\n {2}from: '3d',[\s\S]*?\}\];\nconst timedTables/, '}];\nconst timedTables');
|
||||
assert.ok(!pinned.includes('3d-3e'), 'the 3d engine has no 3d→3e step');
|
||||
writeFileSync(join(moduleRoot, 'src/store.mjs'), pinned);
|
||||
@@ -101,7 +101,7 @@ test('REQ-THREAD-1 REQ-ORG-2: the 3d→3e migration adds the thread tables and l
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
const store = new Store(root, { migrateSchema: true });
|
||||
t.after(() => store.close());
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3j');
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3i');
|
||||
for (const table of ['projects', 'threads', 'thread_claims', 'message_threads', 'thread_opens'])
|
||||
assert.equal(store.get(`SELECT count(*) n FROM ${table}`).n, 0, table);
|
||||
// Parked: the undelivered ones are counted per business and role, and none is changed or given a thread.
|
||||
@@ -161,5 +161,5 @@ test('REQ-THREAD-1: the offline command prints the kept-message counts before th
|
||||
const command = new URL('../src/migrate-schema.mjs', import.meta.url).pathname;
|
||||
const migrated = spawnSync(process.execPath, [command, root], { encoding: 'utf8' });
|
||||
assert.equal(migrated.status, 0, migrated.stderr);
|
||||
assert.equal(migrated.stdout, [...REPORT, 'bus schema 3j ready', ''].join('\n'));
|
||||
assert.equal(migrated.stdout, [...REPORT, 'bus schema 3i ready', ''].join('\n'));
|
||||
});
|
||||
|
||||
@@ -51,12 +51,12 @@ function snapshot(path, columns) {
|
||||
return { columns, rows };
|
||||
} finally { db.close(); }
|
||||
}
|
||||
test('REQ-LIMIT-4 3g copy migrates through 3h and 3i to 3j preserving every old column, row and sequence; new usage table is empty', t => {
|
||||
test('REQ-LIMIT-4 3g copy migrates through 3h to 3i preserving every old column, row and sequence; new usage table is empty', t => {
|
||||
const { root, path, copy } = source3g(t), before = snapshot(path), untouched = readFileSync(copy);
|
||||
assert.throws(() => new Store(root), /schema-mismatch/);
|
||||
const store = new Store(root, { migrateSchema: true });
|
||||
try {
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3j');
|
||||
assert.equal(store.get("SELECT value FROM meta WHERE key='schema_version'").value, '3i');
|
||||
assert.deepEqual({ ...store.get('SELECT to_name FROM messages') }, { to_name: null });
|
||||
assert.equal(store.get('SELECT count(*) AS n FROM usage_records').n, 0);
|
||||
assert.equal(store.get('SELECT name FROM instance_names').name, 'Builder');
|
||||
|
||||
@@ -10,7 +10,8 @@ import { checkVars } from "./vars.mjs";
|
||||
import { parseCredentialRef } from "./credentials.mjs";
|
||||
import { loadRole } from "./role.mjs";
|
||||
import { checkPlugins } from "../../plugins/src/kinds.mjs";
|
||||
import { forkProblem, giteaName, parseGiteaUrl, HOST_SERVICE, CREATIVE_DEFINITIONS } from "./vocabulary.mjs";
|
||||
import { forkProblem, giteaName, parseGiteaUrl, HOST_SERVICE, HOST_PREFIX } from "./vocabulary.mjs";
|
||||
import { checkHosts, checkHostGrants } from "./hosts.mjs";
|
||||
import {
|
||||
requireObject, rejectUnknownKeys, requireId, requirePositiveInt, requireString, requireDistinctList, readJsonFile, deepFreeze,
|
||||
} from "./util.mjs";
|
||||
@@ -102,20 +103,7 @@ function checkTracker(tracker, file) {
|
||||
return { sync, labels };
|
||||
}
|
||||
|
||||
// Row 213 (C2-08, Case 2 design 4): persona vars belong only to a creative instance, and come as a
|
||||
// pair, since the bundle reads the file only against its digest.
|
||||
function checkPersonaVars(vars, definition, at) {
|
||||
const set = ["persona.name", "persona.sha256"].filter((key) => Object.hasOwn(vars, key));
|
||||
if (set.length === 0) return;
|
||||
if (!CREATIVE_DEFINITIONS.includes(definition)) refuse(`${at}.vars: persona vars need a creative definition (${definition} isn't one)`);
|
||||
if (set.length === 1) refuse(`${at}.vars: persona.name and persona.sha256 are set together or not at all`);
|
||||
}
|
||||
|
||||
// Row 234 (#1740, r6 S1): hosts and host grants are bus store records made by a human-approved grant,
|
||||
// so the business file can't name them. The key stays known so the refusal says where they went.
|
||||
const HOSTS_MOVED = "lives in the bus store now: enroll a host with a host-enroll grant (mosaic hosts status)";
|
||||
|
||||
function checkRoles(roles, file, rolesDir, business) {
|
||||
function checkRoles(roles, file, rolesDir, business, hosts) {
|
||||
const where = `${file} roles`;
|
||||
requireObject(roles, where);
|
||||
if (Object.keys(roles).length === 0) refuse(`${where} must declare at least one role instance`);
|
||||
@@ -133,9 +121,14 @@ function checkRoles(roles, file, rolesDir, business) {
|
||||
definitions[entry.definition] = definition;
|
||||
if (definition.roleVersion !== 2) refuse(`${at}: role definition ${entry.definition} is version 1 and can't back a business role instance`);
|
||||
const services = definition.credentials.map((c) => c.service);
|
||||
if (entry.hosts !== undefined) refuse(`${at}.hosts ${HOSTS_MOVED}`);
|
||||
// A host.<id> key reference comes from the agent's grant record at bus start (r6 X4), never from here.
|
||||
const kinds = services.filter((s) => s !== HOST_SERVICE);
|
||||
// Row 210 (#1707, design D3 steps 1 and 3): a host grant needs a definition that declares the
|
||||
// host credential, and each granted host needs its own host.<id> key reference.
|
||||
let hostGrants = null;
|
||||
if (entry.hosts !== undefined) {
|
||||
if (!services.includes(HOST_SERVICE)) refuse(`${at}.hosts needs a role definition that declares the host credential`);
|
||||
hostGrants = checkHostGrants(entry.hosts, hosts, `${at}.hosts`);
|
||||
}
|
||||
const kinds = [...services.filter((s) => s !== HOST_SERVICE), ...Object.keys(hostGrants ?? {}).map((id) => HOST_PREFIX + id)];
|
||||
let tracker = null;
|
||||
if (services.includes("vikunja")) {
|
||||
if (entry.tracker === undefined) refuse(`${at} needs "tracker" with its Vikunja bot, because ${entry.definition} uses vikunja`);
|
||||
@@ -158,13 +151,13 @@ function checkRoles(roles, file, rolesDir, business) {
|
||||
// Row 199 (#1697, design D8, D9 step 2): identity and publish are optional, so today's files
|
||||
// load unchanged. publish needs both an identity and a gitea credential; the project ids it
|
||||
// names are checked against projects once those are read.
|
||||
if (hostGrants) out[instance].hosts = hostGrants;
|
||||
if (entry.identity !== undefined) out[instance].identity = checkIdentity(entry.identity, `${at}.identity`);
|
||||
if (entry.publish !== undefined) {
|
||||
// N10: one message for both, naming the grant.
|
||||
if (!out[instance].identity || !services.includes("gitea")) refuse(`${at}.publish needs identity and a gitea definition`);
|
||||
out[instance].publish = requireDistinctList(entry.publish, `${at}.publish`, (p) => requireId(p, `${at}.publish entry`), { nonEmpty: true });
|
||||
}
|
||||
checkPersonaVars(out[instance].vars, entry.definition, at);
|
||||
}
|
||||
return { roles: out, definitions };
|
||||
}
|
||||
@@ -214,8 +207,8 @@ export function validateBusinessDocument(document, file, { rolesDir }) {
|
||||
}
|
||||
const human = requireId(document.human, "business human");
|
||||
const vars = checkVars(document.vars ?? {}, "business", `${file} vars`);
|
||||
if (document.hosts !== undefined) refuse(`${file} hosts ${HOSTS_MOVED}`);
|
||||
const { roles, definitions } = checkRoles(document.roles, file, rolesDir, document.id);
|
||||
const hosts = checkHosts(document.hosts, `${file} hosts`);
|
||||
const { roles, definitions } = checkRoles(document.roles, file, rolesDir, document.id, hosts);
|
||||
|
||||
requireObject(document.arbiters, `${file} arbiters`);
|
||||
rejectUnknownKeys(document.arbiters, ["delivery", "technical"], `${file} arbiters`);
|
||||
@@ -275,6 +268,7 @@ export function validateBusinessDocument(document, file, { rolesDir }) {
|
||||
|
||||
return deepFreeze({
|
||||
businessVersion: 1, id: document.id, file, human, arbiters, projects, vars, tracker, roles, launch, plugins, definitions,
|
||||
...(document.hosts === undefined ? {} : { hosts }),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
// Row 210 (#1707, design D3 and D6): the address, user and host key checks, and the argv allowlist the
|
||||
// broker matches each host.run against. Row 234 (#1740, r6 S1) moved the host registry and the grants
|
||||
// out of the business file into bus store records. The enrollment raise checks its fields with these,
|
||||
// and row b's host grant raise checks its commands with checkCommands.
|
||||
// Row 210 (#1707, design D3 and D6): the host registry in the business file, an agent's host
|
||||
// grants, and the argv allowlist the broker matches each host.run against. Hand edits only: the
|
||||
// chief's organization.set and the human's instances.set take neither key.
|
||||
|
||||
import { isIP } from "node:net";
|
||||
import { refuse } from "./errors.mjs";
|
||||
import { ARGV_MAX } from "./vocabulary.mjs";
|
||||
import { HOST_ID, ARGV_MAX } from "./vocabulary.mjs";
|
||||
// Row 210 r4 (#1707): the argv check lives in vocabulary.mjs, which the worker sandbox mounts
|
||||
// and which imports nothing, so the broker can read it. Re-exported so the D6 checks keep one
|
||||
// business home here.
|
||||
export { ARGV_MAX, ARG_BYTES, ARGV_BYTES, validArgv, commandAllowed } from "./vocabulary.mjs";
|
||||
import { requireObject, rejectUnknownKeys, isPlainObject } from "./util.mjs";
|
||||
|
||||
const DNS = /^[a-z0-9]([a-z0-9.-]{0,251}[a-z0-9])?$/;
|
||||
export const USER = /^[a-z_][a-z0-9_-]{0,31}$/;
|
||||
export const HOST_KEY = /^(ssh-ed25519|ecdsa-sha2-nistp256|ssh-rsa) [A-Za-z0-9+/]+={0,2}$/;
|
||||
const USER = /^[a-z_][a-z0-9_-]{0,31}$/;
|
||||
const HOST_KEY = /^(ssh-ed25519|ecdsa-sha2-nistp256|ssh-rsa) [A-Za-z0-9+/]+={0,2}$/;
|
||||
|
||||
// D6: a prefix starting with one of these, by basename, would turn the grant back into "any".
|
||||
// The list can't be complete. Under PRD 1.7 the control is the human's decision on each call (D4).
|
||||
@@ -49,7 +49,7 @@ export function ownMachine(address) {
|
||||
return address === "localhost" || address.endsWith(".localhost");
|
||||
}
|
||||
|
||||
export function checkAddress(address, where) {
|
||||
function checkAddress(address, where) {
|
||||
if (typeof address !== "string") refuse(`${where} must be an IP address or a DNS name`);
|
||||
const version = isIP(address);
|
||||
if (version === 6 && address.includes("%")) refuse(`${where} must not carry an IPv6 zone`);
|
||||
@@ -63,6 +63,32 @@ export function checkAddress(address, where) {
|
||||
return address;
|
||||
}
|
||||
|
||||
// The top-level "hosts" key: { <hostId>: { address, port, user, hostKeys } }.
|
||||
export function checkHosts(hosts, where) {
|
||||
if (hosts === undefined) return {};
|
||||
requireObject(hosts, where);
|
||||
const out = {};
|
||||
for (const [id, entry] of Object.entries(hosts)) {
|
||||
if (!HOST_ID.test(id)) refuse(`${where} host id ${JSON.stringify(id)} must match ${HOST_ID}`);
|
||||
const at = `${where}.${id}`;
|
||||
requireObject(entry, at);
|
||||
rejectUnknownKeys(entry, ["address", "port", "user", "hostKeys"], at);
|
||||
const address = checkAddress(entry.address, `${at}.address`);
|
||||
if (!Number.isInteger(entry.port) || entry.port < 1 || entry.port > 65535) refuse(`${at}.port must be 1 to 65535`);
|
||||
if (typeof entry.user !== "string" || !USER.test(entry.user)) refuse(`${at}.user must match ${USER}`);
|
||||
if (!Array.isArray(entry.hostKeys) || entry.hostKeys.length === 0) refuse(`${at}.hostKeys must be a non-empty list`);
|
||||
const keys = entry.hostKeys.map((key, i) => {
|
||||
if (typeof key !== "string" || !HOST_KEY.test(key)) {
|
||||
refuse(`${at}.hostKeys[${i}] must be "<type> <base64>" with type ssh-ed25519, ecdsa-sha2-nistp256 or ssh-rsa, and no comment`);
|
||||
}
|
||||
return key;
|
||||
});
|
||||
if (new Set(keys).size !== keys.length) refuse(`${at}.hostKeys lists a key twice`);
|
||||
out[id] = { address, port: entry.port, user: entry.user, hostKeys: keys };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// D6: an argv allowlist and nothing else. No wildcard: "any", "*", {} and [] all refuse.
|
||||
export function checkCommands(commands, where) {
|
||||
if (!Array.isArray(commands)) refuse(`${where} must be a list of argv prefixes; there is no wildcard grant`);
|
||||
@@ -84,3 +110,18 @@ export function checkCommands(commands, where) {
|
||||
return [...prefix];
|
||||
});
|
||||
}
|
||||
|
||||
// A role entry's "hosts": { <hostId>: { commands } }, each id in the registry.
|
||||
export function checkHostGrants(grants, registry, where) {
|
||||
requireObject(grants, where);
|
||||
if (Object.keys(grants).length === 0) refuse(`${where} must name at least one host`);
|
||||
const out = {};
|
||||
for (const [id, grant] of Object.entries(grants)) {
|
||||
const at = `${where}.${id}`;
|
||||
if (!Object.hasOwn(registry, id)) refuse(`${at}: host ${id} isn't in the business file's hosts`);
|
||||
if (!isPlainObject(grant)) refuse(`${at} must be an object`);
|
||||
rejectUnknownKeys(grant, ["commands"], at);
|
||||
out[id] = { commands: checkCommands(grant.commands, `${at}.commands`) };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
import { existsSync, readdirSync } from "node:fs";
|
||||
import { organizationWriter, OrganizationError } from "./organization.mjs";
|
||||
import { validateBusinessDocument, businessFilePath } from "./business.mjs";
|
||||
import { checkRoutes, creativeHumanOnly } from "./launch-settings.mjs";
|
||||
import { checkRoutes } from "./launch-settings.mjs";
|
||||
import { loadProject, projectFilePath } from "./project.mjs";
|
||||
import { resolveInstance } from "./resolve.mjs";
|
||||
import { loadRole } from "./role.mjs";
|
||||
import { isPlainObject, canonicalJson } from "./util.mjs";
|
||||
import { CREATIVE_DEFINITIONS, END_PROTECTED, ID_PATTERN } from "./vocabulary.mjs";
|
||||
import { END_PROTECTED, ID_PATTERN } from "./vocabulary.mjs";
|
||||
|
||||
const SET_KEYS = ["revision", "instance", "op", "definition", "vars", "launch"];
|
||||
const id = value => typeof value === "string" && ID_PATTERN.test(value);
|
||||
@@ -19,12 +19,8 @@ const id = value => typeof value === "string" && ID_PATTERN.test(value);
|
||||
// A definition this writer can give an instance: version 2, not END_PROTECTED, and declaring no
|
||||
// credential. An instance of one that declares credentials needs credentials and a tracker bot,
|
||||
// which stay out of this row (sage-0918); the refusal names that, so a later row lifts it alone.
|
||||
// Row 213 (C2-08, M10): a creative definition is END_PROTECTED, yet this writer is how the human
|
||||
// adds and changes one, so it isn't closed here. The caller runs creativeHumanOnly first.
|
||||
const closed = name => END_PROTECTED.includes(name) && !CREATIVE_DEFINITIONS.includes(name);
|
||||
|
||||
function definitionFor(rolesDir, name) {
|
||||
if (closed(name)) throw new OrganizationError("organization-definition-refused");
|
||||
if (END_PROTECTED.includes(name)) throw new OrganizationError("organization-definition-refused");
|
||||
const definition = loadRole(rolesDir, name);
|
||||
if (definition.roleVersion !== 2) throw new OrganizationError("invalid-request", `role definition ${name} is version 1`);
|
||||
if (definition.credentials.length > 0) {
|
||||
@@ -53,7 +49,7 @@ export function instanceSettings({ dir, rolesDir, system, levels = () => null })
|
||||
}
|
||||
if (definition.roleVersion !== 2) continue;
|
||||
const services = definition.credentials.map(c => c.service);
|
||||
out[name] = { services, accepted: !closed(name) && services.length === 0 };
|
||||
out[name] = { services, accepted: !END_PROTECTED.includes(name) && services.length === 0 };
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -67,7 +63,7 @@ export function instanceSettings({ dir, rolesDir, system, levels = () => null })
|
||||
vars: entry.vars ?? {},
|
||||
launched: launch ? launch.instances.includes(name) : false,
|
||||
launcher: launch ? launch.by === name : false,
|
||||
protected: closed(entry.definition),
|
||||
protected: END_PROTECTED.includes(entry.definition),
|
||||
}]));
|
||||
return { business, revision, launch: launch !== null, instances, definitions: definitions() };
|
||||
}
|
||||
@@ -101,7 +97,6 @@ export function instanceSettings({ dir, rolesDir, system, levels = () => null })
|
||||
if (op === "add") {
|
||||
if (!Object.hasOwn(args, "definition")) throw new OrganizationError("invalid-request");
|
||||
if (exists) throw new OrganizationError("organization-instance-exists");
|
||||
creativeHumanOnly(old, actor, instance, args.definition);
|
||||
definitionFor(rolesDir, args.definition);
|
||||
next.roles[instance] = { definition: args.definition, ...(Object.hasOwn(args, "vars") ? { vars: structuredClone(args.vars) } : {}) };
|
||||
redefined = true;
|
||||
@@ -110,12 +105,9 @@ export function instanceSettings({ dir, rolesDir, system, levels = () => null })
|
||||
if (!exists) throw new OrganizationError("organization-unknown-instance");
|
||||
const entry = next.roles[instance];
|
||||
// An assistant's settings change only through limits.set's assistants key (row 155), so
|
||||
// nothing here touches a protected instance, its vars and launch membership included. A
|
||||
// creative instance is the exception: the human changes it here, and only the human (M10).
|
||||
creativeHumanOnly(old, actor, instance, entry.definition);
|
||||
if (closed(entry.definition)) throw new OrganizationError("organization-definition-refused");
|
||||
// nothing here touches a protected instance, its vars and launch membership included.
|
||||
if (END_PROTECTED.includes(entry.definition)) throw new OrganizationError("organization-definition-refused");
|
||||
if (Object.hasOwn(args, "definition") && args.definition !== entry.definition) {
|
||||
creativeHumanOnly(old, actor, instance, args.definition);
|
||||
definitionFor(rolesDir, args.definition);
|
||||
// The old definition's credentials would bind to the new one's authority.
|
||||
if (loadRole(rolesDir, entry.definition).credentials.length > 0) {
|
||||
|
||||
@@ -5,16 +5,7 @@ import { resolveInstance } from "./resolve.mjs";
|
||||
import { usageCounts } from "./launch.mjs";
|
||||
import { canonicalJson, isPlainObject, requireObject, rejectUnknownKeys } from "./util.mjs";
|
||||
import { FALLBACK_VARS } from "./vars.mjs";
|
||||
import { THREAD_DEFINITION, CREATIVE_DEFINITIONS } from "./vocabulary.mjs";
|
||||
|
||||
// Row 213 (C2-08, Case 2 design 4, M10): a creative instance, its persona included, is the
|
||||
// human's. A write that touches one is accepted only when its actor is the business file's
|
||||
// human; the broker sets the actor to the human's id, "tester" or <definition>.<instance>.
|
||||
export function creativeHumanOnly(document, actor, instance, definition) {
|
||||
if (CREATIVE_DEFINITIONS.includes(definition) && actor !== document.human) {
|
||||
throw new OrganizationError("organization-creative-human-only", `${instance} is a ${definition} instance, which only the human changes`);
|
||||
}
|
||||
}
|
||||
import { THREAD_DEFINITION } from "./vocabulary.mjs";
|
||||
|
||||
// Row 155 (#1649, Jason's ruling Q169): the fields of an assistant instance's entry the human and
|
||||
// the chief of staff may change. holder and credentials stay hand edits.
|
||||
@@ -175,30 +166,13 @@ export function launchSettings({ dir, rolesDir, system, sessions = () => [], now
|
||||
stamp(next.launch.limits, old.document.launch.limits, at);
|
||||
}
|
||||
if (Object.hasOwn(args, "reset")) reset(next.launch.limits, args.reset, at);
|
||||
if (Object.hasOwn(args, "models")) {
|
||||
// M10: replacing launch.models can change the model behind a key a creative instance names
|
||||
// without touching the instance, so a change to or removal of such a key is the human's.
|
||||
for (const [instance, entry] of Object.entries(old.document.roles)) {
|
||||
const vars = entry.vars ?? {};
|
||||
for (const key of [vars.model, vars["fallback.model"]]) {
|
||||
if (typeof key !== "string") continue;
|
||||
const was = own(old.document.launch.models, key) ? canonicalJson(old.document.launch.models[key]) : null;
|
||||
const is = own(args.models, key) ? canonicalJson(args.models[key]) : null;
|
||||
if (was !== is) creativeHumanOnly(old.document, actor, instance, entry.definition);
|
||||
}
|
||||
}
|
||||
next.launch.models = args.models;
|
||||
}
|
||||
if (Object.hasOwn(args, "models")) next.launch.models = args.models;
|
||||
if (Object.hasOwn(args, "instances")) {
|
||||
requireObject(args.instances, "instance model selections");
|
||||
for (const [instance, key] of Object.entries(args.instances)) {
|
||||
if (!Object.hasOwn(next.roles, instance) || typeof key !== "string") {
|
||||
throw new OrganizationError("invalid-request");
|
||||
}
|
||||
// M10: a creative instance's model changes through instances.set or routes.set, whoever asks.
|
||||
if (CREATIVE_DEFINITIONS.includes(next.roles[instance].definition)) {
|
||||
throw new OrganizationError("organization-creative-instance", `${instance}'s model changes through instances.set or routes.set`);
|
||||
}
|
||||
next.roles[instance].vars = { ...next.roles[instance].vars, model: key };
|
||||
}
|
||||
}
|
||||
@@ -276,7 +250,6 @@ export function launchSettings({ dir, rolesDir, system, sessions = () => [], now
|
||||
const exact = (value, keys) => isPlainObject(value) && Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
||||
for (const [instance, route] of Object.entries(args.routes)) {
|
||||
if (!Object.hasOwn(next.roles, instance)) throw new OrganizationError("organization-unknown-instance");
|
||||
creativeHumanOnly(old.document, actor, instance, next.roles[instance].definition);
|
||||
if (!exact(route, [...ROUTE_FIELDS, "fallback"]) || ROUTE_FIELDS.some(key => typeof route[key] !== "string")) {
|
||||
throw new OrganizationError("invalid-request");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import { basename, dirname, join } from "node:path";
|
||||
import { refuse } from "./errors.mjs";
|
||||
import {
|
||||
ACTIONS, GATED_ONLY, TOOLS, NETWORKS, SERVICES, HOST_SERVICE, GITEA_SCOPE_CATEGORIES, VIKUNJA_GRANTABLE,
|
||||
CREATIVE_DEFINITIONS, CREATIVE_TOOLS,
|
||||
} from "./vocabulary.mjs";
|
||||
import {
|
||||
requireObject, rejectUnknownKeys, requireId, requireString, requireDistinctList, readJsonFile, deepFreeze,
|
||||
@@ -137,25 +136,6 @@ function checkContract(contract, file) {
|
||||
return path;
|
||||
}
|
||||
|
||||
// Row 213 (C2-08, Case 2 design 4, M1): a creative role only reads and answers the human. Its file
|
||||
// may name no tool outside CREATIVE_TOOLS, no authority but message.send, and must carry a messaging
|
||||
// key that names only the human, so it can't relay through another role.
|
||||
function checkCreative(role) {
|
||||
const wider = role.tools.filter((tool) => !CREATIVE_TOOLS.includes(tool));
|
||||
if (wider.length > 0) refuse(`creative role ${role.name} may not name tools ${wider.join(", ")} (allowed: ${CREATIVE_TOOLS.join(", ")})`);
|
||||
const actions = [...role.authority.withinRole, ...role.authority.crossRole];
|
||||
if (role.authority.crossRole.length > 0 || actions.some((a) => a !== "message.send")) {
|
||||
refuse(`creative role ${role.name} may hold only withinRole message.send`);
|
||||
}
|
||||
if (role.messaging === null) refuse(`creative role ${role.name} requires "messaging"`);
|
||||
for (const key of ["sendTo", "receiveFrom"]) {
|
||||
if (role.messaging[key].some((entry) => entry !== "human")) {
|
||||
refuse(`creative role ${role.name} messaging.${key} may name only human`);
|
||||
}
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
// Validate a parsed role document read from `file`. Returns a frozen role:
|
||||
// { roleVersion, name, title, contract, contractPath, tools, network,
|
||||
// authority: { withinRole, crossRole }, credentials: [{ service, scopes }],
|
||||
@@ -169,7 +149,6 @@ export function validateRoleDocument(document, file) {
|
||||
if (document.name !== base) refuse(`role "name" (${document.name}) must match its filename (${base}.json)`);
|
||||
const tools = checkTools(document.tools);
|
||||
if (document.roleVersion === 1) {
|
||||
if (CREATIVE_DEFINITIONS.includes(document.name)) refuse(`creative role ${document.name} must be version 2`);
|
||||
const network = document.network === undefined ? "none" : checkNetwork(document.network);
|
||||
return deepFreeze({
|
||||
roleVersion: 1, name: document.name, title: null, contract: null, contractPath: null, tools, network,
|
||||
@@ -179,7 +158,7 @@ export function validateRoleDocument(document, file) {
|
||||
for (const key of V2_REQUIRED) {
|
||||
if (document[key] === undefined) refuse(`role version 2 requires "${key}"`);
|
||||
}
|
||||
const role = {
|
||||
return deepFreeze({
|
||||
roleVersion: 2,
|
||||
name: document.name,
|
||||
title: requireString(document.title, 'role "title"', { max: 80 }),
|
||||
@@ -191,8 +170,7 @@ export function validateRoleDocument(document, file) {
|
||||
credentials: checkCredentials(document.credentials),
|
||||
messaging: document.messaging === undefined ? null : checkMessaging(document.messaging),
|
||||
skills: document.skills === undefined ? [] : checkSkills(document.skills),
|
||||
};
|
||||
return deepFreeze(CREATIVE_DEFINITIONS.includes(role.name) ? checkCreative(role) : role);
|
||||
});
|
||||
}
|
||||
|
||||
export function loadRoleFile(file) {
|
||||
|
||||
@@ -145,18 +145,6 @@ export const REGISTRY = Object.freeze({
|
||||
"fallback.harness": def(["agent"], moduleName),
|
||||
"fallback.model": def(["agent"], string(200)),
|
||||
"fallback.thinking": def(["agent"], oneOf(THINKING)),
|
||||
// Row 213 (C2-08, Case 2 design 4): a creative instance's persona. The name the user sees, one line,
|
||||
// and the sha256 of <configDir>/personas/<business>/<instance>.md. The text stays out of the
|
||||
// business file; the bundle reads the file at launch and refuses it off this digest.
|
||||
"persona.name": def(["agent"], (v, key) => {
|
||||
requireString(v, `variable ${key}`, { max: 40 });
|
||||
if (/[\u0000-\u001f\u007f\u2028\u2029]/.test(v)) refuse(`variable ${key} must be one line with no control characters`);
|
||||
return v;
|
||||
}),
|
||||
"persona.sha256": def(["agent"], (v, key) => {
|
||||
if (typeof v !== "string" || !/^[0-9a-f]{64}$/.test(v)) refuse(`variable ${key} must be 64 lowercase hex characters`);
|
||||
return v;
|
||||
}),
|
||||
|
||||
// Limits narrow the role definition's ceilings. limits.authority is an
|
||||
// allowlist: a role action it doesn't name becomes gated.
|
||||
|
||||
@@ -170,29 +170,10 @@ export const ID_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
|
||||
// Row 121 (#1615): an instance of this definition talks with the user in threads (REQ-THREAD-1).
|
||||
// Row 155 (#1649) moves it here from the broker, so the organization writer reads the same name.
|
||||
export const THREAD_DEFINITION = "assistant";
|
||||
|
||||
// Row 213 (C2-08, #1714, Case 2 design 4): the creative roles. Each only reads and answers the human
|
||||
// in cited items; its instances are the human's alone (M10).
|
||||
export const CREATIVE_DEFINITIONS = Object.freeze(["companion", "ideas", "research", "proofreader", "fact-checker", "continuity"]);
|
||||
// The reply item kinds each creative definition may send (design 4, 5.2's reply-kind check).
|
||||
export const CREATIVE_KINDS = Object.freeze({
|
||||
companion: Object.freeze(["idea", "question", "finding", "fact"]),
|
||||
ideas: Object.freeze(["idea", "question"]),
|
||||
research: Object.freeze(["fact", "question"]),
|
||||
proofreader: Object.freeze(["correction", "question"]),
|
||||
"fact-checker": Object.freeze(["finding", "question"]),
|
||||
continuity: Object.freeze(["finding", "question"]),
|
||||
});
|
||||
// The only tools a creative role file may name (M1): reading, and the broker's web grant.
|
||||
export const CREATIVE_TOOLS = Object.freeze(["read", "grep", "find", "ls", "web"]);
|
||||
// The definitions that may hold a thread: the assistant and the creative roles. The definition the
|
||||
// chief of staff may set stays THREAD_DEFINITION.
|
||||
export const THREAD_DEFINITIONS = Object.freeze([THREAD_DEFINITION, ...CREATIVE_DEFINITIONS]);
|
||||
// Row 139 (#1633), Jason's ruling Q169 (PRD 1.6): definitions only the chief of staff, or a decision
|
||||
// the human resolved through the CLI, may end or revoke. Row 155 moves the list here, and no
|
||||
// organization write may give an instance one of them, except the human's instances.set for a
|
||||
// creative definition (row 213).
|
||||
export const END_PROTECTED = THREAD_DEFINITIONS;
|
||||
// organization write may give an instance one of them.
|
||||
export const END_PROTECTED = Object.freeze([THREAD_DEFINITION]);
|
||||
|
||||
// Row 199 (#1697, design D9c): the Gitea URL parse. It lives here because the broker reads it and
|
||||
// this file imports nothing. Gitea's name rule for users and repositories: letters, digits, "_", "."
|
||||
|
||||
@@ -159,11 +159,10 @@ test("the contract passes work to the chief of staff and directs no one", () =>
|
||||
assert.doesNotMatch(text, /to\s+the\s+role\s+it\s+concerns/);
|
||||
});
|
||||
|
||||
// Row 213 (C2-08, Case 2 design 4): companion and research hold it too, for the broker's web tools.
|
||||
test("REQ-HARN-2: the assistant, companion and research hold the web grant, and no other role file does", () => {
|
||||
test("REQ-HARN-2: the assistant holds the web grant, and no other role file does", () => {
|
||||
const names = readdirSync(REPO_ROLES).filter((f) => f.endsWith(".json") && f !== "conductor-policy.json").map((f) => f.slice(0, -5));
|
||||
const granted = names.filter((name) => loadRole(REPO_ROLES, name).tools.includes("web"));
|
||||
assert.deepEqual(granted, ["assistant", "companion", "research"]);
|
||||
assert.deepEqual(granted, ["assistant"]);
|
||||
for (const name of ["coder", "reviewer", "chief-of-staff", "pm", "cto", "researcher"]) {
|
||||
assert.ok(!loadRole(REPO_ROLES, name).tools.includes("web"), name);
|
||||
}
|
||||
|
||||
@@ -234,25 +234,3 @@ test("the shipped example refuses as written and validates once filled in", () =
|
||||
assert.equal(business.tracker.sync.credentials.vikunja.file, join(root, ".config/mosaic-dev/secrets/mosaic-stack/sync-vikunja.token"));
|
||||
assert.equal(id, 15);
|
||||
});
|
||||
|
||||
// Row 213 (C2-08, #1714), deviation D1: the persona vars sit on a creative instance only, and
|
||||
// both or neither. The var checks themselves are vars.mjs's.
|
||||
test("persona vars: agent layer, creative definition only, both or neither", () => {
|
||||
const sha = "a".repeat(64);
|
||||
const persona = { "persona.name": "Bean", "persona.sha256": sha };
|
||||
const business = check((d) => { d.roles.bean = { definition: "companion", vars: { ...persona } }; });
|
||||
assert.deepEqual({ ...business.roles.bean.vars }, persona);
|
||||
assert.doesNotThrow(() => check((d) => { d.roles.bean = { definition: "ideas" }; }));
|
||||
refuses(() => check((d) => { d.vars["persona.name"] = "Bean"; }), /persona\.name can't be set at the business layer/);
|
||||
refuses(() => check((d) => { d.roles.pm.vars = { ...d.roles.pm.vars, ...persona }; }),
|
||||
/roles\.pm\.vars: persona vars need a creative definition \(pm isn't one\)/);
|
||||
refuses(() => check((d) => { d.roles.chief.vars = { ...persona }; }), /chief-of-staff isn't one/);
|
||||
for (const key of Object.keys(persona)) {
|
||||
refuses(() => check((d) => { d.roles.bean = { definition: "research", vars: { [key]: persona[key] } }; }),
|
||||
/roles\.bean\.vars: persona\.name and persona\.sha256 are set together or not at all/);
|
||||
}
|
||||
for (const [key, value] of [["persona.name", "x".repeat(41)], ["persona.name", "Be\nan"], ["persona.name", "Be\u0007an"], ["persona.name", "Be\u2028an"], ["persona.name", "Be\u2029an"], ["persona.name", 7],
|
||||
["persona.sha256", "A".repeat(64)], ["persona.sha256", sha.slice(1)], ["persona.sha256", `${sha}0`]]) {
|
||||
refuses(() => check((d) => { d.roles.bean = { definition: "companion", vars: { ...persona, [key]: value } }; }), new RegExp(`variable ${key.replace(".", "\\.")}`), 2);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// Row 210 (#1707, design D3 and D6): the address checks and the argv allowlist. Row 234 (#1740, r6 S1)
|
||||
// moved the registry and the grants to bus store records, so the business file refuses them.
|
||||
// Row 210 (#1707, design D3 and D6): the host registry, an agent's host grant and its argv
|
||||
// allowlist, checked at business load. Tests T1, T2 and T26 of the design.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { BusinessError, validateBusinessDocument } from "../src/index.mjs";
|
||||
import { HOST_KEY as HOST_KEY_PATTERN, REFUSED_COMMANDS, USER, checkAddress, checkCommands, commandAllowed, ownMachine, validArgv } from "../src/hosts.mjs";
|
||||
import { businessDoc, rolesCopy, tmp, tokenFile, FAR_DATE } from "./helpers.mjs";
|
||||
import { resolveInstance } from "../src/resolve.mjs";
|
||||
import { REFUSED_COMMANDS, commandAllowed, ownMachine, validArgv } from "../src/hosts.mjs";
|
||||
import { businessDoc, rolesCopy, systemFor, tmp, tokenFile, FAR_DATE } from "./helpers.mjs";
|
||||
|
||||
const HOST_KEY = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOv6Rq3Mvo9w2j3eYvYbqX0J1pJ0x9m8Zr0w1kJ8p0Qn";
|
||||
|
||||
@@ -18,7 +19,8 @@ function refuses(fn, pattern) {
|
||||
});
|
||||
}
|
||||
|
||||
// The fixture with coder's definition declaring the host credential and no hosts.
|
||||
// The fixture with coder's definition declaring the host credential, one registered host, and
|
||||
// coder granted it with one command.
|
||||
function check(mutate, { declare = true } = {}) {
|
||||
const root = tmp();
|
||||
const rolesDir = rolesCopy(root);
|
||||
@@ -29,44 +31,62 @@ function check(mutate, { declare = true } = {}) {
|
||||
writeFileSync(file, JSON.stringify(coder));
|
||||
}
|
||||
const doc = businessDoc(root);
|
||||
doc.hosts = { web1: { address: "10.1.1.53", port: 22, user: "localadmin", hostKeys: [HOST_KEY] } };
|
||||
doc.roles.coder.hosts = { web1: { commands: [["systemctl", "status"]] } };
|
||||
doc.roles.coder.credentials["host.web1"] = { file: tokenFile(join(root, "secrets"), "coder-host.key"), rotateBy: FAR_DATE };
|
||||
mutate?.(doc, root);
|
||||
return validateBusinessDocument(doc, join(root, "businesses", "acme.json"), { rolesDir });
|
||||
}
|
||||
|
||||
// Row 234 (#1740, r6 S1): hosts and grants are bus store records, so the business file refuses both keys
|
||||
// and any host.<id> key reference. The control loads.
|
||||
test("S1: the business file refuses hosts at the top level and in a role, and host.<id> references", () => {
|
||||
assert.equal("hosts" in check(), false);
|
||||
assert.equal("hosts" in check().roles.coder, false);
|
||||
const entry = { address: "10.1.1.53", port: 22, user: "localadmin", hostKeys: [HOST_KEY] };
|
||||
refuses(() => check((d) => { d.hosts = { web1: entry }; }), /acme\.json hosts lives in the bus store/);
|
||||
refuses(() => check((d) => { d.hosts = {}; }), /hosts lives in the bus store/);
|
||||
refuses(() => check((d) => { d.roles.coder.hosts = { web1: { commands: [["systemctl", "status"]] } }; }), /roles\.coder\.hosts lives in the bus store/);
|
||||
refuses(() => check((d) => { d.roles.coder.hosts = {}; }, { declare: false }), /roles\.coder\.hosts lives in the bus store/);
|
||||
const key = (d, root) => { d.roles.coder.credentials["host.web1"] = { file: tokenFile(join(root, "secrets"), "coder-host.key"), rotateBy: FAR_DATE }; };
|
||||
refuses(() => check(key), /host\.web1/);
|
||||
test("T1: a registry and a grant load, and the resolved session credentials leave the host key out", () => {
|
||||
const business = check();
|
||||
assert.deepEqual(business.hosts.web1, { address: "10.1.1.53", port: 22, user: "localadmin", hostKeys: [HOST_KEY] });
|
||||
assert.deepEqual(business.roles.coder.hosts, { web1: { commands: [["systemctl", "status"]] } });
|
||||
assert.ok(business.roles.coder.credentials["host.web1"]);
|
||||
assert.equal(check((d) => { d.hosts.web1.address = "host.example"; }).hosts.web1.address, "host.example");
|
||||
// A file without hosts loads with no hosts key at all.
|
||||
assert.equal("hosts" in check((d) => { delete d.hosts; delete d.roles.coder.hosts; delete d.roles.coder.credentials["host.web1"]; }), false);
|
||||
});
|
||||
|
||||
test("T1: address, user and host key checks, which the enrollment raise uses", () => {
|
||||
test("T1: registry field checks name the key path", () => {
|
||||
refuses(() => check((d) => { d.hosts = []; }), /hosts/);
|
||||
refuses(() => check((d) => { d.hosts = { "Web 1": d.hosts.web1 }; }), /host id/);
|
||||
refuses(() => check((d) => { d.hosts.web1.extra = 1; }), /hosts\.web1/);
|
||||
for (const port of [0, 65536, "22", 1.5]) refuses(() => check((d) => { d.hosts.web1.port = port; }), /hosts\.web1\.port/);
|
||||
for (const user of ["Root", "a b", "", 7]) refuses(() => check((d) => { d.hosts.web1.user = user; }), /hosts\.web1\.user/);
|
||||
refuses(() => check((d) => { d.hosts.web1.hostKeys = []; }), /hosts\.web1\.hostKeys/);
|
||||
refuses(() => check((d) => { d.hosts.web1.hostKeys = [`${HOST_KEY} root@web1`]; }), /hosts\.web1\.hostKeys\[0\]/);
|
||||
refuses(() => check((d) => { d.hosts.web1.hostKeys = ["ssh-dss AAAA"]; }), /hosts\.web1\.hostKeys\[0\]/);
|
||||
refuses(() => check((d) => { d.hosts.web1.hostKeys = [HOST_KEY, HOST_KEY]; }), /twice/);
|
||||
for (const address of ["bad_name", "a..b", "-a.b", "fe80::1%eth0", 7])
|
||||
refuses(() => check((d) => { d.hosts.web1.address = address; }), /hosts\.web1\.address/);
|
||||
});
|
||||
|
||||
test("T1: every own-machine form refuses, and the controls load", () => {
|
||||
const own = ["127.0.0.2", "0.0.0.0", "::1", "::", "0:0:0:0:0:0:0:1", "::ffff:127.0.0.1", "::ffff:0.0.0.0", "localhost", "a.localhost",
|
||||
"127.1", "2130706433", "0177.0.0.1", "0x7f.1", "bad_name", "a..b", "-a.b", "fe80::1%eth0", 7];
|
||||
for (const address of own) refuses(() => checkAddress(address, "grant.address"), /grant\.address/);
|
||||
for (const address of ["10.1.1.53", "host.example", "2001:db8::1"]) assert.equal(checkAddress(address, "grant.address"), address);
|
||||
"127.1", "2130706433", "0177.0.0.1", "0x7f.1"];
|
||||
for (const address of own) refuses(() => check((d) => { d.hosts.web1.address = address; }), /hosts\.web1\.address/);
|
||||
for (const address of ["10.1.1.53", "host.example", "2001:db8::1"]) assert.equal(check((d) => { d.hosts.web1.address = address; }).hosts.web1.address, address);
|
||||
assert.equal(ownMachine("::ffff:7f00:1"), true);
|
||||
assert.equal(ownMachine("::ffff:10.0.0.1"), false);
|
||||
for (const user of ["Root", "a b", ""]) assert.equal(USER.test(user), false);
|
||||
assert.equal(USER.test("localadmin"), true);
|
||||
for (const key of [`${HOST_KEY} root@web1`, "ssh-dss AAAA"]) assert.equal(HOST_KEY_PATTERN.test(key), false);
|
||||
assert.equal(HOST_KEY_PATTERN.test(HOST_KEY), true);
|
||||
});
|
||||
|
||||
test("T2: a grant naming an unknown host, or on a definition without host, refuses at roles.<agent>.hosts", () => {
|
||||
refuses(() => check((d) => { d.roles.coder.hosts = { web2: { commands: [["ls"]] } }; }), /roles\.coder\.hosts\.web2: host web2 isn't/);
|
||||
refuses(() => check(null, { declare: false }), /roles\.coder\.hosts needs a role definition that declares the host credential/);
|
||||
refuses(() => check((d) => { d.roles.coder.hosts = {}; }), /roles\.coder\.hosts must name at least one host/);
|
||||
refuses(() => check((d) => { d.roles.coder.hosts.web1.extra = 1; }), /roles\.coder\.hosts\.web1/);
|
||||
// The key reference is for a granted host only.
|
||||
refuses(() => check((d) => { d.roles.coder.credentials["host.web2"] = d.roles.coder.credentials["host.web1"]; }), /host\.web2/);
|
||||
});
|
||||
|
||||
test("T26: no wildcard and no shell, runner or interpreter as a prefix", () => {
|
||||
const at = /grant\.commands/;
|
||||
const at = /roles\.coder\.hosts\.web1\.commands/;
|
||||
for (const commands of ["any", "*", {}, [], [[]], [[7]], [["ls", ""]], [["ls"], ["ls"]], [["ls", "*"]], [["ls", "a?"]], [["ls", "[a]"]], [["bin/ls"]], [["ls\0"]]])
|
||||
refuses(() => checkCommands(commands, "grant.commands"), at);
|
||||
refuses(() => check((d) => { d.roles.coder.hosts.web1.commands = commands; }), at);
|
||||
const names = [...REFUSED_COMMANDS, "python", "python3", "python3.12", "awk", "gawk", "mawk", "nawk", "php", "php8.2", "/bin/bash", "/usr/bin/env"];
|
||||
for (const name of names) refuses(() => checkCommands([[name, "x"]], "grant.commands"), at);
|
||||
for (const name of ["systemctl", "/usr/bin/journalctl", "tee"]) assert.deepEqual(checkCommands([[name]], "grant.commands"), [[name]]);
|
||||
for (const name of names) refuses(() => check((d) => { d.roles.coder.hosts.web1.commands = [[name, "x"]]; }), at);
|
||||
for (const name of ["systemctl", "/usr/bin/journalctl", "tee"]) assert.ok(check((d) => { d.roles.coder.hosts.web1.commands = [[name]]; }));
|
||||
});
|
||||
|
||||
test("D6: argv shape and the literal prefix match", () => {
|
||||
@@ -81,3 +101,11 @@ test("D6: argv shape and the literal prefix match", () => {
|
||||
assert.equal(commandAllowed(["systemctl", "restart", "nginx"], commands), false);
|
||||
assert.equal(commandAllowed(["systemctl", "status*"], commands), false);
|
||||
});
|
||||
|
||||
test("D5: resolveInstance leaves host.<id> out of the session's credentials", () => {
|
||||
let root;
|
||||
const business = check((d, r) => { root = r; });
|
||||
const resolved = resolveInstance({ system: systemFor(root), business, instance: "coder" });
|
||||
assert.equal("host.web1" in resolved.credentials, false);
|
||||
assert.ok(resolved.credentials.gitea);
|
||||
});
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
import test, { after } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
||||
import { readFileSync, rmSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { instanceSettings } from "../src/instance-settings.mjs";
|
||||
import { projectFilePath } from "../src/project.mjs";
|
||||
@@ -215,52 +214,3 @@ test("row 65 an instance write refuses harness-off, thinking-unsupported, an unk
|
||||
const h = fixture(doc => harnessOn(doc, ["pi", "fixture"]), { levels: name => LEVELS[name] ?? null });
|
||||
refuses(h, { instance: "coder", op: "change", vars: { harness: "fixture", thinking: "high" } }, "harness-refused");
|
||||
});
|
||||
|
||||
// Row 213 (C2-08, #1714, M10): the human adds and changes a creative instance here, its persona
|
||||
// vars included; the chief of staff and the tester are refused. The persona text never enters the
|
||||
// business file, a read or the change log: the vars hold only its name and digest.
|
||||
test("row 213 a creative instance is the human's: add, vars and definition changes, persona digest only", () => {
|
||||
const f = fixture(doc => { doc.roles["sec-1"] = { definition: "security-reviewer" }; });
|
||||
const marker = "PERSONA-MARKER-7f3a";
|
||||
const text = `Warm and brief. ${marker}\n`;
|
||||
mkdirSync(join(f.root, "config", "personas", "acme"), { recursive: true, mode: 0o700 });
|
||||
writeFileSync(join(f.root, "config", "personas", "acme", "bean.md"), text, { mode: 0o600 });
|
||||
const persona = { "persona.name": "Bean", "persona.sha256": createHash("sha256").update(text).digest("hex") };
|
||||
const view = f.settings.read("acme");
|
||||
assert.deepEqual(view.definitions.companion, { services: [], accepted: true });
|
||||
const add = { instance: "bean", op: "add", definition: "companion", vars: persona };
|
||||
for (const actor of ["chief-of-staff.chief", "tester"]) {
|
||||
assert.throws(() => f.settings.set("acme", { revision: view.revision, ...add }, actor), e => e.code === "organization-creative-human-only", actor);
|
||||
assert.throws(() => f.settings.set("acme", { revision: view.revision, instance: "sec-1", op: "change", definition: "ideas" }, actor),
|
||||
e => e.code === "organization-creative-human-only", `${actor} redefine`);
|
||||
}
|
||||
let done = f.settings.set("acme", { revision: view.revision, ...add }, "jason");
|
||||
assert.deepEqual(done.instances.bean, { definition: "companion", vars: persona, launched: false, launcher: false, protected: false });
|
||||
for (const actor of ["chief-of-staff.chief", "tester"]) {
|
||||
for (const change of [{ vars: {} }, { launch: true }, { definition: "security-reviewer" }]) {
|
||||
assert.throws(() => f.settings.set("acme", { revision: done.revision, instance: "bean", op: "change", ...change }, actor),
|
||||
e => e.code === "organization-creative-human-only", `${actor} ${JSON.stringify(change)}`);
|
||||
}
|
||||
}
|
||||
done = f.settings.set("acme", { revision: done.revision, instance: "bean", op: "change", definition: "ideas", vars: { ...persona, "persona.name": "Bean Two" } }, "jason");
|
||||
assert.equal(done.instances.bean.definition, "ideas");
|
||||
assert.equal(done.restart, true);
|
||||
// A persona var on a definition that isn't creative is refused by the validator (D1).
|
||||
refuses(f, { instance: "bean", op: "change", definition: "security-reviewer" }, "BusinessError");
|
||||
assert.equal(f.validate().status, 0);
|
||||
assert.deepEqual(f.log().filter(e => e.state === "committed").map(e => e.actor), ["jason", "jason"]);
|
||||
for (const out of [JSON.stringify(f.settings.read("acme")), readFileSync(f.settings.writer.logFile("acme"), "utf8"), readFileSync(f.file, "utf8")]) {
|
||||
assert.ok(!out.includes(marker));
|
||||
}
|
||||
// The writer's modes hold for the new file and its history.
|
||||
assert.equal(statSync(f.file).mode & 0o777, 0o600);
|
||||
// changes.jsonl sits in the history dir; the loop below covers it too, but the brief names it.
|
||||
assert.equal(statSync(f.settings.writer.logFile("acme")).mode & 0o777, 0o600);
|
||||
const history = join(f.root, "config", "businesses", ".history", "acme");
|
||||
assert.ok(readdirSync(history).includes("changes.jsonl"));
|
||||
assert.equal(statSync(history).mode & 0o777, 0o700);
|
||||
for (const name of readdirSync(history)) {
|
||||
const st = statSync(join(history, name));
|
||||
assert.equal(st.mode & 0o777, st.isDirectory() ? 0o700 : 0o600, name);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -142,32 +142,3 @@ test('row 65 a file with harness vars and no plugins.harness loads and its views
|
||||
const moved=settings.set('acme',{revision:view.revision,instances:{coder:'opus'}},'jason');assert.equal(moved.instances.coder.modelKey,'opus');
|
||||
assert.throws(()=>settings.setRoutes('acme',{revision:moved.revision,routes:{coder:{harness:'pi',model:'opus',thinking:'low',fallback:null}}},'jason'),code('harness-off'));
|
||||
});
|
||||
// Row 213 (C2-08, #1714, M10): a creative instance is the human's. The chief of staff (and the tester)
|
||||
// can't reach its model through the models table, the instances key or a route; the human can,
|
||||
// except through the instances key, which refuses a creative instance for everyone.
|
||||
test('M10 creative instance: models keys it names, the instances key and its route are the human\'s',async()=>{
|
||||
const f=fixture();const doc=structuredClone(f.doc);doc.roles.bean={definition:'companion',vars:{model:'sonnet'}};writeJson(f.file,doc);
|
||||
const g={...f,doc};const {settings}=await routeSettings(g);const file=()=>readFileSync(f.file,'utf8');
|
||||
const chief='chief-of-staff.chief';let {revision}=settings.read('acme');
|
||||
const models=structuredClone(settings.read('acme').models);
|
||||
const sonnet={...models,sonnet:{provider:'proxy',model:'claude-sonnet-5-5'}};
|
||||
for(const actor of [chief,'tester']){
|
||||
const bytes=file();
|
||||
assert.throws(()=>settings.set('acme',{revision,models:sonnet},actor),code('organization-creative-human-only'),actor);
|
||||
const {sonnet:_,...gone}=models;assert.throws(()=>settings.set('acme',{revision,models:gone},actor),code('organization-creative-human-only'),`${actor} removal`);
|
||||
assert.throws(()=>settings.set('acme',{revision,instances:{bean:'opus'}},actor),code('organization-creative-instance'),actor);
|
||||
assert.throws(()=>settings.setRoutes('acme',{revision,routes:{bean:{harness:'pi',model:'opus',thinking:'high',fallback:null}}},actor),code('organization-creative-human-only'),actor);
|
||||
assert.equal(file(),bytes,actor);
|
||||
}
|
||||
// A key no creative instance names stays the chief's.
|
||||
({revision}=settings.set('acme',{revision,models:{...models,opus:{provider:'proxy',model:'claude-opus-5-5'}}},chief));
|
||||
assert.throws(()=>settings.set('acme',{revision,instances:{bean:'opus'}},'jason'),code('organization-creative-instance'));
|
||||
({revision}=settings.set('acme',{revision,models:sonnet},'jason'));
|
||||
({revision}=settings.setRoutes('acme',{revision,routes:{bean:{harness:'pi',model:'sonnet',thinking:'high',fallback:{harness:'pi',model:'opus',thinking:'low'}}}},'jason'));
|
||||
assert.equal(JSON.parse(file()).roles.bean.vars['fallback.model'],'opus');
|
||||
// Now bean names opus as its fallback, so opus is the human's too.
|
||||
const opus=structuredClone(settings.read('acme').models);opus.opus.provider='proxy-next';
|
||||
assert.throws(()=>settings.set('acme',{revision,models:opus},chief),code('organization-creative-human-only'));
|
||||
settings.set('acme',{revision,models:opus},'jason');
|
||||
const e=JSON.parse(readFileSync(settings.writer.logFile('acme'),'utf8').trim().split('\n').at(-1));assert.equal(e.actor,'jason');
|
||||
});
|
||||
|
||||
@@ -215,43 +215,3 @@ test("contract: a non-empty regular Markdown file beside the role file", () => {
|
||||
symlinkSync("r.md", join(dir, "link.md"));
|
||||
refuses(() => validateRoleDocument(doc, file), /non-empty regular file/);
|
||||
});
|
||||
|
||||
// Row 213 (C2-08, #1714, M1): a creative role reads and answers the human, and nothing else.
|
||||
const CREATIVE = { companion: ["read", "web"], ideas: ["read"], research: ["read", "web"], proofreader: ["read"], "fact-checker": ["read"], continuity: ["read"] };
|
||||
|
||||
test("the six creative roles load: read tools, message.send only, messaging with the human only", () => {
|
||||
for (const [name, tools] of Object.entries(CREATIVE)) {
|
||||
const role = loadRole(REPO_ROLES, name);
|
||||
assert.equal(role.roleVersion, 2, name);
|
||||
assert.deepEqual(role.tools, tools, name);
|
||||
assert.equal(role.network, tools.includes("web") ? "api-only" : "none", name);
|
||||
assert.deepEqual(role.authority, { withinRole: ["message.send"], crossRole: [] }, name);
|
||||
assert.deepEqual(role.credentials, [], name);
|
||||
assert.deepEqual(role.messaging, { sendTo: ["human"], receiveFrom: ["human"] }, name);
|
||||
}
|
||||
});
|
||||
|
||||
test("M1: a creative role file wider than read and answer is refused", () => {
|
||||
const creative = (name, overrides) => {
|
||||
const dir = tmp();
|
||||
writeFileSync(join(dir, `${name}.md`), "# contract\n");
|
||||
const doc = {
|
||||
roleVersion: 2, name, title: "C", contract: `${name}.md`, tools: ["read"], network: "none",
|
||||
authority: { withinRole: ["message.send"], crossRole: [] }, credentials: [],
|
||||
messaging: { sendTo: ["human"], receiveFrom: ["human"] }, ...overrides,
|
||||
};
|
||||
// An override of undefined drops the key.
|
||||
for (const key of Object.keys(doc)) if (doc[key] === undefined) delete doc[key];
|
||||
return () => validateRoleDocument(doc, join(dir, `${name}.json`));
|
||||
};
|
||||
assert.doesNotThrow(creative("ideas", { tools: ["read", "grep", "find", "ls", "web"] }));
|
||||
for (const tool of ["write", "edit", "bash"]) {
|
||||
refuses(creative("ideas", { tools: ["read", tool] }), new RegExp(`^creative role ideas may not name tools ${tool} `));
|
||||
}
|
||||
refuses(creative("proofreader", { authority: { withinRole: ["message.send", "record.write"], crossRole: [] } }), /^creative role proofreader may hold only withinRole message.send$/);
|
||||
refuses(creative("proofreader", { authority: { withinRole: [], crossRole: ["message.send"] } }), /^creative role proofreader may hold only withinRole message.send$/);
|
||||
refuses(creative("continuity", { messaging: undefined }), /^creative role continuity requires "messaging"$/);
|
||||
refuses(creative("research", { messaging: { sendTo: ["human", "pm"], receiveFrom: ["human"] } }), /^creative role research messaging.sendTo may name only human$/);
|
||||
refuses(creative("research", { messaging: { sendTo: ["human"], receiveFrom: ["assistant"] } }), /^creative role research messaging.receiveFrom may name only human$/);
|
||||
refuses(creative("companion", { roleVersion: 1, title: undefined, contract: undefined, authority: undefined, credentials: undefined, messaging: undefined }), /^creative role companion must be version 2$/);
|
||||
});
|
||||
|
||||
+7
-22
@@ -432,11 +432,9 @@ A Claude Code session logs in with `CLAUDE_CODE_OAUTH_TOKEN`,
|
||||
on. The bus unit loads it ("Unit" below). Nothing from the host's
|
||||
`~/.claude` reaches a session, whose `HOME` is its own. With none of them
|
||||
set, a Claude Code launch refuses `no-session-credential` before anything
|
||||
starts. A Pi session gets the same variables through the allowlist. A Pi
|
||||
session on provider `zai` logs in with `ZAI_API_KEY`, which the allowlist
|
||||
passes. Like every allowlist variable, it reaches every session the host
|
||||
starts, Claude Code ones included. A shell the harness opens, Claude Code's
|
||||
`Bash` or Pi's `bash`, can read all of these variables.
|
||||
starts. A Pi session gets the same variables through the allowlist. A
|
||||
shell the harness opens, Claude Code's `Bash` or Pi's `bash`, can read
|
||||
them.
|
||||
|
||||
A Pi session logs in only through the variables `ENV_ALLOW` passes. Its
|
||||
`HOME` is the run's own, so Pi never reads the operator's `~/.pi/agent`
|
||||
@@ -708,14 +706,13 @@ instead and sessions run `claude` from the unit's `PATH`, which in the
|
||||
sandbox finds only a `claude` under `/usr`. A running host
|
||||
keeps the environment it started with until it restarts.
|
||||
|
||||
The session credentials come from
|
||||
The session credential comes from
|
||||
`EnvironmentFile=-%h/.config/mosaic-dev/secrets/claude-session.env`, the
|
||||
one place the path is set. The file holds one line per variable, for
|
||||
example `CLAUDE_CODE_OAUTH_TOKEN=<token>`, mode 0600. It holds every session
|
||||
provider key, not only Claude's. The operator writes it;
|
||||
one place the path is set. The file holds one line, for example
|
||||
`CLAUDE_CODE_OAUTH_TOKEN=<token>`, mode 0600. The operator writes it;
|
||||
nothing in the repository creates it, and only the Case 2 precheck reads
|
||||
it, printing variable names, never values. No session sees the file
|
||||
itself, only the variables. The leading `-` lets the unit start
|
||||
itself, only the variable. The leading `-` lets the unit start
|
||||
without it, so Pi sessions still launch and a Claude Code launch refuses
|
||||
`no-session-credential`. To change the credential, edit or swap the file
|
||||
(or this line and this paragraph), then restart the unit; a running host
|
||||
@@ -1049,18 +1046,6 @@ entries; `delete` refuses `agent-running` while the agent holds a claim. With
|
||||
`--tester` only `status` and `revoke` run. After a rotate or revoke, delete
|
||||
the old token in Gitea or Vikunja yourself; the bus only forgets it.
|
||||
|
||||
## hosts (row 234)
|
||||
|
||||
`mosaic hosts [status] [--json] [--tester] [--business ID]` prints one tab-separated line per
|
||||
enrolled host: id, state, `user@address:port`, `sudo` or `no-sudo`, the last check time or
|
||||
`unchecked`, and any host lines a failed step left. `--json` prints the bus rows. `check HOST`
|
||||
runs the bus's `hosts.check` and `remove HOST` its `hosts.remove`, each printing the JSON result.
|
||||
`revoke AGENT HOST --reason R` runs `hosts.revoke`, which takes the agent's grant on the host away
|
||||
at once, and `sweep HOST` runs `hosts.sweep`, which removes the host lines a failure left (row 235).
|
||||
A status line shows `revoking:` with the tags of a revoke still in progress.
|
||||
Enrollment itself is a `host-enroll` grant the chief raises and the human approves, not a CLI
|
||||
command. A usage error exits 4 and a bus refusal 2.
|
||||
|
||||
## Token usage
|
||||
|
||||
`mosaic usage [--business ID] [--json] [--tester]` reads the bus's accounting, without
|
||||
|
||||
@@ -18,7 +18,6 @@ import { resolveThread, threadCommand, threadMembers, threadsCommand, THREAD_TAL
|
||||
import { limitsCommand, LIMITS_USAGE } from "./limits.mjs";
|
||||
import { pluginsCommand, PLUGINS_USAGE } from "./plugins.mjs";
|
||||
import { credentialsCommand, CREDENTIALS_USAGE } from "./credentials.mjs";
|
||||
import { hostsCommand, HOSTS_USAGE } from "./hosts.mjs";
|
||||
import { instancesCommand, INSTANCES_USAGE } from "./instances.mjs";
|
||||
import { createChannelCaller } from "../../plugins/src/channel.mjs";
|
||||
import { PluginError } from "../../plugins/src/kinds.mjs";
|
||||
@@ -41,7 +40,6 @@ export const USAGE = `usage:
|
||||
${LIMITS_USAGE}
|
||||
${PLUGINS_USAGE}
|
||||
${CREDENTIALS_USAGE}
|
||||
${HOSTS_USAGE}
|
||||
${INSTANCES_USAGE}
|
||||
${PROJECT_USAGE}
|
||||
${PROJECT_BUS_USAGE}
|
||||
@@ -582,8 +580,6 @@ export async function main(argv, io = { env: process.env, stdin: process.stdin,
|
||||
if (verb === "plugins") return pluginsCommand(rest, io, (p) => callFor(p, io, deps));
|
||||
// Row 199 (#1697): issue and rotate read the token on stdin.
|
||||
if (verb === "credentials") return credentialsCommand(rest, io, (p) => callFor(p, io, deps));
|
||||
// Row 234 (#1740, r6 E4): the host records.
|
||||
if (verb === "hosts") return hostsCommand(rest, io, (p) => callFor(p, io, deps));
|
||||
// Row 165 (#1662): scripts/mosaic sends only `business instances` and `business instance` here.
|
||||
if (verb === "business") return instancesCommand(rest, io, (p) => callFor(p, io, deps));
|
||||
if (verb === "talk") return talk(rest, io, deps);
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// `mosaic hosts` (row 234, #1740, r6 E4): the broker's hosts.status, hosts.check and hosts.remove. The
|
||||
// human runs all three. With --tester the tester's session runs them. check logs in as mosaic-installer
|
||||
// and runs `list` on the host, then marks the host ready. remove drops a host no grant uses. Nothing here
|
||||
// reads a key: the answers carry fingerprints only. Row 235 (#1741, r6 section 6, X3) adds revoke, which
|
||||
// takes an agent's grant on a host away at once, and sweep, which removes the lines a failure left.
|
||||
import { CliError } from "./errors.mjs";
|
||||
|
||||
export const HOSTS_USAGE =
|
||||
"mosaic hosts [status] [--json] [--tester] [--business ID] | check|remove|sweep HOST [--tester] [--business ID] | revoke AGENT HOST --reason R [--tester] [--business ID]";
|
||||
|
||||
function parse(args) {
|
||||
const out = { positional: [], flags: new Set(), values: {} };
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg === "--json" || arg === "--tester") out.flags.add(arg);
|
||||
else if (arg === "--business" || arg === "--reason") {
|
||||
if (!args[i + 1] || Object.hasOwn(out.values, arg)) throw new CliError(HOSTS_USAGE, 4);
|
||||
out.values[arg] = args[++i];
|
||||
} else if (arg.startsWith("--")) throw new CliError(HOSTS_USAGE, 4);
|
||||
else out.positional.push(arg);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const line = (h) =>
|
||||
[h.host, h.state, `${h.user}@${h.address}:${h.port}`, h.sudo ? "sudo" : "no-sudo", h.checkedAt ?? "unchecked",
|
||||
...(h.hostLineLeft.length ? [`line left: ${h.hostLineLeft.join(" ")}`] : []),
|
||||
...(h.revoking?.length ? [`revoking: ${h.revoking.join(" ")}`] : [])].join("\t");
|
||||
|
||||
export async function hostsCommand(args, io, callFor) {
|
||||
const parsed = parse(args);
|
||||
const [verb = "status", first, second, ...extra] = parsed.positional;
|
||||
const one = first !== undefined && second === undefined;
|
||||
const shape = { status: first === undefined, check: one, remove: one, sweep: one, revoke: second !== undefined };
|
||||
// N10: own keys only, so `constructor` or `toString` is a usage error, not a verb.
|
||||
if (extra.length || !Object.hasOwn(shape, verb) || !shape[verb] || (parsed.flags.has("--json") && verb !== "status") ||
|
||||
(verb === "revoke") !== Object.hasOwn(parsed.values, "--reason"))
|
||||
throw new CliError(HOSTS_USAGE, 4);
|
||||
try {
|
||||
const call = callFor(parsed);
|
||||
if (verb === "status") {
|
||||
const rows = await call("hosts.status", {});
|
||||
io.stdout.write(parsed.flags.has("--json") ? JSON.stringify(rows, null, 2) + "\n" : rows.map(line).join("\n") + (rows.length ? "\n" : ""));
|
||||
return;
|
||||
}
|
||||
const args = verb === "revoke" ? { agent: first, host: second, reason: parsed.values["--reason"] } : { host: first };
|
||||
io.stdout.write(JSON.stringify(await call(`hosts.${verb}`, args), null, 2) + "\n");
|
||||
} catch (error) {
|
||||
if (error instanceof CliError) throw error;
|
||||
throw new CliError(error.message, 2);
|
||||
}
|
||||
}
|
||||
@@ -391,7 +391,6 @@ export function createLauncher({
|
||||
harnessVersion: version,
|
||||
land,
|
||||
skillsDir,
|
||||
personaDir: join(configDir(env), "personas"),
|
||||
});
|
||||
const { manifest, ...files } = bundle.files;
|
||||
const adapter = call(model.harness, "adapter", () => harness.adapter());
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# Mosaic Case 1 host check at boot (row 240, #1746; r6 B2). Root installs it as
|
||||
# /etc/systemd/system/mosaic-hostcheck.service, root:root 0644, and enables it
|
||||
# (docs/guides/host-run-sheet.md). It runs the drift stop before the bus starts, which covers a kernel
|
||||
# or parser change that takes effect at boot. --enforce always exits 0; on drift it closes bwrap to
|
||||
# root, and every role session then refuses to start.
|
||||
[Unit]
|
||||
Description=Mosaic Case 1 host check: the bwrap profile, the statoverride and the sysctls
|
||||
After=apparmor.service
|
||||
Before=[email protected]
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/lib/mosaic-stack/hostcheck.sh --enforce
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -1,487 +0,0 @@
|
||||
// Row 195 (#1693): scripts/case1-accept.sh, root's acceptance run on the Case 1 host. Design r7 section 5
|
||||
// (agents/darkwing/work/queue-195/DESIGN.md); deviations in agents/darkwing/work/queue-195/BUILD.md.
|
||||
// Every case runs the script with --root on a scratch host tree: /etc, /proc, /srv/mosaic, /opt and the
|
||||
// host check live under it. Fake systemctl, curl, ss, sudo and stat on PATH record their argv; the fake
|
||||
// sudo runs the stack's user's commands from the tree. Nothing here reads or writes the real /etc,
|
||||
// /proc or /srv, and the stand-in credential is not a credential.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { tmp } from "./helpers.mjs";
|
||||
|
||||
const REPO = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
const SCRIPT = join(REPO, "scripts", "case1-accept.sh");
|
||||
const COPY = "0123456789abcdef0123456789abcdef01234567";
|
||||
const NODE_PIN = "v24.1.0", CLAUDE_PIN = "2.1.0";
|
||||
const NODE = `/opt/mosaic-stack/node-${NODE_PIN}/bin/node`;
|
||||
const CLAUDE = `/opt/mosaic-stack/claude-${CLAUDE_PIN}/node_modules/@anthropic-ai/claude-code/bin/claude.exe`;
|
||||
const HOME = "/srv/mosaic";
|
||||
const CLI = `${HOME}/.local/share/mosaic-stack/copies/${COPY}/scripts/mosaic`;
|
||||
const PRECHECK = `${HOME}/.local/share/mosaic-stack/copies/${COPY}/scripts/case2-precheck.sh`;
|
||||
const CRED = `${HOME}/.config/mosaic-dev/secrets/claude-session.env`;
|
||||
const CRED_VALUE = "stand-in-not-a-credential-7f3e2a";
|
||||
const AS_MOSAIC = `-u mosaic -H env PATH=/opt/mosaic-stack/node-${NODE_PIN}/bin:/usr/local/bin:/usr/bin:/bin`;
|
||||
const ARGS = ["--profile", "factory", "--user", "mosaic", "--home", HOME, "--business", "mosaic-stack", "--copy", COPY,
|
||||
"--node", NODE, "--claude", CLAUDE, "--pm", "--", "--port", "732", "--business", "mosaic-stack", "--tester-port", "7333"];
|
||||
const OUTER = "bwrap (enforce)", CHILD = "bwrap//&unpriv_bwrap (enforce)";
|
||||
const MARKS = ["pass", "FAIL", "closed", "accepted Q182+Q183", "accepted Q183", "accepted mos-1096", "accepted mos-1101", "unnamed"];
|
||||
const P_PASS = { P1: "closed", P2: "closed", P3: "accepted Q183", P4: "accepted Q182+Q183", P5: "closed", P6: "closed",
|
||||
P7: "closed", P8: "closed", P9: "accepted mos-1096", P10: "accepted mos-1101", P11: "closed" };
|
||||
const PASSWD = "root:x:0:0:root:/root:/bin/bash\nmosaic:x:997:997::/srv/mosaic:/usr/sbin/nologin\nlocaladmin:x:1000:1000::/home/localadmin:/bin/bash\njarvis:x:1001:1001::/home/jarvis:/bin/bash\n";
|
||||
const GROUP = "root:x:0:\nsudo:x:27:localadmin\nmosaic:x:997:\nlxd:x:998:\ndocker:x:999:\nlocaladmin:x:1000:\njarvis:x:1001:\n";
|
||||
const SS = "LISTEN 0 511 127.0.0.1:732 0.0.0.0:* users:((\"node\",pid=200,fd=21))\n"
|
||||
+ "LISTEN 0 511 127.0.0.1:7333 0.0.0.0:* users:((\"node\",pid=200,fd=22))\n"
|
||||
+ "LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:((\"sshd\",pid=900,fd=3))\n";
|
||||
const HOSTCHECK_OK = [1, 2, 3, 4, 5, 6, 7].map((n) => `ok ${n} item ${n} holds`).join("\n") + "\nnote bubblewrap 0.9.0 is the install pin\n";
|
||||
|
||||
function put(file, text, mode) {
|
||||
mkdirSync(dirname(file), { recursive: true });
|
||||
writeFileSync(file, text);
|
||||
if (mode) chmodSync(file, mode);
|
||||
}
|
||||
const edit = (file, f) => writeFileSync(file, f(readFileSync(file, "utf8")));
|
||||
const log = (name) => `printf '%s' ${JSON.stringify(name)} >> "$HC/calls.log"; printf ' %s' "$@" >> "$HC/calls.log"; echo >> "$HC/calls.log"`;
|
||||
|
||||
// Fakes on PATH. Each records its argv and answers from a file in the state directory.
|
||||
const FAKES = {
|
||||
systemctl: `case "$1" in
|
||||
show) [ -f "$HC/show-$2" ] && cat "$HC/show-$2" ;;
|
||||
is-enabled) cat "$HC/enabled-$2" 2>/dev/null || { echo disabled; exit 1; } ;;
|
||||
esac`,
|
||||
curl: `exit "$(cat "$HC/curl-rc")"`,
|
||||
ss: `cat "$HC/ss"`,
|
||||
// The credential and the settings file answer from the state directory, as root would see them, and
|
||||
// only those calls are recorded; everything else is the real stat, which reads the args file.
|
||||
stat: `case "\${@: -1}" in
|
||||
*claude-session.env) ${log("stat")}; cat "$HC/stat-cred" ;;
|
||||
*managed-settings.json) ${log("stat")}; cat "$HC/stat-settings" ;;
|
||||
*) exec /usr/bin/stat "$@" ;;
|
||||
esac`,
|
||||
// -l -U USER prints the state file; -u jarvis is the bwrap probe; -u mosaic -H env PATH=... CMD runs
|
||||
// CMD from the tree, with the PATH entries and each absolute argument that exists there moved under it.
|
||||
sudo: `case "$1" in
|
||||
-l) [ -f "$HC/sudo-l-$3" ] && cat "$HC/sudo-l-$3"; exit 0 ;;
|
||||
-u) ;;
|
||||
*) exit 97 ;;
|
||||
esac
|
||||
user="$2"; shift 2
|
||||
if [ "$user" = jarvis ]; then cat "$HC/jarvis-bwrap" >&2; exit "$(cat "$HC/jarvis-bwrap-rc")"; fi
|
||||
[ "$user" = mosaic ] && [ "$1" = -H ] && [ "$2" = env ] && [[ "$3" == PATH=* ]] || exit 98
|
||||
p="\${3#PATH=}"; shift 3
|
||||
np=""; IFS=: read -ra parts <<< "$p"; for x in "\${parts[@]}"; do np+="$ROOT_DIR$x:"; done
|
||||
cmd="$1"; shift
|
||||
args=(); for a in "$@"; do if [[ "$a" == /* ]] && [ -e "$ROOT_DIR$a" ]; then args+=("$ROOT_DIR$a"); else args+=("$a"); fi; done
|
||||
HOME="$ROOT_DIR/srv/mosaic" PATH="$np$PATH" exec "$ROOT_DIR$cmd" "\${args[@]}"`,
|
||||
};
|
||||
|
||||
// Executables inside the tree, run by the fake sudo or by the script itself.
|
||||
const TREE = {
|
||||
[NODE]: `[ "\${1:-}" = --version ] && { cat "$HC/node-version"; exit 0; }
|
||||
exec "$REAL_NODE" "$@"`,
|
||||
[CLAUDE]: `[ "\${1:-}" = --version ] && cat "$HC/claude-version"; exit 0`,
|
||||
[CLI]: `${log("mosaic")}
|
||||
case "$1" in
|
||||
talk) case "$(cat "$HC/talk-mode")" in
|
||||
reply) echo "sent ab12cd34 to chief"; echo "[chief -> tester] seen" ;;
|
||||
noreply) echo "sent ab12cd34 to chief"; echo "no reply from chief within 300 s" >&2; exit 1 ;;
|
||||
sentonly) echo "sent ab12cd34 to chief" ;;
|
||||
esac ;;
|
||||
launches) cat "$HC/launches.json" ;;
|
||||
*) exit 2 ;;
|
||||
esac`,
|
||||
[PRECHECK]: `${log("precheck")}
|
||||
echo "precheck: done"; exit "$(cat "$HC/precheck-rc")"`,
|
||||
"/usr/local/lib/mosaic-stack/hostcheck.sh": `${log("hostcheck")}
|
||||
cat "$HC/hostcheck-out"`,
|
||||
};
|
||||
|
||||
function proc(root, pid, { ppid, uid = 997, exe, argv0 = "x", comm = "x", label }) {
|
||||
const d = join(root, "proc", String(pid));
|
||||
put(join(d, "status"), `Name:\t${comm}\nState:\tS (sleeping)\nPPid:\t${ppid}\nUid:\t${uid}\t${uid}\t${uid}\t${uid}\n`);
|
||||
put(join(d, "cmdline"), `${argv0}\0--x\0`);
|
||||
put(join(d, "comm"), `${comm}\n`);
|
||||
rmSync(join(d, "exe"), { force: true });
|
||||
if (exe) symlinkSync(exe, join(d, "exe"));
|
||||
if (label !== undefined) put(join(d, "attr", "current"), label);
|
||||
}
|
||||
|
||||
// A scratch Case 1 host where every F check passes and every P check is closed or accepted.
|
||||
function host(t) {
|
||||
const dir = tmp(t, "c1accept-");
|
||||
const root = join(dir, "root"), hc = join(dir, "hc"), bin = join(dir, "bin");
|
||||
const args = join(root, "etc", "mosaic-stack", "dev.args");
|
||||
put(args, ARGS.join("\n") + "\n", 0o644);
|
||||
put(join(root, "etc", "passwd"), PASSWD);
|
||||
put(join(root, "etc", "group"), GROUP);
|
||||
put(join(root, "etc", "sudoers.d", "90-localadmin"), "localadmin ALL=(ALL) NOPASSWD: ALL\n");
|
||||
put(join(root, "etc", "claude-code", "managed-settings.json"), JSON.stringify({ env: { DISABLE_AUTOUPDATER: "1" } }));
|
||||
put(join(root, CRED), `CLAUDE_CODE_OAUTH_TOKEN=${CRED_VALUE}\n`, 0o600);
|
||||
put(join(root, HOME, ".config", "mosaic-dev", "businesses", "mosaic-stack.json"), JSON.stringify({ id: "mosaic-stack", launch: { by: "pm" } }));
|
||||
put(join(root, "proc", "sys", "net", "ipv4", "ip_unprivileged_port_start"), "1024\n");
|
||||
proc(root, 1, { ppid: 0, uid: 0, exe: "/usr/lib/systemd/systemd", comm: "systemd" });
|
||||
proc(root, 100, { ppid: 1, exe: NODE, argv0: NODE, comm: "node" });
|
||||
proc(root, 200, { ppid: 1, exe: NODE, argv0: NODE, comm: "node" });
|
||||
proc(root, 300, { ppid: 100, exe: "/usr/bin/bwrap", argv0: "/usr/bin/bwrap", comm: "bwrap", label: `${OUTER}\n` });
|
||||
proc(root, 301, { ppid: 300, exe: NODE, argv0: NODE, comm: "node", label: `${CHILD}\n` });
|
||||
proc(root, 302, { ppid: 301, exe: CLAUDE, argv0: CLAUDE, comm: "claude.exe", label: `${CHILD}\n` });
|
||||
// A root bwrap with a mislabelled claude child, which F5 must pass over.
|
||||
proc(root, 400, { ppid: 1, uid: 0, exe: "/usr/bin/bwrap", argv0: "/usr/bin/bwrap", comm: "bwrap", label: "unconfined\n" });
|
||||
proc(root, 401, { ppid: 400, uid: 0, argv0: "claude", comm: "claude", label: "unconfined\n" });
|
||||
const state = {
|
||||
"[email protected]": "ActiveState=active\nUser=mosaic\nMainPID=100\n",
|
||||
"show-mosaic-webui.service": "ActiveState=active\nUser=mosaic\nMainPID=200\n",
|
||||
"show-mosaic-hostcheck.service": "[email protected] mosaic-webui.service multi-user.target\n",
|
||||
"enabled-mosaic-hostcheck.service": "enabled\n",
|
||||
"curl-rc": "0", ss: SS,
|
||||
"stat-cred": "mosaic 600 regular file\n", "stat-settings": "root:root 644 regular file\n",
|
||||
"sudo-l-mosaic": "User mosaic is not allowed to run sudo on dev-53.\n",
|
||||
"sudo-l-localadmin": "User localadmin may run the following commands on dev-53:\n (ALL : ALL) ALL\n (ALL) NOPASSWD: ALL\n",
|
||||
"jarvis-bwrap": "sudo: unable to execute /usr/bin/bwrap: Permission denied\n", "jarvis-bwrap-rc": "1",
|
||||
"node-version": `${NODE_PIN}\n`, "claude-version": `${CLAUDE_PIN} (Claude Code)\n`,
|
||||
"talk-mode": "reply", "precheck-rc": "0", "hostcheck-out": HOSTCHECK_OK,
|
||||
"launches.json": JSON.stringify([
|
||||
{ instance: "pm", live: true, business: "mosaic-stack", run: "r-0002" },
|
||||
{ instance: "pm", live: false, business: "mosaic-stack", run: "r-0001" },
|
||||
{ instance: "dev-1", live: true, business: "mosaic-stack", run: "r-0003" },
|
||||
]),
|
||||
};
|
||||
for (const [name, text] of Object.entries(state)) put(join(hc, name), text);
|
||||
for (const [name, body] of Object.entries(FAKES)) put(join(bin, name), `#!/usr/bin/env bash\n${name === "stat" ? "" : log(name)}\n${body}\n`, 0o755);
|
||||
for (const [path, body] of Object.entries(TREE)) put(join(root, path), `#!/usr/bin/env bash\n${body}\n`, 0o755);
|
||||
return { dir, root, hc, bin, args };
|
||||
}
|
||||
|
||||
function run(h, extra = {}, argv = ["--business", "mosaic-stack", "--args", "/etc/mosaic-stack/dev.args", "--claude-pin", CLAUDE_PIN, "--node-pin", NODE_PIN, "--root", h.root]) {
|
||||
const r = spawnSync(SCRIPT, argv, {
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, PATH: `${h.bin}:${process.env.PATH}`, HC: h.hc, ROOT_DIR: h.root, REAL_NODE: process.execPath, TMPDIR: h.dir, ...extra },
|
||||
});
|
||||
const lines = r.stdout.split("\n").filter(Boolean);
|
||||
// Each check line as { id, path, mark, evidence }.
|
||||
const checks = lines.filter((l) => /^[FP][0-9]+ /.test(l)).map((l) => {
|
||||
const [id, path, ...rest] = l.split(" ");
|
||||
const tail = rest.join(" ");
|
||||
const mark = MARKS.find((m) => tail === m || tail.startsWith(`${m} `));
|
||||
return { id, path, mark, evidence: tail.slice(mark?.length ?? 0).trim(), line: l };
|
||||
});
|
||||
return { status: r.status, out: r.stdout, err: r.stderr, lines, checks };
|
||||
}
|
||||
const calls = (h, name) => (existsSync(join(h.hc, "calls.log")) ? readFileSync(join(h.hc, "calls.log"), "utf8") : "")
|
||||
.split("\n").filter((l) => l === name || l.startsWith(`${name} `)).map((l) => l.slice(name.length + 1));
|
||||
const failed = (r) => r.checks.filter((c) => c.mark === "FAIL").map((c) => c.id);
|
||||
const marksOf = (r, id) => r.checks.filter((c) => c.id === id).map((c) => c.mark);
|
||||
const mustRun = (h, extra) => { const r = run(h, extra); assert.ok(r.status === 0 || r.status === 1, r.out + r.err); return r; };
|
||||
|
||||
// One fault per F check; each makes that check, and only that one, fail.
|
||||
const F_FAULTS = {
|
||||
F1: (h) => proc(h.root, 100, { ppid: 1, uid: 0, exe: NODE, comm: "node" }),
|
||||
F2: (h) => put(join(h.hc, "ss"), SS.replace("127.0.0.1:732 ", "0.0.0.0:732 ")),
|
||||
F3: (h) => put(join(h.hc, "talk-mode"), "noreply"),
|
||||
F4: (h) => put(join(h.hc, "precheck-rc"), "1"),
|
||||
F5: (h) => put(join(h.root, "proc", "302", "attr", "current"), "unconfined\n"),
|
||||
F6: (h) => put(join(h.hc, "claude-version"), "2.0.9 (Claude Code)\n"),
|
||||
F7: (h) => put(join(h.hc, "launches.json"), JSON.stringify([{ instance: "pm", live: false, business: "mosaic-stack", run: "r-1" }])),
|
||||
F8: (h) => put(join(h.hc, "stat-cred"), "mosaic 640 regular file\n"),
|
||||
F9: (h) => put(join(h.root, "etc", "claude-code", "managed-settings.json"), JSON.stringify({ env: { DISABLE_AUTOUPDATER: "0" } })),
|
||||
F10: (h) => put(join(h.hc, "node-version"), "v24.0.0\n"),
|
||||
F11: (h) => put(join(h.root, HOME, ".mosaic-dev", "discord", "binding.json"), "{}"),
|
||||
};
|
||||
|
||||
test("row 195 accept: every check passing exits 0, with each P mark and counts that match the lines", (t) => {
|
||||
const h = host(t);
|
||||
const r = run(h);
|
||||
assert.equal(r.status, 0, r.out + r.err);
|
||||
assert.deepEqual(r.checks.map((c) => c.id), ["F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11",
|
||||
"P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P11"]);
|
||||
for (const c of r.checks.filter((x) => x.id.startsWith("F"))) assert.equal(c.mark, "pass", c.line);
|
||||
for (const [id, mark] of Object.entries(P_PASS)) assert.deepEqual(marksOf(r, id), [mark], id);
|
||||
const counts = r.lines.filter((l) => l.startsWith("count ")).map((l) => l.slice(6));
|
||||
assert.deepEqual(counts, MARKS.map((m) => `${m} ${r.checks.filter((c) => c.mark === m).length}`));
|
||||
assert.match(r.lines.at(-1), /^case1-accept: every F check passes/);
|
||||
assert.match(r.out, /^F5 bwrap-label pass bwrap 300 reads 'bwrap \(enforce\)' and its claude descendant 302 reads/m);
|
||||
assert.match(r.out, /^F7 pm-live pass one live launch: pm run r-0002$/m);
|
||||
assert.ok(!(r.out + r.err).includes(CRED_VALUE));
|
||||
});
|
||||
|
||||
test("row 195 accept: exits 1 with each F check failing alone, and its line names it", (t) => {
|
||||
for (const [id, fault] of Object.entries(F_FAULTS)) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = mustRun(h);
|
||||
assert.equal(r.status, 1, `${id}: ${r.out}`);
|
||||
assert.deepEqual(failed(r), [id], `${id}: ${r.out}`);
|
||||
assert.equal(r.lines.at(-1), "case1-accept: an F check failed, so the row fails");
|
||||
}
|
||||
});
|
||||
|
||||
test("row 195 accept: F3 fails on exit 0 with no reply line, and its evidence takes talk's error", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.hc, "talk-mode"), "sentonly");
|
||||
let r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F3"]);
|
||||
assert.match(r.out, /^F3 tester-reply FAIL talk exited 0 with 1 lines on stdout; last: sent ab12cd34 to chief$/m);
|
||||
h = host(t);
|
||||
put(join(h.hc, "talk-mode"), "noreply");
|
||||
r = mustRun(h);
|
||||
assert.match(r.out, /^F3 tester-reply FAIL talk exited 1 with 1 lines on stdout; last: no reply from chief within 300 s$/m);
|
||||
});
|
||||
|
||||
test("row 195 accept: F1 fails on a unit that isn't active or isn't User=mosaic", (t) => {
|
||||
for (const show of ["ActiveState=failed\nUser=mosaic\nMainPID=0\n", "ActiveState=active\nUser=root\nMainPID=100\n"]) {
|
||||
const h = host(t);
|
||||
put(join(h.hc, "show-mosaic-webui.service"), show);
|
||||
const r = mustRun(h);
|
||||
assert.equal(r.status, 1);
|
||||
assert.ok(failed(r).includes("F1"), r.out);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 195 accept: F2 fails when healthz doesn't answer and when another pid holds the port", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.hc, "curl-rc"), "7");
|
||||
let r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F2"]);
|
||||
assert.match(r.out, /^F2 console-loopback FAIL curl http:\/\/127\.0\.0\.1:732\/healthz exited 7$/m);
|
||||
h = host(t);
|
||||
put(join(h.hc, "ss"), SS.replace("pid=200,fd=21", "pid=555,fd=4"));
|
||||
r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F2"]);
|
||||
});
|
||||
|
||||
test("row 195 accept: F5 fails on unpriv_bwrap (enforce), on complain and on a trailing space", (t) => {
|
||||
for (const label of ["unpriv_bwrap (enforce)\n", "bwrap//&unpriv_bwrap (complain)\n", `${CHILD} \n`]) {
|
||||
const h = host(t);
|
||||
put(join(h.root, "proc", "302", "attr", "current"), label);
|
||||
const r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F5"], `${JSON.stringify(label)}: ${r.out}`);
|
||||
}
|
||||
const h = host(t);
|
||||
put(join(h.root, "proc", "300", "attr", "current"), `${OUTER} \n`);
|
||||
assert.deepEqual(failed(mustRun(h)), ["F5"]);
|
||||
});
|
||||
|
||||
test("row 195 accept: F5 fails with no bwrap of mosaic's, and passes on comm alone", (t) => {
|
||||
let h = host(t);
|
||||
proc(h.root, 300, { ppid: 100, uid: 1001, exe: "/usr/bin/bwrap", comm: "bwrap", label: `${OUTER}\n` });
|
||||
let r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F5"]);
|
||||
assert.match(r.out, /^F5 bwrap-label FAIL no \/usr\/bin\/bwrap process of mosaic/m);
|
||||
h = host(t);
|
||||
proc(h.root, 302, { ppid: 301, argv0: "/proc/self/fd/3", comm: "claude", label: `${CHILD}\n` });
|
||||
assert.deepEqual(failed(mustRun(h)), []);
|
||||
});
|
||||
|
||||
test("row 195 accept: F6 fails on a stub that prints nothing and on a path outside claude-<pin>", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.hc, "claude-version"), "");
|
||||
let r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F6"]);
|
||||
h = host(t);
|
||||
const other = CLAUDE.replace(`claude-${CLAUDE_PIN}`, "claude-2.0.9");
|
||||
put(h.args, ARGS.map((a) => (a === CLAUDE ? other : a)).join("\n") + "\n", 0o644);
|
||||
put(join(h.root, other), `#!/usr/bin/env bash\necho "${CLAUDE_PIN} (Claude Code)"\n`, 0o755);
|
||||
r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F6"]);
|
||||
assert.match(r.out, /^F6 claude-pin FAIL --claude \S+claude-2\.0\.9\S+ is not under \/opt\/mosaic-stack\/claude-2\.1\.0\/$/m);
|
||||
});
|
||||
|
||||
test("row 195 accept: F7 fails on two live PM launches, one for another business, and no launch.by", (t) => {
|
||||
const two = [{ instance: "pm", live: true, business: "mosaic-stack", run: "a" }, { instance: "pm", live: true, business: "mosaic-stack", run: "b" }];
|
||||
for (const [file, text] of [["launches.json", JSON.stringify(two)], ["launches.json", JSON.stringify([{ instance: "pm", live: true, business: "other", run: "a" }])]]) {
|
||||
const h = host(t);
|
||||
put(join(h.hc, file), text);
|
||||
assert.deepEqual(failed(mustRun(h)), ["F7"]);
|
||||
}
|
||||
const h = host(t);
|
||||
put(join(h.root, HOME, ".config", "mosaic-dev", "businesses", "mosaic-stack.json"), JSON.stringify({ id: "mosaic-stack" }));
|
||||
const r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F7"]);
|
||||
assert.match(r.out, /^F7 pm-live FAIL the business file has no launch\.by$/m);
|
||||
});
|
||||
|
||||
test("row 195 accept: F8 fails on 0640, on another owner and on a symlink, and never prints the credential", (t) => {
|
||||
for (const fault of [
|
||||
(h) => put(join(h.hc, "stat-cred"), "mosaic 640 regular file\n"),
|
||||
(h) => put(join(h.hc, "stat-cred"), "root 600 regular file\n"),
|
||||
(h) => { const f = join(h.root, CRED); rmSync(f); put(`${f}.real`, `X=${CRED_VALUE}\n`, 0o600); symlinkSync(`${f}.real`, f); },
|
||||
]) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F8"], r.out);
|
||||
assert.ok(!(r.out + r.err).includes(CRED_VALUE));
|
||||
}
|
||||
});
|
||||
|
||||
test("row 195 accept: F9 fails on another owner, a group-writable mode and a number for the flag", (t) => {
|
||||
for (const fault of [
|
||||
(h) => put(join(h.hc, "stat-settings"), "root:root 664 regular file\n"),
|
||||
(h) => put(join(h.hc, "stat-settings"), "mosaic:root 644 regular file\n"),
|
||||
(h) => put(join(h.root, "etc", "claude-code", "managed-settings.json"), JSON.stringify({ env: { DISABLE_AUTOUPDATER: 1 } })),
|
||||
]) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
assert.deepEqual(failed(mustRun(h)), ["F9"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 195 accept: F11 fails on one *.json under discord/ and passes on an empty directory", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.root, HOME, ".mosaic-dev", "discord", "chief.json"), "{}");
|
||||
let r = mustRun(h);
|
||||
assert.deepEqual(failed(r), ["F11"]);
|
||||
assert.match(r.out, /^F11 no-discord FAIL \/srv\/mosaic\/\.mosaic-dev\/discord holds bindings: chief\.json$/m);
|
||||
h = host(t);
|
||||
mkdirSync(join(h.root, HOME, ".mosaic-dev", "discord"), { recursive: true });
|
||||
assert.deepEqual(failed(mustRun(h)), []);
|
||||
});
|
||||
|
||||
// Each P check in its unnamed mark, with the line count each fault makes; none changes the exit.
|
||||
const P_FAULTS = {
|
||||
P1: [1, (h) => put(join(h.hc, "sudo-l-mosaic"), "User mosaic may run the following commands on dev-53:\n")],
|
||||
P2: [1, (h) => put(join(h.root, HOME, ".ssh", "authorized_keys"), "ssh-ed25519 AAAA test\n")],
|
||||
P5: [1, (h) => edit(join(h.root, "etc", "group"), (s) => s.replace("docker:x:999:", "docker:x:999:jarvis"))],
|
||||
P6: [2, (h) => edit(join(h.root, "etc", "group"), (s) => s.replace("sudo:x:27:localadmin", "sudo:x:27:localadmin,bob").replace("lxd:x:998:", "lxd:x:998:carol"))],
|
||||
P7: [1, (h) => put(join(h.root, "etc", "sudoers.d", "50-mosaic"), "mosaic ALL=(root) NOPASSWD: /usr/bin/systemctl\n")],
|
||||
P8: [1, (h) => put(join(h.hc, "ss"), `${SS}LISTEN 0 511 0.0.0.0:7331 0.0.0.0:* users:(("node",pid=200,fd=23))\n`)],
|
||||
P9: [3, (h) => { put(join(h.hc, "hostcheck-out"), HOSTCHECK_OK.replace("ok 2 ", "FAIL 2 ").replace("ok 5 ", "FAIL 5 ")); put(join(h.hc, "jarvis-bwrap-rc"), "0"); }],
|
||||
P10: [1, (h) => put(join(h.root, "proc", "sys", "net", "ipv4", "ip_unprivileged_port_start"), "700\n")],
|
||||
P11: [1, (h) => put(join(h.hc, "show-mosaic-hostcheck.service"), "[email protected] multi-user.target\n")],
|
||||
};
|
||||
|
||||
test("row 195 accept: each P check reports unnamed on its fault, and the exit stays 0", (t) => {
|
||||
for (const [id, [n, fault]] of Object.entries(P_FAULTS)) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = run(h);
|
||||
assert.equal(r.status, 0, `${id}: ${r.out}`);
|
||||
assert.deepEqual(marksOf(r, id), Array(n).fill("unnamed"), `${id}: ${r.out}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 195 accept: P2 is unnamed with a supplementary group, and P5 names docker", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.root, "etc", "group"), GROUP.replace("lxd:x:998:", "lxd:x:998:mosaic"));
|
||||
let r = run(h);
|
||||
assert.equal(r.status, 0);
|
||||
assert.deepEqual(marksOf(r, "P2"), ["unnamed"]);
|
||||
assert.match(r.out, /^P2 mosaic-groups-keys unnamed id -G is '997 998'; authorized_keys is absent$/m);
|
||||
h = host(t);
|
||||
P_FAULTS.P5[1](h);
|
||||
r = run(h);
|
||||
assert.match(r.out, /^P5 jarvis-reach unnamed jarvis is in docker$/m);
|
||||
assert.match(r.out, /^P6 group-docker unnamed jarvis is a member of docker$/m);
|
||||
});
|
||||
|
||||
test("row 195 accept: P5 is closed with no jarvis account, and P2 with an empty authorized_keys", (t) => {
|
||||
const h = host(t);
|
||||
put(join(h.root, "etc", "passwd"), PASSWD.replace(/^jarvis:.*\n/m, ""));
|
||||
put(join(h.root, HOME, ".ssh", "authorized_keys"), "");
|
||||
const r = run(h);
|
||||
assert.deepEqual(marksOf(r, "P5"), ["closed"]);
|
||||
assert.deepEqual(marksOf(r, "P2"), ["closed"]);
|
||||
});
|
||||
|
||||
test("row 195 accept: P9 is unnamed once for each item missing", (t) => {
|
||||
const items = {
|
||||
hostcheck: (h) => put(join(h.hc, "hostcheck-out"), HOSTCHECK_OK.replace("ok 3 ", "FAIL 3 ")),
|
||||
jarvis: (h) => { put(join(h.hc, "jarvis-bwrap-rc"), "0"); put(join(h.hc, "jarvis-bwrap"), ""); },
|
||||
member: (h) => put(join(h.root, "etc", "group"), GROUP.replace("mosaic:x:997:", "mosaic:x:997:jarvis")),
|
||||
gid: (h) => put(join(h.root, "etc", "passwd"), `${PASSWD}hermes:x:1002:997::/home/hermes:/bin/bash\n`),
|
||||
};
|
||||
for (const [name, fault] of Object.entries(items)) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = run(h);
|
||||
assert.equal(r.status, 0);
|
||||
assert.deepEqual(marksOf(r, "P9"), ["unnamed"], `${name}: ${r.out}`);
|
||||
}
|
||||
const h = host(t);
|
||||
put(join(h.hc, "hostcheck-out"), "");
|
||||
assert.deepEqual(marksOf(run(h), "P9"), Array(6).fill("unnamed"));
|
||||
});
|
||||
|
||||
test("row 195 accept: P10 is unnamed with 7333 held by another pid; P11 with the unit disabled", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.hc, "ss"), SS.replace("pid=200,fd=22", "pid=555,fd=4"));
|
||||
let r = run(h);
|
||||
assert.equal(r.status, 0);
|
||||
assert.deepEqual(marksOf(r, "P10"), ["unnamed"]);
|
||||
h = host(t);
|
||||
put(join(h.hc, "enabled-mosaic-hostcheck.service"), "disabled\n");
|
||||
r = run(h);
|
||||
assert.deepEqual(marksOf(r, "P11"), ["unnamed"]);
|
||||
});
|
||||
|
||||
test("row 195 accept: every P check unnamed together still exits 0", (t) => {
|
||||
const h = host(t);
|
||||
for (const [, fault] of Object.values(P_FAULTS)) fault(h);
|
||||
const r = run(h);
|
||||
assert.equal(r.status, 0, r.out + r.err);
|
||||
assert.deepEqual(failed(r), []);
|
||||
for (const id of ["P1", "P2", "P5", "P6", "P7", "P8", "P9", "P10", "P11"]) assert.ok(marksOf(r, id).every((m) => m === "unnamed"), id);
|
||||
assert.match(r.lines.at(-1), /^case1-accept: every F check passes/);
|
||||
});
|
||||
|
||||
test("row 195 accept: a bad args file refuses with exit 2 before any check, each for its own reason", (t) => {
|
||||
const bad = {
|
||||
"group write": [(h) => chmodSync(h.args, 0o664), /dev\.args must be \S+'s with no group or other write \(it is uid \d+, mode 664\)$/],
|
||||
symlink: [(h) => { put(`${h.args}.real`, ARGS.join("\n") + "\n", 0o644); rmSync(h.args); symlinkSync(`${h.args}.real`, h.args); }, /no regular file \/etc\/mosaic-stack\/dev\.args$/],
|
||||
"unknown flag": [(h) => put(h.args, ["--send", ...ARGS].join("\n") + "\n", 0o644), /has --send before --, which case2-unit\.sh does not take$/],
|
||||
"two copies": [(h) => put(h.args, ["--copy", COPY, ...ARGS].join("\n") + "\n", 0o644), /needs exactly one --copy before --, not 2$/],
|
||||
"library profile": [(h) => put(h.args, ARGS.map((a) => (a === "factory" ? "library" : a)).join("\n") + "\n", 0o644), /has --profile 'library', not factory$/],
|
||||
"another business": [(h) => put(h.args, ARGS.map((a, i) => (a === "mosaic-stack" && i < 14 ? "acme" : a)).join("\n") + "\n", 0o644), /is for business acme, not mosaic-stack$/],
|
||||
"no tester port": [(h) => put(h.args, ARGS.slice(0, -2).join("\n") + "\n", 0o644), /lacks a numeric --port or --tester-port after --$/],
|
||||
"short copy": [(h) => put(h.args, ARGS.map((a) => (a === COPY ? "abc123" : a)).join("\n") + "\n", 0o644), /lacks a plain --user, --home, --business, --node, --claude or --copy$/],
|
||||
"no file": [(h) => rmSync(h.args), /no regular file \/etc\/mosaic-stack\/dev\.args$/],
|
||||
};
|
||||
for (const [name, [fault, why]] of Object.entries(bad)) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = run(h);
|
||||
assert.equal(r.status, 2, `${name}: ${r.out}${r.err}`);
|
||||
assert.match(r.err.trimEnd(), /^case1-accept: refusing: /, name);
|
||||
assert.match(r.err.trimEnd(), why, name);
|
||||
assert.equal(r.out, "", name);
|
||||
assert.ok(!existsSync(join(h.hc, "calls.log")), name);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 195 accept: usage errors and a run without --root as a user exit 2", (t) => {
|
||||
const h = host(t);
|
||||
let r = run(h, {}, ["--business", "mosaic-stack", "--args", "/etc/mosaic-stack/dev.args", "--node-pin", NODE_PIN, "--root", h.root]);
|
||||
assert.equal(r.status, 2);
|
||||
assert.match(r.err, /^usage: /);
|
||||
r = run(h, {}, ["--business", "mosaic-stack", "--args", "/etc/mosaic-stack/dev.args", "--claude-pin", CLAUDE_PIN, "--node-pin", "24.1.0", "--root", h.root]);
|
||||
assert.equal(r.status, 2);
|
||||
r = run(h, {}, ["--business", "mosaic-stack", "--args", "/etc/mosaic-stack/dev.args", "--claude-pin", CLAUDE_PIN, "--node-pin", NODE_PIN]);
|
||||
assert.equal(r.status, 2);
|
||||
assert.equal(r.err, "case1-accept: refusing: run it as root\n");
|
||||
assert.ok(!existsSync(join(h.hc, "calls.log")));
|
||||
});
|
||||
|
||||
test("row 195 accept: every in-instance call goes through sudo -u mosaic -H env PATH=<node dir>:...", (t) => {
|
||||
const h = host(t);
|
||||
const r = run(h);
|
||||
assert.equal(r.status, 0, r.out + r.err);
|
||||
const sudo = calls(h, "sudo");
|
||||
const asMosaic = sudo.filter((a) => a.startsWith("-u mosaic"));
|
||||
for (const a of asMosaic) assert.ok(a.startsWith(`${AS_MOSAIC} /`), a);
|
||||
const cmds = asMosaic.map((a) => a.slice(AS_MOSAIC.length + 1).split(" ")[0]);
|
||||
assert.deepEqual([...new Set(cmds)].sort(), [CLI, PRECHECK, CLAUDE, NODE].sort());
|
||||
assert.deepEqual(sudo.filter((a) => !a.startsWith("-u mosaic")).sort(),
|
||||
["-l -U localadmin", "-l -U mosaic", "-u jarvis /usr/bin/bwrap --version"]);
|
||||
const talk = calls(h, "mosaic").filter((a) => a.startsWith("talk "));
|
||||
assert.equal(talk.length, 1);
|
||||
assert.match(talk[0], /^talk chief case1-accept-[0-9a-f]{12}: .* --business mosaic-stack --tester --wait 300$/);
|
||||
assert.deepEqual(calls(h, "precheck"), ["--business mosaic-stack --profile factory"]);
|
||||
});
|
||||
|
||||
test("row 195 accept: the host check runs with --check and never --enforce", (t) => {
|
||||
const h = host(t);
|
||||
run(h);
|
||||
assert.deepEqual(calls(h, "hostcheck"), ["--check"]);
|
||||
});
|
||||
@@ -1,335 +0,0 @@
|
||||
// Row 240 (I4, #1746): scripts/case1-hostcheck.sh, the Case 1 host's drift stop for bwrap, and its
|
||||
// pins and boot unit. Brief: docs/plans/2026-10-20_installer-rows.md "I4 hostcheck"; design r6 B2
|
||||
// (agents/darkwing/work/queue-195/DESIGN.md at b7239bb66). Every case copies the script into a scratch
|
||||
// lib directory with a fixture case1-pins.sh beside it and runs it with --root on a scratch host tree.
|
||||
// Fake aa-status, dpkg, dpkg-statoverride, apparmor_parser, systemd-run, stat, chown, chmod, apt-get
|
||||
// and dpkg-deb on PATH record their argv. Nothing here reads or writes the real /etc, /proc or /usr.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { tmp } from "./helpers.mjs";
|
||||
|
||||
const REPO = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
const SCRIPT = join(REPO, "scripts", "case1-hostcheck.sh");
|
||||
const PINS = join(REPO, "scripts", "case1-pins.sh");
|
||||
const UNIT = join(REPO, "packages", "cli", "systemd", "mosaic-hostcheck.service");
|
||||
const PROFILE = "/etc/apparmor.d/bwrap-userns-restrict";
|
||||
const LABEL = "bwrap//&unpriv_bwrap (enforce)";
|
||||
// A made-up profile; the fixture pins carry its sha256.
|
||||
const PROFILE_TEXT = "abi <abi/4.0>,\ninclude <tunables/global>\nprofile bwrap /usr/bin/bwrap flags=(attach_disconnected,mediate_deleted) {\n allow capability,\n change_profile /** -> &unpriv_bwrap,\n}\nprofile unpriv_bwrap flags=(attach_disconnected,mediate_deleted) {\n audit deny capability,\n}\n";
|
||||
const sha256 = (s) => createHash("sha256").update(s).digest("hex");
|
||||
const AA_OK = { version: "2", profiles: { "/usr/bin/man": "enforce", bwrap: "enforce", unpriv_bwrap: "enforce", "lsb_release": "enforce" }, processes: {} };
|
||||
const SYSTEMD_RUN = ["--wait", "--pipe", "--uid=mosaic", "--gid=mosaic", "-p", "NoNewPrivileges=yes", "-p", "ProtectSystem=strict",
|
||||
"-p", "ProtectHome=yes", "-p", "PrivateTmp=yes", "/usr/bin/bwrap", "--unshare-user", "--unshare-pid", "--ro-bind", "/", "/",
|
||||
"cat", "/proc/self/attr/current"];
|
||||
|
||||
function put(file, text, mode) {
|
||||
mkdirSync(dirname(file), { recursive: true });
|
||||
writeFileSync(file, text);
|
||||
if (mode) chmodSync(file, mode);
|
||||
}
|
||||
|
||||
// Each fake appends `name argv...` to calls.log and answers from a file in the state directory.
|
||||
const FAKES = {
|
||||
"aa-status": `[ -f "$HC/aa-rc" ] && exit "$(cat "$HC/aa-rc")"; cat "$HC/aa-status.json"`,
|
||||
dpkg: `case "$1" in
|
||||
-S) [ -f "$HC/owner" ] && cat "$HC/owner"; exit "$(cat "$HC/dpkg-S-rc")" ;;
|
||||
-s) [ "$2" = bubblewrap ] && printf 'Package: bubblewrap\\nStatus: install ok installed\\nVersion: %s\\n' "$(cat "$HC/bwrap-version")" ;;
|
||||
*) exit 2 ;;
|
||||
esac`,
|
||||
"dpkg-statoverride": `[ "$1" = --list ] && cat "$HC/statoverride"`,
|
||||
apparmor_parser: `exit 0`,
|
||||
"systemd-run": `cat "$HC/label"`,
|
||||
stat: `cat "$HC/stat"`,
|
||||
chown: `exit 0`,
|
||||
chmod: `exit 0`,
|
||||
"apt-get": `[ -f "$HC/apt-rc" ] && exit "$(cat "$HC/apt-rc")"; [ "$1 $2" = "download apparmor-profiles" ] && cp "$HC/deb" "./apparmor-profiles_9.9_all.deb"`,
|
||||
"dpkg-deb": `case "$1" in
|
||||
-f) [ "$3" = Version ] && echo 9.9-upstream ;;
|
||||
-x) mkdir -p "$3/usr/share/apparmor/extra-profiles"; [ ! -f "$HC/upstream-profile" ] || cp "$HC/upstream-profile" "$3/usr/share/apparmor/extra-profiles/bwrap-userns-restrict" ;;
|
||||
esac`,
|
||||
};
|
||||
|
||||
// A scratch host where all seven items hold.
|
||||
function host(t) {
|
||||
const dir = tmp(t, "case1-hostcheck-");
|
||||
const root = join(dir, "root"), hc = join(dir, "hc"), bin = join(dir, "bin"), lib = join(dir, "lib");
|
||||
put(join(root, PROFILE), PROFILE_TEXT);
|
||||
put(join(root, "etc", "apparmor.d", "abstractions", "base"), " /etc/ld.so.cache r,\n");
|
||||
put(join(root, "etc", "apparmor.d", "tunables", "global"), "@{HOME}=/home/*/\n");
|
||||
put(join(root, "proc", "sys", "kernel", "apparmor_restrict_unprivileged_userns"), "1\n");
|
||||
put(join(root, "proc", "sys", "fs", "protected_hardlinks"), "1\n");
|
||||
put(join(root, "proc", "sys", "net", "ipv4", "ip_unprivileged_port_start"), "1024\n");
|
||||
put(join(root, "etc", "systemd", "system", "mosaic-webui.service"),
|
||||
"[Service]\nExecStart=/opt/mosaic-stack/node/bin/node /srv/mosaic/copies/x/packages/webui/src/cli.mjs serve --port 732 --business mosaic-stack --tester-port 7333\n");
|
||||
put(join(root, "usr", "bin", "bwrap"), "", 0o755);
|
||||
put(join(hc, "aa-status.json"), JSON.stringify(AA_OK));
|
||||
put(join(hc, "dpkg-S-rc"), "1");
|
||||
put(join(hc, "bwrap-version"), "0.9.0-1ubuntu0.3");
|
||||
put(join(hc, "statoverride"), "root mosaic 0750 /usr/bin/bwrap\n");
|
||||
put(join(hc, "label"), `${LABEL}\n`);
|
||||
put(join(hc, "stat"), "root mosaic 750\n");
|
||||
put(join(hc, "deb"), "fake deb\n");
|
||||
put(join(hc, "upstream-profile"), PROFILE_TEXT);
|
||||
for (const [name, body] of Object.entries(FAKES)) {
|
||||
put(join(bin, name), `#!/usr/bin/env bash\nprintf '%s' ${JSON.stringify(name)} >> "$HC/calls.log"; printf ' %s' "$@" >> "$HC/calls.log"; echo >> "$HC/calls.log"\n${body}\n`, 0o755);
|
||||
}
|
||||
mkdirSync(lib);
|
||||
copyFileSync(SCRIPT, join(lib, "hostcheck.sh"));
|
||||
chmodSync(join(lib, "hostcheck.sh"), 0o755);
|
||||
put(join(lib, "case1-pins.sh"), `PIN_PROFILES_VERSION=4.0.1-fixture\nPIN_PROFILE_SHA256=${sha256(PROFILE_TEXT)}\nPIN_BUBBLEWRAP_VERSION=0.9.0-1ubuntu0.3\n`);
|
||||
return { dir, root, hc, bin, lib, script: join(lib, "hostcheck.sh") };
|
||||
}
|
||||
|
||||
function run(h, ...args) {
|
||||
const r = spawnSync(h.script, [...args, "--root", h.root], {
|
||||
encoding: "utf8",
|
||||
env: { ...process.env, PATH: `${h.bin}:${process.env.PATH}`, HC: h.hc, TMPDIR: h.dir },
|
||||
});
|
||||
return { status: r.status, out: r.stdout, err: r.stderr, lines: r.stdout.split("\n").filter(Boolean) };
|
||||
}
|
||||
const calls = (h, name) => (existsSync(join(h.hc, "calls.log")) ? readFileSync(join(h.hc, "calls.log"), "utf8") : "")
|
||||
.split("\n").filter((l) => l === name || l.startsWith(`${name} `)).map((l) => l.slice(name.length + 1));
|
||||
const fails = (r) => r.lines.filter((l) => l.startsWith("FAIL "));
|
||||
const drift = (h) => join(h.root, "etc", "mosaic-stack", "DRIFT");
|
||||
const hlog = (h) => join(h.root, "var", "log", "mosaic-stack", "hostcheck.log");
|
||||
const aa = (h, profiles) => put(join(h.hc, "aa-status.json"), JSON.stringify({ version: "2", profiles, processes: {} }));
|
||||
|
||||
// One fault per item; each makes that item, and only that one, fail.
|
||||
const FAULTS = {
|
||||
1: (h) => put(join(h.root, PROFILE), `${PROFILE_TEXT}# drift\n`),
|
||||
2: (h) => aa(h, { ...AA_OK.profiles, bwrap: "complain" }),
|
||||
3: (h) => put(join(h.root, "etc", "apparmor.d", "usr.bin.other"), "profile other /usr/bin/other {\n /usr/bin/bwrap ix,\n}\n"),
|
||||
4: (h) => put(join(h.hc, "label"), "unconfined\n"),
|
||||
5: (h) => put(join(h.hc, "statoverride"), "root root 0755 /usr/bin/bwrap\n"),
|
||||
6: (h) => put(join(h.root, "proc", "sys", "kernel", "apparmor_restrict_unprivileged_userns"), "0\n"),
|
||||
7: (h) => put(join(h.root, "proc", "sys", "net", "ipv4", "ip_unprivileged_port_start"), "700\n"),
|
||||
};
|
||||
|
||||
test("row 240 check: exits 0 with all seven items and a note that bubblewrap is the install pin", (t) => {
|
||||
const h = host(t);
|
||||
const r = run(h, "--check");
|
||||
assert.equal(r.status, 0, r.out + r.err);
|
||||
assert.deepEqual(r.lines.map((l) => l.split(" ").slice(0, 2).join(" ")), ["ok 1", "ok 2", "ok 3", "ok 4", "ok 5", "ok 6", "ok 7", "note bubblewrap"]);
|
||||
assert.match(r.lines[6], /is 1024, above the Console's --port 732$/);
|
||||
assert.equal(r.lines[7], "note bubblewrap 0.9.0-1ubuntu0.3 is the install pin");
|
||||
});
|
||||
|
||||
test("row 240 check: exits 1 with each item failing alone, and its line names it", (t) => {
|
||||
for (const [n, fault] of Object.entries(FAULTS)) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = run(h, "--check");
|
||||
assert.equal(r.status, 1, `item ${n}: ${r.out}`);
|
||||
assert.deepEqual(fails(r).map((l) => l.split(" ")[1]), [n], `item ${n}: ${r.out}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 240 check: item 1 fails when a package owns the profile, when dpkg -S errs, or with no pin", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.hc, "dpkg-S-rc"), "0");
|
||||
put(join(h.hc, "owner"), `apparmor-profiles: ${PROFILE}\n`);
|
||||
let r = run(h, "--check");
|
||||
assert.equal(r.status, 1);
|
||||
assert.deepEqual(fails(r), [`FAIL 1 ${PROFILE} is owned by a package: apparmor-profiles: ${PROFILE}`]);
|
||||
assert.deepEqual(calls(h, "dpkg").filter((a) => a.startsWith("-S")), [`-S ${PROFILE}`]);
|
||||
h = host(t);
|
||||
put(join(h.hc, "dpkg-S-rc"), "2");
|
||||
r = run(h, "--check");
|
||||
assert.deepEqual(fails(r), [`FAIL 1 dpkg -S ${PROFILE} exited 2`]);
|
||||
h = host(t);
|
||||
rmSync(join(h.lib, "case1-pins.sh"));
|
||||
r = run(h, "--check");
|
||||
assert.equal(r.status, 1);
|
||||
assert.deepEqual(fails(r), [`FAIL 1 no profile pin in ${h.lib}/case1-pins.sh`]);
|
||||
});
|
||||
|
||||
test("row 240 check: item 2 fails on a loaded mosaic-bwrap, a missing unpriv_bwrap or a failed aa-status", (t) => {
|
||||
for (const [fault, text] of [
|
||||
[(h) => aa(h, { ...AA_OK.profiles, "mosaic-bwrap": "enforce" }), "a mosaic-bwrap profile"],
|
||||
[(h) => aa(h, { bwrap: "enforce" }), "no unpriv_bwrap profile in enforce mode"],
|
||||
[(h) => put(join(h.hc, "aa-rc"), "1"), "aa-status --json failed"],
|
||||
]) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = run(h, "--check");
|
||||
assert.equal(r.status, 1);
|
||||
assert.equal(fails(r).length, 1, r.out);
|
||||
assert.ok(fails(r)[0].startsWith("FAIL 2 ") && fails(r)[0].includes(text), r.out);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 240 check: item 3 fails on a second file naming bwrap as a word, /{usr/,}bin/bwrap included", (t) => {
|
||||
for (const text of ["profile x /{usr/,}bin/bwrap {\n}\n", "# runs bwrap\n", "/usr/bin/bwrap ix,\n"]) {
|
||||
const h = host(t);
|
||||
put(join(h.root, "etc", "apparmor.d", "local", "extra"), text);
|
||||
const r = run(h, "--check");
|
||||
assert.equal(r.status, 1, text);
|
||||
assert.deepEqual(fails(r).map((l) => l.split(" ")[1]), ["3"], text);
|
||||
assert.ok(fails(r)[0].includes(join(h.root, "etc", "apparmor.d", "local", "extra")), r.out);
|
||||
}
|
||||
const h = host(t);
|
||||
put(join(h.root, "etc", "apparmor.d", "local", "extra"), "# bwrapper and unpriv-bwrapx are other words\n");
|
||||
assert.equal(run(h, "--check").status, 0);
|
||||
});
|
||||
|
||||
test("row 240 check: item 4 reads the label under the units' no-new-privs and matches it exactly", (t) => {
|
||||
let h = host(t);
|
||||
assert.equal(run(h, "--check").status, 0);
|
||||
assert.deepEqual(calls(h, "systemd-run"), [SYSTEMD_RUN.join(" ")]);
|
||||
for (const label of ["unpriv_bwrap (enforce)", `${LABEL} `, `x${LABEL}`]) {
|
||||
h = host(t);
|
||||
put(join(h.hc, "label"), `${label}\n`);
|
||||
const r = run(h, "--check");
|
||||
assert.equal(r.status, 1, JSON.stringify(label));
|
||||
assert.deepEqual(fails(r), [`FAIL 4 a bwrap child under no-new-privs has the label '${label}', not '${LABEL}'`]);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 240 check: item 5 needs the statoverride and stat to agree", (t) => {
|
||||
const h = host(t);
|
||||
put(join(h.hc, "stat"), "root root 700\n");
|
||||
const r = run(h, "--check");
|
||||
assert.deepEqual(fails(r), ["FAIL 5 /usr/bin/bwrap is 'root root 700', not 'root mosaic 750'"]);
|
||||
assert.deepEqual(calls(h, "dpkg-statoverride"), ["--list /usr/bin/bwrap"]);
|
||||
assert.deepEqual(calls(h, "stat"), [`-c %U %G %a ${h.root}/usr/bin/bwrap`]);
|
||||
});
|
||||
|
||||
test("row 240 check: item 6 fails on protected_hardlinks 0; item 7 fails with the floor at 732 and reads 1023 with no unit", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.root, "proc", "sys", "fs", "protected_hardlinks"), "0\n");
|
||||
assert.deepEqual(fails(run(h, "--check")).map((l) => l.split(" ")[1]), ["6"]);
|
||||
h = host(t);
|
||||
put(join(h.root, "proc", "sys", "net", "ipv4", "ip_unprivileged_port_start"), "732\n");
|
||||
assert.deepEqual(fails(run(h, "--check")), ["FAIL 7 net.ipv4.ip_unprivileged_port_start is 732, not above the Console's --port 732"]);
|
||||
put(join(h.root, "proc", "sys", "net", "ipv4", "ip_unprivileged_port_start"), "733\n");
|
||||
assert.equal(run(h, "--check").status, 0);
|
||||
rmSync(join(h.root, "etc", "systemd", "system", "mosaic-webui.service"));
|
||||
assert.deepEqual(fails(run(h, "--check")), ["FAIL 7 net.ipv4.ip_unprivileged_port_start is 733, not above 1023, because no Console unit is installed"]);
|
||||
put(join(h.root, "proc", "sys", "net", "ipv4", "ip_unprivileged_port_start"), "1024\n");
|
||||
assert.equal(run(h, "--check").status, 0);
|
||||
put(join(h.root, "etc", "systemd", "system", "mosaic-webui.service"), "[Service]\nExecStart=/x serve --business mosaic-stack --tester-port 7333\n");
|
||||
assert.deepEqual(fails(run(h, "--check")), ["FAIL 7 /etc/systemd/system/mosaic-webui.service has no --port"]);
|
||||
});
|
||||
|
||||
test("row 240 check: a bubblewrap version other than the install pin is a note, not a failure", (t) => {
|
||||
const h = host(t);
|
||||
put(join(h.hc, "bwrap-version"), "0.9.0-1ubuntu0.4");
|
||||
const r = run(h, "--check");
|
||||
assert.equal(r.status, 0);
|
||||
assert.equal(r.lines.at(-1), "note bubblewrap 0.9.0-1ubuntu0.4 is not the install pin 0.9.0-1ubuntu0.3, which is not a drift item");
|
||||
});
|
||||
|
||||
test("row 240 enforce: a pass with no DRIFT changes nothing and exits 0", (t) => {
|
||||
const h = host(t);
|
||||
const r = run(h, "--enforce");
|
||||
assert.equal(r.status, 0);
|
||||
assert.equal(r.lines.at(-1), "hostcheck: all seven hold");
|
||||
assert.deepEqual([calls(h, "apparmor_parser"), calls(h, "chown"), calls(h, "chmod")], [[], [], []]);
|
||||
assert.equal(existsSync(drift(h)) || existsSync(hlog(h)), false);
|
||||
});
|
||||
|
||||
test("row 240 enforce: each failure exits 0, unloads the profile, closes bwrap, writes DRIFT and one log line", (t) => {
|
||||
for (const [n, fault] of Object.entries(FAULTS)) {
|
||||
const h = host(t);
|
||||
fault(h);
|
||||
const r = run(h, "--enforce");
|
||||
assert.equal(r.status, 0, `item ${n}: ${r.out}${r.err}`);
|
||||
assert.deepEqual(calls(h, "apparmor_parser"), [`-R ${h.root}${PROFILE}`], `item ${n}`);
|
||||
assert.deepEqual(calls(h, "chown"), [`root:root ${h.root}/usr/bin/bwrap`], `item ${n}`);
|
||||
assert.deepEqual(calls(h, "chmod"), [`0700 ${h.root}/usr/bin/bwrap`], `item ${n}`);
|
||||
const d = readFileSync(drift(h), "utf8").split("\n").filter(Boolean);
|
||||
assert.equal(d.length, 1, `item ${n}`);
|
||||
assert.match(d[0], new RegExp(`^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ ${n} `), `item ${n}`);
|
||||
const l = readFileSync(hlog(h), "utf8").split("\n").filter(Boolean);
|
||||
assert.equal(l.length, 1, `item ${n}`);
|
||||
assert.match(l[0], new RegExp(`^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ enforce stop items=${n} drift-before=0 unload=rc=0 chown=0 chmod=0$`), `item ${n}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 240 enforce: with DRIFT present and every item passing, it still closes bwrap", (t) => {
|
||||
const h = host(t);
|
||||
put(drift(h), "2026-10-20T00:00:00Z 1 an earlier drift\n");
|
||||
const r = run(h, "--enforce");
|
||||
assert.equal(r.status, 0);
|
||||
assert.equal(fails(r).length, 0);
|
||||
assert.deepEqual(calls(h, "chown"), [`root:root ${h.root}/usr/bin/bwrap`]);
|
||||
assert.deepEqual(calls(h, "chmod"), [`0700 ${h.root}/usr/bin/bwrap`]);
|
||||
assert.equal(readFileSync(drift(h), "utf8"), "2026-10-20T00:00:00Z 1 an earlier drift\n");
|
||||
assert.match(readFileSync(hlog(h), "utf8"), /Z enforce stop items=none drift-before=1 unload=rc=0 chown=0 chmod=0\n$/);
|
||||
});
|
||||
|
||||
test("row 240 enforce: no unload when aa-status lists neither bwrap profile; never writes the statoverride", (t) => {
|
||||
const h = host(t);
|
||||
aa(h, { "/usr/bin/man": "enforce" });
|
||||
const r = run(h, "--enforce");
|
||||
assert.equal(r.status, 0);
|
||||
assert.deepEqual(calls(h, "apparmor_parser"), []);
|
||||
assert.deepEqual(calls(h, "chmod"), [`0700 ${h.root}/usr/bin/bwrap`]);
|
||||
assert.match(readFileSync(hlog(h), "utf8"), /Z enforce stop items=2 drift-before=0 unload=skipped chown=0 chmod=0\n$/);
|
||||
for (const [n, fault] of Object.entries(FAULTS)) {
|
||||
const g = host(t);
|
||||
fault(g);
|
||||
run(g, "--enforce");
|
||||
for (const a of calls(g, "dpkg-statoverride")) assert.doesNotMatch(a, /--(update|add|remove)/, `item ${n}`);
|
||||
assert.deepEqual(calls(g, "dpkg-statoverride"), ["--list /usr/bin/bwrap"], `item ${n}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("row 240 upstream: a candidate whose profile differs prints the difference and exits 0", (t) => {
|
||||
let h = host(t);
|
||||
put(join(h.hc, "upstream-profile"), `${PROFILE_TEXT} # upstream change\n`);
|
||||
let r = run(h, "--upstream");
|
||||
assert.equal(r.status, 0, r.err);
|
||||
assert.match(r.out, new RegExp(`^upstream: DIFFERS: apparmor-profiles 9.9-upstream's bwrap-userns-restrict has sha256 ${sha256(`${PROFILE_TEXT} # upstream change\n`)}; the pin is ${sha256(PROFILE_TEXT)} from 4.0.1-fixture\\.`));
|
||||
assert.match(r.out, /^\+ {2}# upstream change$/m);
|
||||
assert.deepEqual(calls(h, "apt-get"), ["download apparmor-profiles"]);
|
||||
assert.deepEqual([calls(h, "chown"), calls(h, "chmod"), existsSync(drift(h))], [[], [], false]);
|
||||
h = host(t);
|
||||
r = run(h, "--upstream");
|
||||
assert.equal(r.status, 0);
|
||||
assert.equal(r.out, "upstream: apparmor-profiles 9.9-upstream's bwrap-userns-restrict matches the pin from 4.0.1-fixture\n");
|
||||
h = host(t);
|
||||
rmSync(join(h.hc, "upstream-profile"));
|
||||
r = run(h, "--upstream");
|
||||
assert.equal(r.status, 0);
|
||||
assert.match(r.out, /^upstream: DIFFERS: apparmor-profiles 9.9-upstream has no bwrap-userns-restrict;/);
|
||||
h = host(t);
|
||||
put(join(h.hc, "apt-rc"), "100");
|
||||
r = run(h, "--upstream");
|
||||
assert.equal(r.status, 1);
|
||||
assert.equal(r.err, "hostcheck: upstream: apt-get download apparmor-profiles failed\n");
|
||||
});
|
||||
|
||||
test("row 240 boot unit: a oneshot after apparmor and before the bus that runs --enforce", () => {
|
||||
const text = readFileSync(UNIT, "utf8");
|
||||
const lines = text.split("\n").filter((l) => l && !l.startsWith("#"));
|
||||
assert.deepEqual(lines.filter((l) => /^(Type|After|Before|ExecStart|WantedBy)=/.test(l)), [
|
||||
"After=apparmor.service",
|
||||
"[email protected]",
|
||||
"Type=oneshot",
|
||||
"ExecStart=/usr/local/lib/mosaic-stack/hostcheck.sh --enforce",
|
||||
"WantedBy=multi-user.target",
|
||||
]);
|
||||
});
|
||||
|
||||
test("row 240 pins and usage: the shipped pins are r6's, the script reads the pins beside it, and bad usage exits 2", (t) => {
|
||||
assert.equal(readFileSync(PINS, "utf8").split("\n").filter((l) => /^PIN_/.test(l)).join("\n"),
|
||||
"PIN_PROFILES_VERSION=4.0.1really4.0.1-0ubuntu0.24.04.9\nPIN_PROFILE_SHA256=11d39094f044f0cda0febb3ad517b830301da6b2ce929664af09ee9e4dd264f9\nPIN_BUBBLEWRAP_VERSION=0.9.0-1ubuntu0.3");
|
||||
const h = host(t);
|
||||
const r = run({ ...h, script: SCRIPT }, "--check");
|
||||
assert.equal(r.status, 1);
|
||||
assert.deepEqual(fails(r), [`FAIL 1 ${PROFILE} sha256 is ${sha256(PROFILE_TEXT)}, not the pin 11d39094f044f0cda0febb3ad517b830301da6b2ce929664af09ee9e4dd264f9`]);
|
||||
for (const args of [[], ["--check", "--enforce"], ["--check", "--root", "relative"], ["--status"]]) {
|
||||
const u = spawnSync(h.script, args, { encoding: "utf8", env: { ...process.env, PATH: `${h.bin}:${process.env.PATH}`, HC: h.hc } });
|
||||
assert.equal(u.status, 2, args.join(" "));
|
||||
}
|
||||
if (process.getuid() !== 0) {
|
||||
const u = spawnSync(h.script, ["--check"], { encoding: "utf8", env: { ...process.env, PATH: `${h.bin}:${process.env.PATH}`, HC: h.hc } });
|
||||
assert.deepEqual([u.status, u.stderr], [2, "hostcheck: refusing: run it as root\n"]);
|
||||
}
|
||||
});
|
||||
@@ -1,336 +0,0 @@
|
||||
// Case 2 row C2-20 (#1722): scripts/case2-persona-import.mjs takes Bean's and Chet's personas from
|
||||
// two Hermes profiles into Mosaic persona files. Brief: docs/plans/2026-10-20_case2-rows.md "C2-20".
|
||||
// Every case runs on a scratch copy of fixtures/case2-persona-import/hermes, a scratch staging
|
||||
// directory and a scratch config directory. Nothing here reads or writes ~/.hermes, ~/.mosaic-dev or
|
||||
// ~/.config/mosaic-dev, and no fixture value is real. Fixture strings starting "marker-" must never
|
||||
// reach the script's output.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { chmodSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { PERSONA_CHARS, personaTextFault } from "../../harness/src/bundle.mjs";
|
||||
import { tmp } from "./helpers.mjs";
|
||||
|
||||
const REPO = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
const SCRIPT = join(REPO, "scripts", "case2-persona-import.mjs");
|
||||
const FIXTURE = join(REPO, "packages", "cli", "tests", "fixtures", "case2-persona-import");
|
||||
const TRACE = join(FIXTURE, "trace.mjs");
|
||||
const PAIRS = ["--pair", "default=Bean", "--pair", "chet=Chet"];
|
||||
const sha256 = (data) => createHash("sha256").update(data).digest("hex");
|
||||
const mode = (path) => statSync(path).mode & 0o777;
|
||||
|
||||
// A scratch Hermes home from the fixture, with the two .env files git won't carry, and empty
|
||||
// staging and config parents.
|
||||
function scratch(t) {
|
||||
const root = tmp(t, "mosaic-persona-");
|
||||
const hermes = join(root, "hermes");
|
||||
cpSync(join(FIXTURE, "hermes"), hermes, { recursive: true });
|
||||
writeFileSync(join(hermes, ".env"), "DISCORD_BOT_TOKEN=marker-env-default-3b58\n");
|
||||
writeFileSync(join(hermes, "profiles", "chet", ".env"), "DISCORD_BOT_TOKEN=marker-env-chet-7e44\n");
|
||||
const configDir = join(root, "config");
|
||||
mkdirSync(configDir, { mode: 0o700 });
|
||||
chmodSync(configDir, 0o700);
|
||||
return { root, hermes, configDir, staging: join(root, "staging"), trace: join(root, "trace.log") };
|
||||
}
|
||||
|
||||
function run(argv, { trace } = {}) {
|
||||
const pre = trace ? ["--import", TRACE] : [];
|
||||
const env = { ...process.env, ...(trace ? { PERSONA_TRACE: trace } : {}) };
|
||||
const r = spawnSync(process.execPath, [...pre, SCRIPT, ...argv], { encoding: "utf8", env, timeout: 30_000 });
|
||||
return { status: r.status, out: r.stdout, err: r.stderr, all: r.stdout + r.stderr };
|
||||
}
|
||||
|
||||
const stage = (s, extra = [], opts) => run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--staging", s.staging, ...extra], opts);
|
||||
const install = (s, business = "case2") => run(["install", "--staging", s.staging, "--config-dir", s.configDir, "--business", business]);
|
||||
|
||||
// Every fixture marker and every line of fixture text the script reads.
|
||||
function assertNoText(s, output) {
|
||||
const markers = new Set();
|
||||
const walk = (dir) => {
|
||||
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
||||
const p = join(dir, e.name);
|
||||
if (e.isDirectory()) walk(p);
|
||||
else for (const m of readFileSync(p, "utf8").match(/marker-[a-z]+(?:-[a-z]+)*-[0-9a-f]{4}/g) ?? []) markers.add(m);
|
||||
}
|
||||
};
|
||||
walk(s.hermes);
|
||||
assert.ok(markers.size >= 20, `only ${markers.size} markers found`);
|
||||
for (const m of markers) assert.ok(!output.includes(m), `output holds ${m}`);
|
||||
for (const line of ["You speak warmly", "Dry humour", "Help with the novel", "Ünïcode prompt"]) {
|
||||
assert.ok(!output.includes(line), `output holds "${line}"`);
|
||||
}
|
||||
}
|
||||
|
||||
function personaTree(s, { bean, chet }) {
|
||||
if (bean !== undefined) writeFileSync(join(s.hermes, "SOUL.md"), bean);
|
||||
if (chet !== undefined) writeFileSync(join(s.hermes, "profiles", "chet", "SOUL.md"), chet);
|
||||
}
|
||||
|
||||
test("stage takes each profile's SOUL.md byte for byte and prints the pairing with sizes and digests", (t) => {
|
||||
const s = scratch(t);
|
||||
const bean = readFileSync(join(s.hermes, "SOUL.md"));
|
||||
const chet = readFileSync(join(s.hermes, "profiles", "chet", "SOUL.md"));
|
||||
const r = stage(s);
|
||||
assert.equal(r.status, 0, r.all);
|
||||
assert.deepEqual(readFileSync(join(s.staging, "bean.md")), bean);
|
||||
assert.deepEqual(readFileSync(join(s.staging, "chet.md")), chet);
|
||||
assert.ok(r.out.includes(`pairing: profile default is Bean (instance bean), SOUL.md ${bean.length} bytes, sha256 ${sha256(bean)}`), r.out);
|
||||
assert.ok(r.out.includes(`pairing: profile chet is Chet (instance chet), SOUL.md ${chet.length} bytes, sha256 ${sha256(chet)}`), r.out);
|
||||
// The pairing comes before the first file written.
|
||||
assert.ok(r.out.indexOf("pairing:") < r.out.indexOf("staged:"), r.out);
|
||||
const manifest = JSON.parse(readFileSync(join(s.staging, "manifest.json"), "utf8"));
|
||||
assert.deepEqual(manifest, {
|
||||
version: 1,
|
||||
personas: [
|
||||
{ instance: "bean", name: "Bean", bytes: bean.length, sha256: sha256(bean) },
|
||||
{ instance: "chet", name: "Chet", bytes: chet.length, sha256: sha256(chet) },
|
||||
],
|
||||
});
|
||||
assert.match(r.out, /next, as root: give .* to <user>/);
|
||||
assertNoText(s, r.all);
|
||||
});
|
||||
|
||||
// gateway/config.py at hermes-agent df5700ebe: a platform's block is <platform> at the top level
|
||||
// (:1159), else platforms.<platform> or gateway.platforms.<platform> (:1172-1178), and the prompts are
|
||||
// its channel_prompts (:1233). The fixture config.yaml has one of each.
|
||||
test("stage lists the per-channel prompts in all three places by name and byte count only", (t) => {
|
||||
const s = scratch(t);
|
||||
const r = stage(s);
|
||||
assert.equal(r.status, 0, r.all);
|
||||
const lines = r.out.split("\n").filter((l) => l.includes(": per-channel prompt "));
|
||||
assert.deepEqual(lines, [
|
||||
`profile default: per-channel prompt discord 111111111111111111, ${Buffer.byteLength("marker-prompt-top-5d02 Help with the novel.")} bytes`,
|
||||
`profile default: per-channel prompt discord 222222222222222222, ${Buffer.byteLength("Ünïcode prompt")} bytes`,
|
||||
// Unquoted in the fixture, and past 2 ** 53: the id prints exactly.
|
||||
"profile default: per-channel prompt discord 1333333333333333333, 5 bytes",
|
||||
`profile default: per-channel prompt platforms.slack C0FIXTURE, ${Buffer.byteLength("marker-prompt-platforms-8e3a")} bytes`,
|
||||
"profile default: per-channel prompt gateway.platforms.telegram -1001, 29 bytes",
|
||||
"profile default: per-channel prompt gateway.platforms.telegram -1002, not text",
|
||||
]);
|
||||
assert.ok(r.out.includes("profile chet: no per-channel prompts"), r.out);
|
||||
assertNoText(s, r.all);
|
||||
});
|
||||
|
||||
test("a read trace shows stage and the dry run open SOUL.md and config.yaml and never memory, sessions or secrets", (t) => {
|
||||
const s = scratch(t);
|
||||
for (const argv of [["--staging", s.staging], ["--dry-run"]]) {
|
||||
rmSync(s.trace, { force: true });
|
||||
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, ...argv], { trace: s.trace });
|
||||
assert.equal(r.status, 0, r.all);
|
||||
const opened = readFileSync(s.trace, "utf8").split("\n").filter(Boolean).map((l) => l.slice(l.indexOf(" ") + 1)).filter((p) => p.startsWith(s.hermes));
|
||||
// The control: the trace sees the reads the script does make.
|
||||
assert.ok(opened.includes(join(s.hermes, "SOUL.md")), opened.join("\n"));
|
||||
assert.ok(opened.includes(join(s.hermes, "profiles", "chet", "SOUL.md")), opened.join("\n"));
|
||||
const allowed = new Set([
|
||||
join(s.hermes, "SOUL.md"), join(s.hermes, "config.yaml"),
|
||||
join(s.hermes, "profiles", "chet", "SOUL.md"), join(s.hermes, "profiles", "chet", "config.yaml"),
|
||||
]);
|
||||
for (const p of opened) assert.ok(allowed.has(p), `opened ${p}`);
|
||||
if (argv[0] === "--dry-run") assert.ok(!opened.some((p) => p.endsWith("config.yaml")), "the dry run read config.yaml");
|
||||
else assert.ok(opened.includes(join(s.hermes, "config.yaml")), opened.join("\n"));
|
||||
}
|
||||
});
|
||||
|
||||
test("the pairing refuses anything but two existing profiles naming Bean and Chet once each, and writes nothing", (t) => {
|
||||
const s = scratch(t);
|
||||
const cases = [
|
||||
[["--pair", "default=Bean", "--pair", "chet=Bob"], 1, /profile chet names "Bob", not Bean or Chet/],
|
||||
[["--pair", "default=bean", "--pair", "chet=Chet"], 1, /names "bean", not Bean or Chet/],
|
||||
[["--pair", "default=Bean", "--pair", "chet=Bean"], 1, /Bean is named twice/],
|
||||
[["--pair", "chet=Bean", "--pair", "chet=Chet"], 1, /profile chet is paired twice/],
|
||||
[["--pair", "default=Bean", "--pair", "nobody=Chet"], 1, /profile nobody: .* doesn't exist/],
|
||||
[["--pair", "default=Bean", "--pair", "../chet=Chet"], 1, /isn't a Hermes profile name/],
|
||||
[["--pair", "default=Bean"], 2, /exactly two --pair/],
|
||||
[["--pair", "default=Bean", "--pair", "chet=Chet", "--pair", "x=Chet"], 2, /exactly two --pair/],
|
||||
];
|
||||
for (const [pairs, status, message] of cases) {
|
||||
const r = run(["stage", "--hermes-root", s.hermes, ...pairs, "--staging", s.staging]);
|
||||
assert.equal(r.status, status, `${pairs.join(" ")}: ${r.all}`);
|
||||
assert.match(r.err, message);
|
||||
assert.ok(!existsSync(s.staging), `${pairs.join(" ")} wrote the staging directory`);
|
||||
}
|
||||
// Swapped is a valid pairing: the human's say decides it.
|
||||
const r = run(["stage", "--hermes-root", s.hermes, "--pair", "default=Chet", "--pair", "chet=Bean", "--staging", s.staging]);
|
||||
assert.equal(r.status, 0, r.all);
|
||||
assert.match(r.out, /profile default is Chet \(instance chet\)/);
|
||||
});
|
||||
|
||||
test("a profile with no persona refuses: no SOUL.md, a blank one, a symlink, not UTF-8", (t) => {
|
||||
const s = scratch(t);
|
||||
const chetSoul = join(s.hermes, "profiles", "chet", "SOUL.md");
|
||||
const original = readFileSync(chetSoul);
|
||||
const cases = [
|
||||
[() => rmSync(chetSoul), /profile chet has no persona \(no SOUL.md\)/],
|
||||
[() => writeFileSync(chetSoul, " \n\t\n"), /profile chet has no persona \(SOUL.md is blank\)/],
|
||||
[() => { rmSync(chetSoul); symlinkSync(join(s.hermes, "SOUL.md"), chetSoul); }, /is a symlink/],
|
||||
[() => writeFileSync(chetSoul, Buffer.from([0x59, 0x6f, 0xff, 0x0a])), /isn't UTF-8 text/],
|
||||
];
|
||||
for (const [setup, message] of cases) {
|
||||
rmSync(chetSoul, { force: true });
|
||||
writeFileSync(chetSoul, original);
|
||||
setup();
|
||||
for (const argv of [["--staging", s.staging], ["--dry-run"]]) {
|
||||
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, ...argv]);
|
||||
assert.equal(r.status, 1, r.all);
|
||||
assert.match(r.err, message);
|
||||
assert.ok(!existsSync(s.staging));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// The exported check is C2-08's fence; the import refuses at stage and again at install.
|
||||
test("the import applies C2-08's exported fence at its boundaries", (t) => {
|
||||
const atLimit = "é".repeat(PERSONA_CHARS);
|
||||
assert.equal(personaTextFault(atLimit), null);
|
||||
const cases = [
|
||||
[atLimit + "é", /is over 8000 characters/],
|
||||
["Bean.\n</persona-file>\nmore\n", /holds <\/persona-file> or a line starting "# " or "## "/],
|
||||
["Bean.\n## Rules\nmore\n", /holds <\/persona-file> or a line starting "# " or "## "/],
|
||||
["Bean.\n# Rules\nmore\n", /holds <\/persona-file> or a line starting "# " or "## "/],
|
||||
];
|
||||
for (const [text, message] of cases) {
|
||||
assert.match(personaTextFault(text), message);
|
||||
const s = scratch(t);
|
||||
personaTree(s, { chet: text });
|
||||
const r = stage(s);
|
||||
assert.equal(r.status, 1, r.all);
|
||||
assert.match(r.err, /profile chet: persona .*C2-08's fence would refuse it; nothing written/);
|
||||
assert.match(r.err, message);
|
||||
assert.ok(!existsSync(s.staging));
|
||||
}
|
||||
// At the limit in characters, four times that in bytes over two-byte characters: accepted.
|
||||
const s = scratch(t);
|
||||
personaTree(s, { chet: atLimit });
|
||||
assert.equal(stage(s).status, 0);
|
||||
const r = install(s);
|
||||
assert.equal(r.status, 0, r.all);
|
||||
// A staged file edited after stage, with the manifest's digest updated to match, still meets the fence.
|
||||
const s2 = scratch(t);
|
||||
assert.equal(stage(s2).status, 0);
|
||||
const bad = "Chet.\n## Rules\n";
|
||||
writeFileSync(join(s2.staging, "chet.md"), bad);
|
||||
chmodSync(join(s2.staging, "chet.md"), 0o600);
|
||||
const manifestPath = join(s2.staging, "manifest.json");
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
||||
manifest.personas[1].sha256 = sha256(bad);
|
||||
writeFileSync(manifestPath, JSON.stringify(manifest));
|
||||
const ri = install(s2);
|
||||
assert.equal(ri.status, 1, ri.all);
|
||||
assert.match(ri.err, /staged persona chet holds <\/persona-file> or a line starting/);
|
||||
assert.ok(!existsSync(join(s2.configDir, "personas", "case2", "bean.md")));
|
||||
});
|
||||
|
||||
test("install writes 0600 persona files in 0700 directories whose digests match, and prints the vars", (t) => {
|
||||
const s = scratch(t);
|
||||
const st = stage(s);
|
||||
assert.equal(st.status, 0, st.all);
|
||||
assert.equal(mode(s.staging), 0o700);
|
||||
for (const f of ["bean.md", "chet.md", "manifest.json"]) assert.equal(mode(join(s.staging, f)), 0o600, f);
|
||||
const r = install(s);
|
||||
assert.equal(r.status, 0, r.all);
|
||||
const dir = join(s.configDir, "personas", "case2");
|
||||
assert.equal(mode(join(s.configDir, "personas")), 0o700);
|
||||
assert.equal(mode(dir), 0o700);
|
||||
for (const [instance, name, src] of [["bean", "Bean", join(s.hermes, "SOUL.md")], ["chet", "Chet", join(s.hermes, "profiles", "chet", "SOUL.md")]]) {
|
||||
const path = join(dir, `${instance}.md`);
|
||||
assert.equal(mode(path), 0o600);
|
||||
const data = readFileSync(path);
|
||||
assert.deepEqual(data, readFileSync(src));
|
||||
assert.ok(r.out.includes(`instance ${instance}: persona.name ${name}, persona.sha256 ${sha256(data)}`), r.out);
|
||||
}
|
||||
assertNoText(s, st.all + r.all);
|
||||
});
|
||||
|
||||
test("install refuses an open or foreign staging file, a digest off the manifest and an existing persona", (t) => {
|
||||
const s = scratch(t);
|
||||
assert.equal(stage(s).status, 0);
|
||||
const chet = join(s.staging, "chet.md");
|
||||
chmodSync(chet, 0o640);
|
||||
let r = install(s);
|
||||
assert.equal(r.status, 1, r.all);
|
||||
assert.match(r.err, /staged persona chet: .* has group or other mode bits/);
|
||||
chmodSync(chet, 0o600);
|
||||
chmodSync(s.staging, 0o750);
|
||||
r = install(s);
|
||||
assert.match(r.err, /staging has group or other mode bits/);
|
||||
chmodSync(s.staging, 0o700);
|
||||
|
||||
writeFileSync(chet, "You are someone else.\n");
|
||||
r = install(s);
|
||||
assert.equal(r.status, 1, r.all);
|
||||
assert.match(r.err, /staged persona chet isn't the file the manifest names/);
|
||||
assert.ok(!existsSync(join(s.configDir, "personas", "case2", "bean.md")), "bean was written before chet was checked");
|
||||
|
||||
const s2 = scratch(t);
|
||||
assert.equal(stage(s2).status, 0);
|
||||
const dir = join(s2.configDir, "personas", "case2");
|
||||
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
||||
chmodSync(join(s2.configDir, "personas"), 0o700);
|
||||
writeFileSync(join(dir, "chet.md"), "already here\n", { mode: 0o600 });
|
||||
r = install(s2);
|
||||
assert.equal(r.status, 1, r.all);
|
||||
assert.match(r.err, /chet.md already exists; nothing written/);
|
||||
assert.equal(readFileSync(join(dir, "chet.md"), "utf8"), "already here\n");
|
||||
assert.ok(!existsSync(join(dir, "bean.md")));
|
||||
|
||||
for (const business of ["../x", "Case2", ""]) {
|
||||
r = install(s2, business);
|
||||
assert.notEqual(r.status, 0, business);
|
||||
}
|
||||
const s3 = scratch(t);
|
||||
assert.equal(stage(s3).status, 0);
|
||||
writeFileSync(join(s3.staging, "manifest.json"), JSON.stringify({ version: 1, personas: [{ instance: "bob", name: "Bob" }] }));
|
||||
r = install(s3);
|
||||
assert.equal(r.status, 1, r.all);
|
||||
assert.match(r.err, /the manifest doesn't list two personas/);
|
||||
});
|
||||
|
||||
test("--dry-run writes nothing and prints only counts, two heading lines in a fixture counted", (t) => {
|
||||
const s = scratch(t);
|
||||
personaTree(s, { chet: "You are Chet. marker-chet-dry-7d21\n# Voice\nShort.\r\n## Habits\nNot # a heading, nor #nospace.\n" });
|
||||
const before = readdirSync(s.root).sort();
|
||||
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--dry-run"]);
|
||||
assert.equal(r.status, 0, r.all);
|
||||
assert.deepEqual(readdirSync(s.root).sort(), before);
|
||||
assert.deepEqual(r.out.split("\n").filter(Boolean), [
|
||||
"files 2",
|
||||
'profile default: lines 3, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 0',
|
||||
'profile chet: lines 5, lines starting "# " or "## " 2, lines naming a Hermes tool or channel 0',
|
||||
]);
|
||||
assert.equal(r.err, "");
|
||||
assertNoText(s, r.all);
|
||||
assert.ok(!r.all.includes("Voice") && !r.all.includes("Habits"));
|
||||
});
|
||||
|
||||
test("--dry-run counts three lines naming a Hermes tool or channel and prints none of the words", (t) => {
|
||||
const s = scratch(t);
|
||||
personaTree(s, {
|
||||
bean: [
|
||||
"You are Bean.",
|
||||
"Use web_search when she asks for facts.",
|
||||
"You live on Discord, in her server.",
|
||||
"Keep a TODO list for her chapters.",
|
||||
"Web searching and discords of music don't count, nor memory_bank.",
|
||||
"",
|
||||
].join("\n"),
|
||||
});
|
||||
const r = run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--dry-run"]);
|
||||
assert.equal(r.status, 0, r.all);
|
||||
assert.match(r.out, /profile default: lines 5, lines starting "# " or "## " 0, lines naming a Hermes tool or channel 3/);
|
||||
for (const word of ["web_search", "Discord", "discord", "TODO", "todo", "memory"]) assert.ok(!r.all.includes(word), `output holds ${word}`);
|
||||
});
|
||||
|
||||
test("usage: stage needs one of --staging and --dry-run, install takes only its own options", (t) => {
|
||||
const s = scratch(t);
|
||||
assert.equal(run(["stage", "--hermes-root", s.hermes, ...PAIRS]).status, 2);
|
||||
assert.equal(run(["stage", "--hermes-root", s.hermes, ...PAIRS, "--staging", s.staging, "--dry-run"]).status, 2);
|
||||
assert.equal(run(["stage", ...PAIRS, "--dry-run"]).status, 2);
|
||||
assert.equal(run(["install", "--staging", s.staging, "--config-dir", s.configDir]).status, 2);
|
||||
assert.equal(run(["install", "--staging", s.staging, "--config-dir", s.configDir, "--business", "case2", "--dry-run"]).status, 2);
|
||||
assert.equal(run(["import"]).status, 2);
|
||||
assert.equal(run(["stage", "--bogus", "x"]).status, 2);
|
||||
assert.ok(!existsSync(s.staging));
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
Fixture Hermes home for packages/cli/tests/case2-persona-import.test.mjs (row 221, C2-20).
|
||||
The layout follows hermes-agent df5700ebe: the default profile is the root, other profiles sit under
|
||||
profiles/<name>, each persona is SOUL.md and channel prompts are in config.yaml. Every value is made up.
|
||||
Strings starting "marker-" must never reach the script's output, and files under memories/, sessions/
|
||||
and skills/, state.db, profile.yaml, auth.json and .env (the test writes .env, which git ignores) must never be opened.
|
||||
@@ -1,3 +0,0 @@
|
||||
You are Bean. marker-bean-soul-71c4
|
||||
You speak warmly and keep replies short.
|
||||
You like sketches, coffee and long walks.
|
||||
@@ -1 +0,0 @@
|
||||
{"token": "marker-auth-default-6e21"}
|
||||
@@ -1,21 +0,0 @@
|
||||
model:
|
||||
default: marker-model-name-2b91
|
||||
provider: openrouter
|
||||
discord:
|
||||
require_mention: true
|
||||
channel_prompts:
|
||||
"111111111111111111": "marker-prompt-top-5d02 Help with the novel."
|
||||
"222222222222222222": "Ünïcode prompt"
|
||||
1333333333333333333: "short"
|
||||
platforms:
|
||||
slack:
|
||||
channel_prompts:
|
||||
C0FIXTURE: "marker-prompt-platforms-8e3a"
|
||||
gateway:
|
||||
platforms:
|
||||
telegram:
|
||||
channel_prompts:
|
||||
"-1001": "marker-prompt-gateway-0f6b ok"
|
||||
"-1002":
|
||||
nested: not a string
|
||||
api_key: marker-token-default-9a17
|
||||
@@ -1 +0,0 @@
|
||||
marker-memory-default-1f8e
|
||||
@@ -1 +0,0 @@
|
||||
description: marker-profile-description-44de
|
||||
@@ -1,2 +0,0 @@
|
||||
You are Chet. marker-chet-soul-38e0
|
||||
Dry humour, quick with a pun.
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
model:
|
||||
default: marker-model-chet-6d13
|
||||
-1
@@ -1 +0,0 @@
|
||||
marker-memory-chet-d913
|
||||
-1
@@ -1 +0,0 @@
|
||||
description: marker-profile-chet-0c55
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
{"text": "marker-session-chet-08bc"}
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
marker-skill-chet-6a70
|
||||
-1
@@ -1 +0,0 @@
|
||||
marker-state-chet-52aa
|
||||
-1
@@ -1 +0,0 @@
|
||||
{"text": "marker-session-default-a4b2"}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user