* 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)
| 100 | * skill template aligned. |
| 101 | */ |
| 102 | function runRollbackSequence(env: RollbackEnv): { exitCode: number; stderr: string } { |
| 103 | const script = ` |
| 104 | set -u |
| 105 | BACKUP="${env.configPath}.gstack-bak-$(date +%s)-$$" |
| 106 | if [ -f "${env.configPath}" ]; then |
| 107 | mv "${env.configPath}" "$BACKUP" |
| 108 | fi |
| 109 | if ! 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 |
| 115 | fi |
| 116 | echo "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 | |
| 132 | describe("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", () => { |
no test coverage detected