Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/test-suite-registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,19 @@
"related_issues": [5610, 7789],
"reason": "Wired by #7789: scripts-test.yml names the suite explicitly, following the sibling pattern for this directory. The workflow is active (the scripts.direct-python row's disabled_manually note is stale registry state for #6187 to refresh)."
},
{
"id": "scripts.restore-row-count-diff",
"paths": ["scripts/tests/test_restore_row_count_diff.py"],
"invocation": "python3 -m unittest discover -s scripts/tests -p 'test_restore_row_count_diff.py' -v",
"venue": {
"workflow": ".github/workflows/scripts-test.yml",
"job_step": "restore row-count diff contract tests (#12788)",
"state": "active",
"dispatchable": true
},
"status": "mapped",
"related_issues": [12788]
},
{
"id": "scripts.research-workflow",
"paths": [
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/scripts-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
python3 -m unittest discover -s scripts/tests -p 'test_hardware_doc_init.py' -v
- name: Run provider retirement gate contract tests (#5610)
run: python3 -m unittest discover -s scripts/tests -p 'test_check_provider_retirement_gate.py' -v
- name: Run restore row-count diff contract tests (#12788)
run: |
test -f scripts/tests/test_restore_row_count_diff.py
python3 -m unittest discover -s scripts/tests -p 'test_restore_row_count_diff.py' -v
- name: Run auto-format workflow contract tests (#7664)
run: python3 -m unittest discover -s scripts/tests -p 'test_auto_format_workflow.py' -v
- name: Run power-guard timing validation tests (#6477)
Expand Down
29 changes: 18 additions & 11 deletions scripts/fleet/restore-row-count-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,30 @@
# Usage:
# restore-row-count-diff.sh --manifest MANIFEST.tsv --live LIVE.tsv # [--inventory INVENTORY.txt]
# Exit: 0 = gate passes, 1 = gate fails, 2 = usage/input error.
# The command line is parsed strictly (#3352): a value option with no
# value, or with a value that is itself an option, is a usage error.
set -euo pipefail

usage() {
echo "usage: restore-row-count-diff.sh --manifest M.tsv --live L.tsv [--inventory I.txt]" >&2
}

manifest=""
live=""
inventory=""
while [ $# -gt 0 ]; do
case "$1" in
--manifest)
manifest="$2"
shift 2
;;
--live)
live="$2"
shift 2
;;
--inventory)
inventory="$2"
--manifest | --live | --inventory)
if [ $# -lt 2 ] || [ "${2#--}" != "$2" ]; then
echo "option $1 requires a value" >&2
usage
exit 2
fi
case "$1" in
--manifest) manifest="$2" ;;
--live) live="$2" ;;
--inventory) inventory="$2" ;;
esac
shift 2
;;
*)
Expand All @@ -59,7 +66,7 @@ while [ $# -gt 0 ]; do
esac
done
[ -n "$manifest" ] && [ -n "$live" ] || {
echo "usage: restore-row-count-diff.sh --manifest M.tsv --live L.tsv [--inventory I.txt]" >&2
usage
exit 2
}
[ -f "$manifest" ] && [ -f "$live" ] || {
Expand Down
68 changes: 68 additions & 0 deletions scripts/tests/test_restore_row_count_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
"""Contract tests for restore-row-count-diff.sh (#12788).

Oracle: the operator-script argument contract
(doc/agents/operator-script-argument-contract.md, #3352) and the
script's own header — a value option with no value, or with a value
that is itself an option, is a usage error: the usage message on
stderr and exit 2, never a raw bash error. A well-formed invocation
still runs the gate.
"""

import subprocess
import tempfile
import unittest
from pathlib import Path


ROOT = Path(__file__).resolve().parents[2]
SCRIPT = ROOT / "scripts" / "fleet" / "restore-row-count-diff.sh"


def run_diff(args):
return subprocess.run(
["bash", str(SCRIPT), *args],
text=True,
capture_output=True,
check=False,
)


class TestRestoreRowCountDiffArgs(unittest.TestCase):
def test_missing_option_value_is_a_usage_error(self):
for option in ("--manifest", "--live", "--inventory"):
with self.subTest(option=option):
result = run_diff([option])
self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("usage:", result.stderr)
self.assertNotIn("unbound variable", result.stderr)

def test_option_looking_value_is_not_consumed(self):
result = run_diff(["--manifest", "--live", "/path"])
self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("usage:", result.stderr)
self.assertNotIn("unknown argument: /path", result.stderr)

def test_unknown_argument_is_a_usage_error(self):
result = run_diff(["--bogus"])
self.assertEqual(result.returncode, 2, result.stderr)
self.assertIn("unknown argument: --bogus", result.stderr)

def test_matching_counts_pass_the_gate(self):
with tempfile.TemporaryDirectory(prefix="row-count-diff-") as tmp:
manifest = Path(tmp) / "manifest.tsv"
manifest.write_text(
"table\tsource_count\tdisposition\tallowed_delta\tnote\n"
"t1\t5\tload\t0\t\n"
)
live = Path(tmp) / "live.tsv"
live.write_text("table\tlive_count\nt1\t5\n")
result = run_diff(
["--manifest", str(manifest), "--live", str(live)]
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("GATE PASSED", result.stdout)


if __name__ == "__main__":
unittest.main()