MCPcopy
hub / github.com/garrytan/gstack / runRollbackSequence

Function runRollbackSequence

test/gbrain-init-rollback.test.ts:102–130  ·  view source on GitHub ↗

* Verbatim reimplementation of the skill template's Step 1.5 / 4.5 rollback * sequence. The skill instructs the model to execute this bash; we execute * the same bash here in a sandboxed environment and assert the contract. * * If gbrain templates rewrite this sequence, this test should fail unt

(env: RollbackEnv)

Source from the content-addressed store, hash-verified

100 * skill template aligned.
101 */
102function runRollbackSequence(env: RollbackEnv): { exitCode: number; stderr: string } {
103 const script = `
104set -u
105BACKUP="${env.configPath}.gstack-bak-$(date +%s)-$$"
106if [ -f "${env.configPath}" ]; then
107 mv "${env.configPath}" "$BACKUP"
108fi
109if ! gbrain init --pglite --json; then
110 if [ -n "\${BACKUP:-}" ] && [ -f "$BACKUP" ]; then
111 mv "$BACKUP" "${env.configPath}"
112 fi
113 echo "gbrain init failed. Existing config (if any) was restored." >&2
114 exit 1
115fi
116echo "ok"
117`;
118 const result = spawnSync("bash", ["-c", script], {
119 encoding: "utf-8",
120 env: {
121 ...process.env,
122 HOME: env.home,
123 PATH: `${env.bindir}:/usr/bin:/bin`,
124 },
125 });
126 return {
127 exitCode: result.status ?? 1,
128 stderr: result.stderr || "",
129 };
130}
131
132describe("Step 1.5 / 4.5 .bak-rollback contract (plan D7)", () => {
133 it("FAILURE PATH: when `gbrain init` fails, broken config is restored to original path", () => {

Callers 1

Calls 1

spawnSyncFunction · 0.85

Tested by

no test coverage detected