salvage 2026-11-06: uncommitted work from scratch/darkwing-scratch/r137/wt (disk cleanup #824)

This commit is contained in:
mos committed 2026-11-06 10:03:20 -06:00
1 parent 7a2987cf51
commit ace2cb9e20
27 files changed
+1229 -255

No files matched your search

+17 -35
View File
@@ -164,22 +164,14 @@ pdiff "$TARGET" "$MB" "$C" > "$SCRATCH/reviewed.patch"
[ -s "$SCRATCH/reviewed.patch" ] || refuse base-conflict "the reviewed diff $MB..$C is empty"
REVIEWED_ID="$(git -C "$TARGET" patch-id --stable < "$SCRATCH/reviewed.patch" | cut -d' ' -f1)"
# Invariant 1: nothing new at the root. A top-level file, a top-level
# directory the base doesn't have, and the legacy src/ and archived v1/
# trees all count as the root.
mapfile -d '' -t ADDED < <(git -C "$TARGET" diff -z --no-renames --name-only --diff-filter=A "$MB" "$C")
mapfile -d '' -t TOP < <(git -C "$TARGET" ls-tree -z --name-only "$OLD")
ROOT_HITS=""
for f in "${ADDED[@]}"; do
case "$f" in
*/*) top="${f%%/*}" ;;
*) ROOT_HITS="$ROOT_HITS $f"; continue ;;
esac
known="no"
for t in "${TOP[@]}"; do [ "$t" = "$top" ] && known="yes" && break; done
if [ "$known" = "no" ] || [ "$top" = "src" ] || [ "$top" = "v1" ]; then ROOT_HITS="$ROOT_HITS $f"; fi
done
[ -z "$ROOT_HITS" ] || refuse root-file "the reviewed diff adds$ROOT_HITS"
# Invariant 1: nothing new at the root. The rule is rootHits in
# packages/seat/src/landing.mjs, which the bus host's landings share.
git -C "$TARGET" diff -z --no-renames --name-only --diff-filter=A "$MB" "$C" > "$SCRATCH/added"
git -C "$TARGET" ls-tree -z --name-only "$OLD" > "$SCRATCH/top"
ROOT_RC=0
node "$REPO/packages/seat/src/landing.mjs" root-file "$SCRATCH/top" "$SCRATCH/added" > "$SCRATCH/root-hits" || ROOT_RC=$?
[ "$ROOT_RC" -ne 2 ] || refuse root-file "the reviewed diff adds $(tr '\n' ' ' < "$SCRATCH/root-hits" | sed 's/ $//')"
[ "$ROOT_RC" -eq 0 ] || fail "the root-file check could not run (exit $ROOT_RC)"
mapfile -d '' -t PATHS < <(git -C "$TARGET" diff -z --no-renames --name-only "$MB" "$C")
# Paths go to git as they are, never as globs or pathspec magic.
@@ -214,25 +206,15 @@ echo "land-work: gate logs in $LOGS" >&2
# to shorten or skip it.
[ -d "$TARGET/node_modules" ] || fail "no node_modules in $TARGET for the gate" 4
ln -s "$TARGET/node_modules" "$WT/node_modules"
gate_step() { # name dir command
local rc=0
(cd "$WT/$2" && bash -c "set -o pipefail; $3") > "$LOGS/$1.log" 2>&1 || rc=$?
echo "$1 rc=$rc $(grep -E '^ℹ (pass|fail) [0-9]+' "$LOGS/$1.log" | tr '\n' ' ')" | tee -a "$LOGS/gate.log" >&2
[ "$rc" -eq 0 ] || refuse gate-failed "$1, see $LOGS/$1.log"
}
# No pkg-queue step: scripts/test-queue.sh runs packages/queue/tests/ itself.
for d in "$WT"/packages/*/; do
p="$(basename "$d")"
[ -d "$d/tests" ] || continue
[ "$p" = queue ] && continue
gate_step "pkg-$p" "packages/$p" 'node --test tests/*.test.mjs'
done
for s in "$WT"/scripts/test-*.sh; do
[ -f "$s" ] || continue
n="$(basename "$s" .sh)"
gate_step "script-${n#test-}" . "bash scripts/$n.sh"
done
echo "GATE_PASSED" | tee -a "$LOGS/gate.log" >&2
# The steps, their logs and the summary lines are runGate's in
# packages/seat/src/landing.mjs, which the bus host's landings share.
GATE_RC=0
node "$REPO/packages/seat/src/landing.mjs" gate "$WT" "$LOGS" > "$SCRATCH/gate.out" || GATE_RC=$?
if [ "$GATE_RC" -eq 2 ] && [ -s "$SCRATCH/gate.out" ]; then
line="$(head -n1 "$SCRATCH/gate.out")"
refuse gate-failed "${line%% *}, see ${line#* }"
fi
[ "$GATE_RC" -eq 0 ] || fail "the gate could not run (exit $GATE_RC)"
# ---- the commit ----
SHORT_ID="${REVIEWED_ID:0:12}"
+11 -124
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env node
// land-work's read of the bus (row 116, #1610). Every query land-work runs
// against bus.sqlite is in this file, and every one is a SELECT.
// land-work's read of the bus (row 116, #1610). The checks themselves are in
// packages/bus/src/landing.mjs, which the broker's agent landings share
// (row 137, #1631); every query there is a SELECT.
//
// node scripts/land-work/read.mjs <dataRoot> <business-file> <decision-id> <base>
//
@@ -17,27 +18,10 @@ import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { createHash } from 'node:crypto';
import { schemaDigest, SCHEMA_SHA256, SCHEMA_VERSION } from '../../packages/bus/src/store.mjs';
import { LandingRefusal, readLanding as shared } from '../../packages/bus/src/landing.mjs';
const MERGE = 'git.merge.protected';
const WORK_REF = /^work\/vikunja-([1-9][0-9]*)-([1-9][0-9]*)$/;
const ANY_WORK_REF = /\bwork\/[A-Za-z0-9._/-]*[A-Za-z0-9_]/g;
const OID = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
class Refusal extends Error {
constructor(reason, detail) {
super(detail);
this.reason = reason;
}
}
const refuse = (reason, detail) => {
throw new Refusal(reason, detail);
};
const json = (text) => {
try {
return JSON.parse(text);
} catch {
return null;
}
throw new LandingRefusal(reason, detail);
};
export function openBus(dataRoot) {
@@ -82,109 +66,12 @@ export function checkSchema(db) {
refuse('bus-schema', `meta says version ${meta('schema_version')}, digest ${String(meta('schema_digest')).slice(0, 12)}`);
}
// The queries. Each takes the business so one bus can't answer for another.
const queries = {
decision: (db, b, id) => db.prepare('SELECT * FROM decisions WHERE business = ? AND id = ?').get(b, id),
raise: (db, b, id) =>
db
.prepare(
`SELECT * FROM events WHERE business = ? AND kind = 'action.allowed' AND subject = ?
AND json_extract(body, '$.operation') = 'decision.raise' AND json_extract(body, '$.decision') = ?
ORDER BY seq`,
)
.all(b, id, id),
closes: (db, id) =>
db
.prepare(
`SELECT * FROM decision_events WHERE decision = ? AND op IN ('resolved','withdrawn','expired') ORDER BY seq`,
)
.all(id),
answer: (db, b, id) =>
db
.prepare(
`SELECT * FROM events WHERE business = ? AND kind = 'human.input' AND subject = ?
AND json_extract(body, '$.kind') = 'answer' AND json_extract(body, '$.decision') = ?
AND json_extract(body, '$.op') = 'resolved'
ORDER BY seq`,
)
.all(b, id, id),
later: (db, b, d) =>
db
.prepare(
`SELECT * FROM decisions WHERE business = ? AND id <> ?
AND (supersedes = ? OR (seq > ? AND action = ?)) ORDER BY seq`,
)
.all(b, d.id, d.id, d.seq, MERGE),
verdict: (db, b, task) =>
db
.prepare(`SELECT * FROM events WHERE business = ? AND kind = 'review.verdict' AND subject = ? ORDER BY seq DESC LIMIT 1`)
.get(b, task),
};
// land-work lands only on refactor (#1610): the base it was given must be
// refactor, and the raise must target it.
export function readLanding(db, business, id, base) {
const b = business.id;
const d = queries.decision(db, b, id);
const raises = queries.raise(db, b, id);
if (!d || raises.length !== 1) refuse('decision-not-found', `no decision ${id} with one raise in business ${b}`);
const raise = json(raises[0].body) ?? {};
if (d.action !== MERGE || raise.action !== MERGE) refuse('not-a-merge', `action ${d.action}`);
const closes = queries.closes(db, id);
if (closes.length !== 1 || closes[0].op !== 'resolved')
refuse('not-resolved', closes.length ? closes.map((r) => r.op).join(',') : 'open');
const res = closes[0];
const answers = queries.answer(db, b, id);
const answer = answers.length === 1 ? answers[0] : null;
if (
res.by !== business.human ||
res.via !== 'cli' ||
!answer ||
answer.actor_role !== null ||
answer.actor_run !== null ||
json(answer.body)?.choice !== res.choice
)
refuse('not-human', `resolved by ${res.by} via ${res.via}, ${answers.length} human answer(s)`);
const options = json(d.options) ?? [];
const merge = options.find((o) => o?.key === raise.approvalChoice);
if (!raise.approvalChoice || !merge) refuse('not-merge-option', 'the raise names no approval option');
if (res.choice !== raise.approvalChoice)
refuse('not-merge-option', `chose ${res.choice}, the merge option is ${raise.approvalChoice}`);
// The work ref comes from the question: decisions don't carry it.
const named = [...new Set(d.question.match(ANY_WORK_REF) ?? [])];
const m = named.length === 1 ? WORK_REF.exec(named[0]) : null;
if (!m) refuse('work-ref', `the question names ${named.join(', ') || 'no work ref'}`);
const workRef = named[0];
const task = `vikunja:${m[1]}/${m[2]}`;
for (const ref of [d.task_ref, raise.task_ref])
if (ref != null && ref !== task) refuse('work-ref', `the decision cites ${ref}, the question ${workRef}`);
// The target is the raise's, and only refactor ever lands.
if (raise.target !== 'refactor' || raise.target !== base)
refuse('target-branch', `the raise targets ${raise.target}, the base is ${base}`);
const later = queries.later(db, b, d).filter(
(r) => r.supersedes === id || r.task_ref === task || (r.question.match(ANY_WORK_REF) ?? []).includes(workRef),
);
if (later.length) refuse('superseded', `later decision ${later.map((r) => r.id).join(', ')} on ${workRef}`);
const v = queries.verdict(db, b, task);
if (!v) refuse('no-verdict', `no review.verdict for ${task}`);
const vb = json(v.body) ?? {};
if (vb.verdict !== 'approve' || vb.task_ref !== task || !OID.test(vb.commit ?? ''))
refuse('not-approved', `latest verdict ${v.id} is ${vb.verdict} on ${vb.commit}`);
return {
task_ref: task,
work_ref: workRef,
commit: vb.commit,
verdict: v.id,
project: d.project ?? '',
choice: res.choice,
by: res.by,
resolved_at: res.at,
subject: String(merge.text ?? '').split('\n')[0].trim(),
};
if (base !== 'refactor') refuse('target-branch', `the base is ${base}, land-work lands only on refactor`);
const q = { get: (sql, ...p) => db.prepare(sql).get(...p), all: (sql, ...p) => db.prepare(sql).all(...p) };
return shared(q, business, id, { into: 'refactor' });
}
function main([dataRoot, businessFile, id, base]) {
@@ -206,7 +93,7 @@ function main([dataRoot, businessFile, id, base]) {
for (const [k, v] of Object.entries(readLanding(db, business, id, base))) out(k, v);
return 0;
} catch (e) {
if (e instanceof Refusal) {
if (e instanceof LandingRefusal) {
out('refuse', `${e.reason}\t${e.message}`);
return 2;
}