feat(wait): a run's end, for the background beside a detached run
A run launched detached, as the prepush skill says, tells the session nothing when it ends: a round finished unread for hours. `crafter-review wait --artifact <artifact> --hash <hash>`, the two values of the run line, follows the hash's run lock. A full run holds it until it ends; taking it, the run now clears the last run's identity there, and it names itself with its run number once it has one. When a run the wait has seen hold or take the lock lets it go, the wait reads the identity - under its own instant shared hold, so never a rewrite in flight - prints the summary of the final dump of the run the identity names and exits with the code its verdict maps to, as run's does: 2 when there is no final dump or no run number, 3 with the message of a preflight check that stopped the run after it took the lock, which the run adds to the identity. A wait that sees no run within --appear (120 s by default) exits 3. Every probe of the lock, a test or dry run's too, takes it shared for an instant, and the run lock is tried for 200 ms before another driver counts as its holder. A wait only reads: one that is stopped is started again and the run goes on. freeze prints the wait line before the run line, and the skill and the process start the wait in the background, then launch the run detached. Released as 1.2.0.
This commit is contained in:
parent
ad33242609
commit
4318c7d8f2
15 changed files with 607 additions and 33 deletions
|
|
@ -5,8 +5,12 @@
|
|||
// refreshes, keeps what it did not write, replaces the old link into the
|
||||
// submodule, refuses a foreign link, a subdirectory and the home directory
|
||||
// before it writes anything), doc, stop (a scratch dir, --hash on the
|
||||
// board), seats on a claude stand-in, and browser's usage.
|
||||
// board), --version, wait (a run's end at the hash's run lock), seats on a
|
||||
// claude stand-in, and browser's usage.
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
import std;
|
||||
import Crafter.Review;
|
||||
|
|
@ -66,7 +70,7 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"ok","total
|
|||
}
|
||||
|
||||
std::int32_t Checks() {
|
||||
std::println("commands: init, doc, stop, seats on a claude stand-in, browser's usage");
|
||||
std::println("commands: init, doc, stop, --version, wait, seats on a claude stand-in, browser's usage");
|
||||
Platform::SetMode(Platform::Mode::Native);
|
||||
const fs::path checkout = fs::current_path();
|
||||
SetHome(checkout);
|
||||
|
|
@ -316,6 +320,265 @@ echo '{"type":"result","subtype":"success","is_error":false,"result":"ok","total
|
|||
Check("stop --hash: every live run of the hash on the board gets its stop file (the first 8 characters decide); another hash finds none (exit 1); the board is read, never written",
|
||||
byHash.returnCode == 0 && wroteHash && otherHash.returnCode == 1 && otherHash.err.contains("no live run of 00000000 on the board") && Read(base / "board.json") == boardBefore,
|
||||
byHash.out + byHash.err + otherHash.err);
|
||||
// --version: the driver, the home, every charter's sha256.
|
||||
const Process::Captured version = Self({"--version"}, base);
|
||||
std::int64_t charters = 0;
|
||||
bool chartersHashed = true;
|
||||
for (const fs::directory_entry& entry : fs::directory_iterator(checkout / "process" / "lenses")) {
|
||||
if (entry.path().extension() != ".md") continue;
|
||||
++charters;
|
||||
chartersHashed = chartersHashed && version.out.contains(std::format("charter {} {}\n", entry.path().filename().string(), Sha256Hex(Read(entry.path()))));
|
||||
}
|
||||
Check("--version: the home and every charter's sha256", version.returnCode == 0 && version.out.contains(std::format("home {}\n", checkout.string())) && charters > 0 && chartersHashed,
|
||||
version.out);
|
||||
// wait (1.2.0): a run's end, for the background beside a detached
|
||||
// run, read from the hash's run lock and the run's dump. This process
|
||||
// stands in for the run's driver on a thread while the wait runs: it
|
||||
// holds the lock, names a run in it, writes the dump, lets the lock go.
|
||||
auto artifactOf = [&](std::string_view name) {
|
||||
const fs::path art = base / "waits" / name;
|
||||
fs::create_directories(art / "gate-state");
|
||||
return art;
|
||||
};
|
||||
auto dumpOf = [](std::string_view h8, std::int64_t n, std::string_view overall) {
|
||||
return Json {{"overall", overall}, {"results", Json::array()}, {"dumpPath", std::format("gate-state/commits-{}-run-{}.json", h8, n)}};
|
||||
};
|
||||
auto identity = [&](std::int64_t n) {
|
||||
return Json {{"pid", 4242}, {"since", std::format("2026-11-02T22:00:0{}", n)}, {"scratch", (base / "scratch" / std::format("x-run-{}", n)).string()}, {"run_n", n}};
|
||||
};
|
||||
auto waitOn = [&](const fs::path& art, std::string_view hash, std::vector<std::string> extra = {}) {
|
||||
std::vector<std::string> argv = {"wait", "--artifact", art.string(), "--hash", std::string(hash)};
|
||||
std::ranges::move(extra, std::back_inserter(argv));
|
||||
return Self(argv, base);
|
||||
};
|
||||
// A run live when the wait begins, ending with its final dump.
|
||||
const fs::path artA = artifactOf("a");
|
||||
const Json dumpA = dumpOf("beefa001", 1, "SEND-READY");
|
||||
auto lockA = std::make_unique<State::RunLock>(artA / "gate-state", "commits", "beefa001");
|
||||
lockA->WriteInfo(identity(1));
|
||||
std::jthread endA([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
Write(artA / "gate-state" / "commits-beefa001-run-1.json", DumpFile(dumpA));
|
||||
lockA.reset();
|
||||
});
|
||||
const double startA = Platform::Now();
|
||||
const Process::Captured ended = waitOn(artA, "beefa001ffff");
|
||||
const double waitedA = Platform::Now() - startA;
|
||||
endA.join();
|
||||
// A run whose lock goes without its final dump (killed).
|
||||
const fs::path artB = artifactOf("b");
|
||||
Write(artB / "gate-state" / "commits-beefb002-run-1.json", DumpFile(dumpOf("beefb002", 1, "IN PROGRESS - after Gate 1 — Approach")));
|
||||
auto lockB = std::make_unique<State::RunLock>(artB / "gate-state", "commits", "beefb002");
|
||||
lockB->WriteInfo(identity(1));
|
||||
std::jthread endB([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
lockB.reset();
|
||||
});
|
||||
const Process::Captured killed = waitOn(artB, "beefb002");
|
||||
endB.join();
|
||||
// A run a preflight check stops after it took the lock.
|
||||
const fs::path artC = artifactOf("c");
|
||||
auto lockC = std::make_unique<State::RunLock>(artC / "gate-state", "commits", "beefc003");
|
||||
lockC->WriteInfo(identity(1));
|
||||
std::jthread endC([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
lockC->AddInfo("preflight", "no lens runs: --without drops all");
|
||||
lockC.reset();
|
||||
});
|
||||
const Process::Captured stopped = waitOn(artC, "beefc003");
|
||||
endC.join();
|
||||
// Run 1 ended before the wait began; a new holder takes the lock and
|
||||
// names itself only a poll later - the wait follows run 2, not run 1.
|
||||
const fs::path artD = artifactOf("d");
|
||||
{
|
||||
State::RunLock first(artD / "gate-state", "commits", "beefd004");
|
||||
first.WriteInfo(identity(1));
|
||||
}
|
||||
Write(artD / "gate-state" / "commits-beefd004-run-1.json", DumpFile(dumpOf("beefd004", 1, "FIX FIRST")));
|
||||
const Json dumpD2 = dumpOf("beefd004", 2, "SEND-READY");
|
||||
std::jthread runD([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
State::RunLock second(artD / "gate-state", "commits", "beefd004");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
second.WriteInfo(identity(2));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
Write(artD / "gate-state" / "commits-beefd004-run-2.json", DumpFile(dumpD2));
|
||||
});
|
||||
const Process::Captured newer = waitOn(artD, "beefd004", {"--appear", "10"});
|
||||
runD.join();
|
||||
// A wait that begins just after a new holder took the lock, before it
|
||||
// names itself: the lock no longer names the last run (killed, its dump
|
||||
// IN PROGRESS), and the new run is followed.
|
||||
const fs::path artE = artifactOf("e");
|
||||
{
|
||||
State::RunLock first(artE / "gate-state", "commits", "beefe005");
|
||||
first.WriteInfo(identity(1));
|
||||
}
|
||||
Write(artE / "gate-state" / "commits-beefe005-run-1.json", DumpFile(dumpOf("beefe005", 1, "IN PROGRESS - after Gate 1 — Approach")));
|
||||
auto lockE = std::make_unique<State::RunLock>(artE / "gate-state", "commits", "beefe005");
|
||||
const Json dumpE2 = dumpOf("beefe005", 2, "SEND-READY");
|
||||
std::jthread runE([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
lockE->WriteInfo(identity(2));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
Write(artE / "gate-state" / "commits-beefe005-run-2.json", DumpFile(dumpE2));
|
||||
lockE.reset();
|
||||
});
|
||||
const Process::Captured fresh = waitOn(artE, "beefe005", {"--appear", "10"});
|
||||
runE.join();
|
||||
// The instant before a new holder clears the identity, held by a bare
|
||||
// flock: the lock still names the last run, killed (its dump IN
|
||||
// PROGRESS) - not that run; the new one is reported once it ends.
|
||||
const fs::path artG = artifactOf("g");
|
||||
{
|
||||
State::RunLock first(artG / "gate-state", "commits", "beef9006");
|
||||
first.WriteInfo(identity(1));
|
||||
}
|
||||
Write(artG / "gate-state" / "commits-beef9006-run-1.json", DumpFile(dumpOf("beef9006", 1, "IN PROGRESS - after Gate 1 — Approach")));
|
||||
const fs::path lockG = State::LockPath(artG / "gate-state", "commits", "beef9006");
|
||||
const std::int32_t bare = open(lockG.c_str(), O_RDWR | O_CLOEXEC);
|
||||
const bool bareHeld = bare >= 0 && flock(bare, LOCK_EX | LOCK_NB) == 0;
|
||||
const Json dumpG2 = dumpOf("beef9006", 2, "SEND-READY");
|
||||
std::jthread runG([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
Write(lockG, DumpFile(identity(2)));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
Write(artG / "gate-state" / "commits-beef9006-run-2.json", DumpFile(dumpG2));
|
||||
close(bare);
|
||||
});
|
||||
const Process::Captured notLast = waitOn(artG, "beef9006", {"--appear", "10"});
|
||||
runG.join();
|
||||
Check("wait: begun just after a new holder took the lock, it follows the new run - the lock no longer names the last one (killed)",
|
||||
fresh.returnCode == 0 && fresh.out == std::format("{}\n", State::Summary(dumpE2)), fresh.out + fresh.err);
|
||||
Check("wait: a held lock still naming the last run, killed - a new holder's instant before it clears the identity - is not that run: the new one is reported once it ends",
|
||||
bareHeld && notLast.returnCode == 0 && notLast.out == std::format("{}\n", State::Summary(dumpG2)), notLast.out + notLast.err);
|
||||
// A run rewriting its identity while it holds the lock - here held
|
||||
// empty across a poll, as in the instant inside AddInfo's rewrite - is
|
||||
// read only once nobody holds the lock: its preflight message, exit 3.
|
||||
const fs::path artT = artifactOf("t");
|
||||
auto lockT = std::make_unique<State::RunLock>(artT / "gate-state", "commits", "beef7007");
|
||||
lockT->WriteInfo(identity(1));
|
||||
const fs::path lockPathT = State::LockPath(artT / "gate-state", "commits", "beef7007");
|
||||
std::jthread endT([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
Write(lockPathT, "");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
||||
lockT->AddInfo("preflight", "the application does not answer");
|
||||
lockT.reset();
|
||||
});
|
||||
const Process::Captured rewritten = waitOn(artT, "beef7007");
|
||||
endT.join();
|
||||
Check("wait: a run whose identity is mid-rewrite while it holds the lock (here empty across a poll) is read once nobody holds it - its preflight message, exit 3",
|
||||
rewritten.returnCode == 3 && rewritten.out == "preflight: the application does not answer\n", rewritten.out + rewritten.err);
|
||||
// A run that takes the lock after the wait began and leaves it between
|
||||
// two polls without naming itself: seen by the identity it cleared,
|
||||
// exit 2.
|
||||
const fs::path artU = artifactOf("u");
|
||||
{
|
||||
State::RunLock first(artU / "gate-state", "commits", "beef8008");
|
||||
first.WriteInfo(identity(1));
|
||||
}
|
||||
Write(artU / "gate-state" / "commits-beef8008-run-1.json", DumpFile(dumpOf("beef8008", 1, "FIX FIRST")));
|
||||
std::jthread runU([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
const State::RunLock unnamed(artU / "gate-state", "commits", "beef8008");
|
||||
});
|
||||
const Process::Captured unnamedRun = waitOn(artU, "beef8008", {"--appear", "10"});
|
||||
runU.join();
|
||||
Check("wait: a run that takes the lock after the wait began and leaves it between two polls unnamed is seen by the identity it cleared - exit 2",
|
||||
unnamedRun.returnCode == 2 && unnamedRun.out.contains("took its run lock and ended before it named itself"), unnamedRun.out + unnamedRun.err);
|
||||
// A wait started after a run a preflight check stopped: the lock names
|
||||
// that run and the check's message.
|
||||
const fs::path artV = artifactOf("v");
|
||||
{
|
||||
State::RunLock stopped(artV / "gate-state", "commits", "beef9009");
|
||||
stopped.WriteInfo(identity(1));
|
||||
stopped.AddInfo("preflight", "no lens runs: --without drops all");
|
||||
}
|
||||
const Process::Captured latePreflight = waitOn(artV, "beef9009", {"--appear", "0"});
|
||||
Check("wait: started after a run a preflight check stopped, it exits 3 naming that run and the check's message",
|
||||
latePreflight.returnCode == 3
|
||||
&& latePreflight.err.contains("the lock names run 1, which a preflight check stopped before this wait began: no lens runs: --without drops all"),
|
||||
latePreflight.err);
|
||||
// A wait started after a run that ended without a dump: the lock names
|
||||
// that run and its log.
|
||||
const fs::path artW = artifactOf("w");
|
||||
{
|
||||
State::RunLock nodump(artW / "gate-state", "commits", "beefa010");
|
||||
nodump.WriteInfo(identity(1));
|
||||
}
|
||||
const Process::Captured lateNoDump = waitOn(artW, "beefa010", {"--appear", "0"});
|
||||
Check("wait: started after a run that ended without a dump, it exits 3 naming that run and its log",
|
||||
lateNoDump.returnCode == 3
|
||||
&& lateNoDump.err.contains(std::format("the lock names run 1, which ended before this wait began without a dump: its log is {}",
|
||||
(base / "scratch" / "x-run-1" / "log.txt").string())),
|
||||
lateNoDump.err);
|
||||
// A run that ends CONFIRMING: its summary, exit 2 - a round to run
|
||||
// again, as run's code says.
|
||||
const fs::path artY = artifactOf("y");
|
||||
const Json dumpY = dumpOf("beefc012", 1, "CONFIRMING - NOT SEND-READY (gates clean; 2 code unit(s) owe 3 clean read(s) to reach 3: run the same line again)");
|
||||
auto lockY = std::make_unique<State::RunLock>(artY / "gate-state", "commits", "beefc012");
|
||||
lockY->WriteInfo(identity(1));
|
||||
std::jthread endY([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
Write(artY / "gate-state" / "commits-beefc012-run-1.json", DumpFile(dumpY));
|
||||
lockY.reset();
|
||||
});
|
||||
const Process::Captured confirming = waitOn(artY, "beefc012");
|
||||
endY.join();
|
||||
Check("wait: a run whose final dump is CONFIRMING - its summary, exit 2, the code run gives it",
|
||||
confirming.returnCode == 2 && confirming.out == std::format("{}\n", State::Summary(dumpY)), confirming.out + confirming.err);
|
||||
// A wait only reads: stopped while its run is live, it leaves the lock
|
||||
// and its identity as they were, a wait started again reports the run,
|
||||
// and a wait leaves the lock file and the dump byte for byte as found.
|
||||
const fs::path artK = artifactOf("k");
|
||||
auto lockK = std::make_unique<State::RunLock>(artK / "gate-state", "commits", "beefb011");
|
||||
lockK->WriteInfo(identity(1));
|
||||
const fs::path lockPathK = State::LockPath(artK / "gate-state", "commits", "beefb011");
|
||||
const std::string identityK = Read(lockPathK);
|
||||
const Process::Child stoppedWait = Process::Start({.argv = {Platform::SelfExe().string(), "wait", "--artifact", artK.string(), "--hash", "beefb011"},
|
||||
.environment = Env,
|
||||
.cwd = base,
|
||||
.input = {.kind = Process::Stream::Kind::Null},
|
||||
.output = {.kind = Process::Stream::Kind::File, .file = base / "stopped-wait.out"},
|
||||
.error = {.kind = Process::Stream::Kind::File, .file = base / "stopped-wait.err"}});
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
|
||||
Process::Signal(stoppedWait.pid, SIGKILL);
|
||||
const std::optional<std::int32_t> stoppedCode = Process::Wait(stoppedWait.pid, std::chrono::seconds(10));
|
||||
const bool untouched = Read(lockPathK) == identityK && State::LockHolder(artK / "gate-state", "commits", "beefb011").has_value();
|
||||
const Json dumpK = dumpOf("beefb011", 1, "SEND-READY");
|
||||
std::jthread endK([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
|
||||
Write(artK / "gate-state" / "commits-beefb011-run-1.json", DumpFile(dumpK));
|
||||
lockK.reset();
|
||||
});
|
||||
const Process::Captured restarted = waitOn(artK, "beefb011");
|
||||
endK.join();
|
||||
const std::string lockBytes = Read(lockPathK);
|
||||
const std::string dumpBytes = Read(artK / "gate-state" / "commits-beefb011-run-1.json");
|
||||
const Process::Captured readsOnly = waitOn(artK, "beefb011", {"--appear", "0"});
|
||||
Check("wait: stopped while its run is live, it leaves the lock and its identity as they were; one started again reports the run; a wait writes neither the lock file nor the dump",
|
||||
stoppedCode.has_value() && untouched && restarted.returnCode == 0 && restarted.out == std::format("{}\n", State::Summary(dumpK)) && readsOnly.returnCode == 3
|
||||
&& Read(lockPathK) == lockBytes && Read(artK / "gate-state" / "commits-beefb011-run-1.json") == dumpBytes,
|
||||
restarted.out + restarted.err + readsOnly.err);
|
||||
// A wait started after its run's end, and one no run ever shows for.
|
||||
const Process::Captured late = waitOn(artD, "beefd004", {"--appear", "0"});
|
||||
const Process::Captured noRun = waitOn(artifactOf("f"), "00000000", {"--appear", "0"});
|
||||
const Process::Captured noArtifact = Self({"wait", "--hash", "00000000"}, base);
|
||||
const Process::Captured badAppear = waitOn(artifactOf("f"), "00000000", {"--appear=-1"});
|
||||
Check("wait: a run live when it begins - its summary as `run` prints it from the dump, its exit code, once the lock goes",
|
||||
ended.returnCode == 0 && ended.out == std::format("{}\n", State::Summary(dumpA)) && waitedA > 2.0, std::format("{} {:.1f}s", ended.out + ended.err, waitedA));
|
||||
Check("wait: a run whose lock goes without its final dump (killed) exits 2 naming its log; one a preflight check stopped after the lock, 3 with the message",
|
||||
killed.returnCode == 2 && killed.out.contains("ended without its final dump") && killed.out.contains((base / "scratch" / "x-run-1" / "log.txt").string())
|
||||
&& stopped.returnCode == 3 && stopped.out == "preflight: no lens runs: --without drops all\n",
|
||||
killed.out + killed.err + stopped.out + stopped.err);
|
||||
Check("wait: a new holder that has not named itself is not the run the lock still names - the run it then names is followed",
|
||||
newer.returnCode == 0 && newer.out == std::format("{}\n", State::Summary(dumpD2)), newer.out + newer.err);
|
||||
Check("wait: started after its run's end it exits 3 naming that run's dump; no run, exit 3; no --artifact or a negative --appear is a usage error (3)",
|
||||
late.returnCode == 3 && late.err.contains(std::format("ended before this wait began: {}", (artD / "gate-state" / "commits-beefd004-run-2.json").string())) && noRun.returnCode == 3
|
||||
&& noRun.err.contains("no full run of 00000000 seen at its run lock") && noArtifact.returnCode == 3 && noArtifact.err.contains("the following arguments are required: --artifact")
|
||||
&& badAppear.returnCode == 3 && badAppear.err.contains("invalid seconds"),
|
||||
late.err + noRun.err + noArtifact.err + badAppear.err);
|
||||
// Only `run` and `seats` read the seats file, and its lines reach the
|
||||
// placement readers alone (rounds 8 and 11 of the self-review): a
|
||||
// `stop` with the board path only in the working directory's .env
|
||||
|
|
|
|||
|
|
@ -10,8 +10,10 @@
|
|||
// stand until it dies; two drivers recording into one memory file are two
|
||||
// runs of this binary (`--record`).
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
import std;
|
||||
import Crafter.Review;
|
||||
|
|
@ -436,6 +438,27 @@ namespace {
|
|||
Check("run lock: another hash is free; nobody holds an untaken one", takes("ffff0000") && !State::LockHolder(gd, "commits", "00000000"));
|
||||
f.reset();
|
||||
Check("run lock: released on close (the kernel releases it on death the same way)", !State::LockHolder(gd, "commits", "abcd1234") && takes("abcd1234"));
|
||||
{
|
||||
// Taken again, the lock no longer names the last run.
|
||||
const State::RunLock again(gd, "commits", "abcd1234");
|
||||
const std::optional<Json> holder = State::LockHolder(gd, "commits", "abcd1234");
|
||||
Check("run lock: taken again, it clears the last run's identity - its holder reads as not named yet", holder && *holder == Json::object(),
|
||||
holder ? holder->dump() : std::string("no holder"));
|
||||
}
|
||||
{
|
||||
// A probe takes the lock shared for an instant: another prober's
|
||||
// is no holder, and a starting run waits it out.
|
||||
const std::int32_t probe = open(State::LockPath(gd, "commits", "abcd1234").c_str(), O_RDONLY | O_CLOEXEC);
|
||||
const bool shared = probe >= 0 && flock(probe, LOCK_SH | LOCK_NB) == 0;
|
||||
const bool seenFree = !State::LockHolder(gd, "commits", "abcd1234");
|
||||
std::jthread release([probe] {
|
||||
std::this_thread::sleep_for(50ms);
|
||||
close(probe);
|
||||
});
|
||||
const bool started = takes("abcd1234");
|
||||
release.join();
|
||||
Check("run lock: a probe's instant shared lock is no holder to another probe, and a starting run waits it out", shared && seenFree && started);
|
||||
}
|
||||
|
||||
// unit-state merge-on-write
|
||||
const fs::path sp = td / "unit-state.json";
|
||||
|
|
|
|||
|
|
@ -123,6 +123,8 @@ int main() {
|
|||
const std::string line = Freeze::RunLine(r1, "out", ".");
|
||||
Check("run line: built from the report, names the hash, the base, the tree and the register", line.starts_with(std::format("{} run --artifact out --hash {}", Invocation(), r1.at("hash").get<std::string>()))
|
||||
&& line.contains(std::format("--base {}", base)) && line.contains("--trees .") && line.contains("out/gate-state/dispositions.json"));
|
||||
Check("wait line: built from the report, the invocation's, names the artifact and the hash's first 8 characters",
|
||||
Freeze::WaitLine(r1, "out") == std::format("{} wait --artifact out --hash {}", Invocation(), r1.at("hash").get<std::string>().substr(0, 8)), Freeze::WaitLine(r1, "out"));
|
||||
const Json r2 = freeze({.base = base, .replace = true, .worktree = true});
|
||||
const fs::path wt = td / Dyn::Str(Dyn::Get(r2, "worktree"));
|
||||
Check("--worktree checks out HEAD detached under .review-gates/trees", r2.at("ok").get<bool>() && r2.at("worktree").get<std::string>().starts_with(std::format("{}/r-", Freeze::Worktrees))
|
||||
|
|
|
|||
|
|
@ -229,6 +229,20 @@ echo "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"result\"
|
|||
}
|
||||
const std::string hash = freezeJson.at("hash").get<std::string>();
|
||||
const std::string h8 = hash.substr(0, 8);
|
||||
// The wait line freeze prints, before the run line: Freeze::WaitLine's,
|
||||
// the invocation this binary's path (main() runs every child native).
|
||||
// Every wait below starts from it, as the skill does.
|
||||
const std::string waitMark = "first the wait, in the background:\n ";
|
||||
const std::size_t waitAt = frozen.out.find(waitMark);
|
||||
const std::size_t runAt = frozen.out.find("then the run,");
|
||||
std::string printedWait;
|
||||
if (waitAt != std::string::npos) {
|
||||
const std::size_t from = waitAt + waitMark.size();
|
||||
printedWait = frozen.out.substr(from, frozen.out.find('\n', from) - from);
|
||||
}
|
||||
Check("freeze prints the wait line, Freeze::WaitLine's, before the run line",
|
||||
waitAt != std::string::npos && runAt != std::string::npos && waitAt < runAt && printedWait == Freeze::WaitLine(freezeJson, ".review-gates/push/x"), frozen.out);
|
||||
const std::vector<std::string> waitLine = Dyn::Split(printedWait);
|
||||
auto runArgs = [&](std::vector<std::string> extra) {
|
||||
std::vector<std::string> args = {Platform::SelfExe().string(), "run", "--artifact", ".review-gates/push/x", "--hash", hash, "--base", baseSha, "--trees", ".",
|
||||
"--dispositions", ".review-gates/push/x/gate-state/dispositions.json", "--date", Text(freezeJson.at("date")),
|
||||
|
|
@ -284,6 +298,18 @@ echo "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"result\"
|
|||
// driver is SIGKILLed once every other pass has.
|
||||
const fs::path scratchA = scratchRoot / std::format("{}-run-1", h8);
|
||||
const Process::Child a = start({}, {{"FAKE_SLEEP", "571"}, {"FAKE_SLEEP_ON", std::format("repo-security:{}", securityUnit)}}, "a");
|
||||
// `wait` beside it, as the skill runs it: the line freeze printed.
|
||||
auto waitBeside = [&](std::string_view name) {
|
||||
std::vector<std::string> argv = waitLine;
|
||||
argv.insert(argv.end(), {"--appear", "30"});
|
||||
return Process::Start({.argv = argv,
|
||||
.environment = Env,
|
||||
.cwd = repo,
|
||||
.input = {.kind = Process::Stream::Kind::Null},
|
||||
.output = {.kind = Process::Stream::Kind::File, .file = base / std::format("{}.out", name)},
|
||||
.error = {.kind = Process::Stream::Kind::File, .file = base / std::format("{}.err", name)}});
|
||||
};
|
||||
const Process::Child waitA = waitBeside("wait-a");
|
||||
auto answered = [&] {
|
||||
std::int64_t n = 0;
|
||||
std::error_code error;
|
||||
|
|
@ -295,6 +321,9 @@ echo "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"result\"
|
|||
const bool settled = WaitFor([&] { return calls() == all && answered() == all - 1; }, std::chrono::seconds(30));
|
||||
Process::Signal(a.pid, SIGKILL);
|
||||
const std::optional<std::int32_t> aCode = Process::Wait(a.pid, std::chrono::seconds(10));
|
||||
const std::optional<std::int32_t> waitACode = Process::Wait(waitA.pid, std::chrono::seconds(30));
|
||||
Check("...and a wait beside it reports a run that left no final dump: exit 2", waitACode == 2 && Read(base / "wait-a.out").contains("ended without its final dump"),
|
||||
Read(base / "wait-a.out") + Read(base / "wait-a.err"));
|
||||
const std::vector<std::string> aLeft = LeftoversAfter(fakeDir);
|
||||
Json resumeA;
|
||||
try {
|
||||
|
|
@ -310,7 +339,9 @@ echo "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"result\"
|
|||
// The next run: the first gate resumed, the outputs of the killed run
|
||||
// salvaged, the one pass that never answered bought again.
|
||||
std::int64_t before = calls();
|
||||
const Process::Child waitB = waitBeside("wait-b");
|
||||
const Process::Captured b = run({});
|
||||
const std::optional<std::int32_t> waitBCode = Process::Wait(waitB.pid, std::chrono::seconds(30));
|
||||
const Json dumpB = LatestDump(gateDir, h8);
|
||||
const Json& processesB = dumpB.is_object() ? dumpB.at("processes") : Json::array();
|
||||
Check("the next run resumes the first gate from the checkpoint, salvages every output the killed run finished and buys only the pass that never answered - SEND-READY, exit 0",
|
||||
|
|
@ -318,6 +349,9 @@ echo "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"result\"
|
|||
&& std::ranges::count_if(processesB, [](const Json& r) { return Dyn::Truthy(Dyn::Get(r, "salvaged")); }) == all - gate1 - 1
|
||||
&& Count(processesB, "status", "ok") == all - gate1,
|
||||
std::format("exit {}, {} call(s), {}", b.returnCode, calls() - before, dumpB.is_object() ? Text(dumpB.at("overall")) : b.out + b.err));
|
||||
const std::string waitBOut = Read(base / "wait-b.out");
|
||||
Check("a wait beside the next run ends with it, printing the summary the run printed at its end, with its exit code", waitBCode == 0 && !waitBOut.empty() && b.out.ends_with(waitBOut),
|
||||
waitBOut + Read(base / "wait-b.err"));
|
||||
const Json stored = State::LoadState(gateDir / "unit-state.json").at("entries");
|
||||
Check("...and stores the clean block results of the range for reuse", static_cast<std::int64_t>(stored.size()) >= all - gate1, std::to_string(stored.size()));
|
||||
|
||||
|
|
@ -329,14 +363,28 @@ echo "{\"type\":\"result\",\"subtype\":\"success\",\"is_error\":false,\"result\"
|
|||
c.returnCode == 0 && calls() == before && dumpC.is_object() && dumpC.at("overall") == "SEND-READY" && dumpC.at("resumedLenses").size() == 3,
|
||||
std::format("exit {}, {} call(s)", c.returnCode, calls() - before));
|
||||
|
||||
// A full run a preflight check stops after it took the run lock: the
|
||||
// wait beside it prints the check's message, exit 3.
|
||||
const Process::Child waitP = waitBeside("wait-p");
|
||||
const Process::Captured p = run({"--without", "repo-better-solution.md,repo-bug-prover.md,repo-security.md"});
|
||||
const std::optional<std::int32_t> waitPCode = Process::Wait(waitP.pid, std::chrono::seconds(30));
|
||||
Check("a wait beside a full run that a preflight check stops after its run lock prints the check's message, exit 3", p.returnCode == 3 && waitPCode == 3
|
||||
&& Read(base / "wait-p.out").starts_with("preflight: no lens runs") && p.err.contains(Dyn::Strip(Read(base / "wait-p.out"))),
|
||||
Read(base / "wait-p.out") + Read(base / "wait-p.err") + p.err);
|
||||
|
||||
// A defect, on a run that reuses nothing; the scratch dir it claims
|
||||
// holds a stop file from before, which is not this run's.
|
||||
const std::string nextRun = std::format("{}-run-{}", h8, RunNumber(dumpC) + 1);
|
||||
const fs::path stale = scratchRoot / nextRun / "stop";
|
||||
Write(stale, "");
|
||||
before = calls();
|
||||
const Process::Child waitD = waitBeside("wait-d");
|
||||
const Process::Captured d = run({"--no-reuse", "--no-salvage"},
|
||||
{{"FAKE_FIX", std::format("repo-bug-prover:{}", proverUnit)}, {"FAKE_SLEEP", "3"}, {"FAKE_SLEEP_ON", "repo-better-solution:whole:order"}});
|
||||
const std::optional<std::int32_t> waitDCode = Process::Wait(waitD.pid, std::chrono::seconds(30));
|
||||
const std::string waitDOut = Read(base / "wait-d.out");
|
||||
Check("a wait beside a FIX FIRST run prints the summary the run printed at its end, exit 1", waitDCode == 1 && !waitDOut.empty() && d.out.ends_with(waitDOut),
|
||||
waitDOut + Read(base / "wait-d.err"));
|
||||
const Json dumpD = LatestDump(gateDir, h8);
|
||||
Check("FIX FIRST: a defect in the last gate stops the run there, exit 1 - every pass bought again with --no-reuse --no-salvage",
|
||||
d.returnCode == 1 && calls() - before == all && dumpD.is_object() && dumpD.at("overall") == "FIX FIRST" && dumpD.at("stoppedAt") == "Gate 3 — Proof",
|
||||
|
|
|
|||
Loading…
Reference in a new issue