diff --git a/CHANGELOG.md b/CHANGELOG.md index 7678d21d0..0057fd119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Drop the `skills` submodule and its daily Dependabot `gitsubmodule` entry. Nothing in this repo read it, nor did the npm package or any workflow, and the job in `FailproofAI/skills` that kept it current failed on every merge once the version-bot App was gone. The skills reach users through `npx skills add FailproofAI/skills`, which this pin never fed (#1075) - Delete `sync-fp-cloud-cli-skill.yml` and `sync-failproofai-sdk-skill.yml`, red on every run since August because the `SKILLS_SYNC_PAT` they pushed to `FailproofAI/skills` with was never created; that repo now pulls both skills from this public one with its own token, so nothing here holds a credential that writes to it. The fp-cloud-cli skill's description is cut from 1118 to 995 characters, under the 1024 that the skills repo's validator enforces and past which Copilot drops a skill (#1068) +- The audit's `sleep-polling-loop` detector now counts the explicit-seconds form `sleep 30s`, which its regex used to drop, and checks every `sleep` in a command rather than only the first, so `sleep 1; sleep 60` counts too; cached transcripts are re-scanned once on the next audit, so those already in history are counted too (#1100, from #588, #845, fixes #522) - Add a global `--no-color` flag, the same as `NO_COLOR=1`, accepted before or after any command; `failproofai policies` already honors `NO_COLOR` (#1067, from #695, #700, #848, fixes #688) - CI: the contributor-welcome workflow no longer tries to approve Dependabot pull requests. GitHub refuses a workflow approval while "Allow GitHub Actions to create and approve pull requests" is off, so every Dependabot PR got a failed run, and with it on the approval would count as the one review `main` requires. Dependency updates are reviewed by a person; the workflow drops `pull-requests: write` (#1049) diff --git a/__tests__/audit/detectors.test.ts b/__tests__/audit/detectors.test.ts index 0df1aef5e..c9ae16e13 100644 --- a/__tests__/audit/detectors.test.ts +++ b/__tests__/audit/detectors.test.ts @@ -100,9 +100,44 @@ describe("sleep-polling-loop", () => { it("matches `sleep 60`", () => { expect(sleepPollingLoop.detect(bash("sleep 60"), {})).not.toBeNull(); }); + it("matches `sleep 30s` - the explicit-seconds form the regex used to drop", () => { + expect(sleepPollingLoop.detect(bash("sleep 30s"), {})).not.toBeNull(); + }); + it("matches `sleep 45s`", () => { + expect(sleepPollingLoop.detect(bash("sleep 45s"), {})).not.toBeNull(); + }); + it("still does not match `sleep 1s`", () => { + expect(sleepPollingLoop.detect(bash("sleep 1s"), {})).toBeNull(); + }); + it("does not match `sleep 29s`, one second under the threshold", () => { + expect(sleepPollingLoop.detect(bash("sleep 29s"), {})).toBeNull(); + }); + it("matches `sleep 30s` followed by another command", () => { + expect(sleepPollingLoop.detect(bash("sleep 30s && npm test"), {})).not.toBeNull(); + }); + it("matches a long sleep after a short one (`sleep 1s && sleep 60`)", () => { + expect(sleepPollingLoop.detect(bash("sleep 1s && sleep 60"), {})).not.toBeNull(); + expect(sleepPollingLoop.detect(bash("sleep 1; make; sleep 45s"), {})).not.toBeNull(); + }); + it("does not match when every sleep is short (`sleep 1s && sleep 5`)", () => { + expect(sleepPollingLoop.detect(bash("sleep 1s && sleep 5"), {})).toBeNull(); + }); + it("does not match `sleep 30sec`, which is not a unit sleep accepts", () => { + expect(sleepPollingLoop.detect(bash("sleep 30sec"), {})).toBeNull(); + }); it("matches `sleep 5m`", () => { expect(sleepPollingLoop.detect(bash("sleep 5m"), {})).not.toBeNull(); }); + it("matches `sleep 0.5m` (30 seconds)", () => { + expect(sleepPollingLoop.detect(bash("sleep 0.5m"), {})).not.toBeNull(); + }); + it("does not match `sleep 0.4m` (24 seconds)", () => { + expect(sleepPollingLoop.detect(bash("sleep 0.4m"), {})).toBeNull(); + }); + it("matches `sleep 2h` and `sleep 1d`", () => { + expect(sleepPollingLoop.detect(bash("sleep 2h"), {})).not.toBeNull(); + expect(sleepPollingLoop.detect(bash("sleep 1d"), {})).not.toBeNull(); + }); it("matches while-sleep loop", () => { expect( sleepPollingLoop.detect(bash("while true; do echo x; sleep 5; done"), {}), diff --git a/src/audit/detectors/sleep-polling-loop.ts b/src/audit/detectors/sleep-polling-loop.ts index c701f0f88..beb018292 100644 --- a/src/audit/detectors/sleep-polling-loop.ts +++ b/src/audit/detectors/sleep-polling-loop.ts @@ -19,9 +19,12 @@ export const sleepPollingLoop: Detector = { if (/\bwhile\b[\s\S]*?\bsleep\b[\s\S]*?\bdone\b/.test(cmd)) { return { example: cmd.replace(/\s+/g, " ").trim().slice(0, 160) }; } - // Standalone long sleep. parseFloat so `sleep 0.5m` (= 30s) isn't dropped. - const match = /\bsleep\s+(\d+(?:\.\d+)?)(m|h|d)?\b/.exec(cmd); - if (match) { + // Standalone long sleep. parseFloat so `sleep 0.5m` (= 30s) isn't dropped; + // the unit group includes `s` so the common explicit form `sleep 30s` matches + // (the trailing \b used to fail on `0s`, dropping the whole match). + // Every sleep in the command is checked, not just the first, so a short one + // ahead of a long one (`sleep 1s && sleep 60`) does not hide it. + for (const match of cmd.matchAll(/\bsleep\s+(\d+(?:\.\d+)?)(s|m|h|d)?\b/g)) { const n = parseFloat(match[1]); const unit = match[2] ?? "s"; const seconds = unit === "m" ? n * 60 : unit === "h" ? n * 3600 : unit === "d" ? n * 86400 : n;