Skip to content

Commit 32cf61c

Browse files
committed
test(hermes): keep stale guard tests branchless
Signed-off-by: Aaron Erickson <aerickson@nvidia.com>
1 parent 9e453b9 commit 32cf61c

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

test/hermes-stale-openclaw-guard.test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,14 @@ const DIFFERENT_DIGEST = `sha256:${"0".repeat(64)}`;
1515

1616
function dockerRunCommandContaining(dockerfile: string, signature: string): string {
1717
const signatureIndex = dockerfile.indexOf(signature);
18-
if (signatureIndex === -1) {
19-
throw new Error(`Expected Dockerfile RUN signature: ${signature}`);
20-
}
18+
expect(signatureIndex, `Expected Dockerfile RUN signature: ${signature}`).not.toBe(-1);
2119
const runIndex = dockerfile.lastIndexOf("RUN set -eu;", signatureIndex);
22-
if (runIndex === -1) {
23-
throw new Error(`Expected RUN instruction before ${signature}`);
24-
}
25-
const runLines: string[] = [];
26-
for (const line of dockerfile.slice(runIndex).split("\n")) {
27-
runLines.push(line);
28-
if (!line.trimEnd().endsWith("\\")) break;
29-
}
30-
const lastLine = runLines[runLines.length - 1]?.trimEnd() ?? "";
31-
if (lastLine.endsWith("\\")) {
32-
throw new Error(`Expected complete RUN instruction containing ${signature}`);
33-
}
34-
return runLines
20+
expect(runIndex, `Expected RUN instruction before ${signature}`).not.toBe(-1);
21+
const linesAfterRun = dockerfile.slice(runIndex).split("\n");
22+
const endIndex = linesAfterRun.findIndex((line) => !line.trimEnd().endsWith("\\"));
23+
expect(endIndex, `Expected complete RUN instruction containing ${signature}`).toBeGreaterThan(-1);
24+
return linesAfterRun
25+
.slice(0, endIndex + 1)
3526
.join("\n")
3627
.trim()
3728
.replace(/^RUN\s+/, "")

0 commit comments

Comments
 (0)