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
159 changes: 154 additions & 5 deletions .github/tests/quality_report_contract_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess
import sys
import tempfile
import time
import unittest
from unittest import mock

Expand Down Expand Up @@ -176,13 +177,161 @@ def test_selector_expands_brace_alternatives_like_download_artifact(self):

self.assertEqual([1, 2], ids)

def test_selector_rejects_extglob_patterns(self):
with self.assertRaises(SELECTOR_MODULE["SelectionError"]) as caught:
def test_selector_selects_extglob_alternatives(self):
ids, _ = self.select(
[
self.artifact(1, "2026-08-13T12:01:00Z", name="quality-result-auth"),
self.artifact(2, "2026-08-13T12:01:00Z", name="quality-result-stats"),
self.artifact(3, "2026-08-13T12:01:00Z", name="quality-result-other"),
],
pattern="quality-result-@(auth|stats)",
)

self.assertEqual([1, 2], ids)

def test_matches_agrees_with_minimatch_defaults(self):
# Each row was checked against minimatch 10 with default options, the
# matcher actions/download-artifact applies to its pattern input.
rows = [
("quality-result-*", "quality-result-auth", True),
("quality-result-*", "quality-result-", True),
("quality-result-*", "quality-report-auth", False),
("quality-result-{auth,stats}", "quality-result-stats", True),
("quality-result-{auth,stats}", "quality-result-other", False),
("result-{1..3}", "result-2", True),
("result-{1..3}", "result-4", False),
("{a,{b,c}}", "c", True),
("a{b", "a{b", True),
("quality-result-@(auth|stats)", "quality-result-auth", True),
("quality-result-@(auth|stats)", "quality-result-other", False),
("@(a|b)c", "bc", True),
("@(a|b)c", "abc", False),
("?(a|b)c", "c", True),
("?(a|b)c", "abc", False),
("+(x)", "xxx", True),
("+(x)", "", False),
("*(a|b)c", "ababc", True),
("*(a|b)c", "abcd", False),
("target-result-!(windows)-*", "target-result-linux-x64", True),
("target-result-!(windows)-*", "target-result-windows-x64", False),
# a leading ! negates the whole pattern, so !(...) at the start is
# not an extglob: it negates the literal "(auth)*"
("!(auth)*", "stats", True),
("!(auth)*", "authz", True),
("!(a)", "a", True),
("!!(a)", "(a)", True),
("!a", "b", True),
("!a", "a", False),
("!!a", "a", True),
("#a", "#a", False),
("", "", True),
("", "a", False),
("*", ".hidden", False),
("*", "visible", True),
(".*", ".hidden", True),
("?", ".", False),
("[a-c]x", "bx", True),
("[a-c]x", ".x", False),
("@(.a|b)", ".a", True),
("*(a|b)", ".a", False),
("+(*|.a)", ".a", True),
("[abc]", "b", True),
("[a-c]", "d", False),
("[!a]", "b", True),
("[^a]", "a", False),
("[a", "[a", True),
("[]a]", "]", True),
("[[:alpha:]]", "q", True),
("[[:alpha:]]", "7", False),
("[[:digit:]]x", "7x", True),
("a\\*", "a*", True),
("a\\*", "ab", False),
("@(a|b", "@(a|b", True),
("@()", "@()", True),
("quality-report-.dist", "quality-report-.dist", True),
("quality-report-*", "quality-report-.dist", True),
("*.txt", "a.txt", True),
("*.txt", ".txt", False),
("Quality-*", "quality-a", False),
]
matches = SELECTOR_MODULE["matches"]
for pattern, name, expected in rows:
with self.subTest(pattern=pattern, name=name):
self.assertIs(expected, matches(name, pattern))

def test_selector_refuses_constructs_it_cannot_mirror(self):
error = SELECTOR_MODULE["SelectionError"]
for pattern in ("**/quality-result-a", "quality-result-a/**", "a\\|b", "a-[[:alpha:]]"):
with self.subTest(pattern=pattern):
with self.assertRaises(error):
self.select(
[self.artifact(1, "2026-08-13T12:01:00Z", name="quality-result-a")],
pattern=pattern,
)

def refuses(self, pattern):
error = SELECTOR_MODULE["SelectionError"]
with self.assertRaises(error):
self.select(
[self.artifact(1, "2026-08-13T12:01:00Z", name="quality-result-auth")],
pattern="quality-result-@(auth|stats)",
[self.artifact(1, "2026-08-13T12:01:00Z", name="quality-result-a")],
pattern=pattern,
)
self.assertIn("extglob", str(caught.exception))

def test_oversized_brace_range_bound_is_a_selection_error(self):
self.refuses("a-{1.." + "9" * 4301 + "}")
self.refuses("a-{" + "9" * 4301 + "..1}")
self.assertEqual(["a-1", "a-2", "a-3"], SELECTOR_MODULE["expand_braces"]("a-{1..3}"))

def test_brace_expansion_deduplicates_a_large_range_quickly(self):
expanded = SELECTOR_MODULE["expand_braces"]("a-{0..99999}")
self.assertEqual(100000, len(expanded))
self.assertEqual("a-0", expanded[0])
self.assertEqual(["a-1", "a-2"], SELECTOR_MODULE["expand_braces"]("a-{1,2,1}"))

def test_deeply_nested_extglob_is_a_selection_error(self):
self.refuses("@(" * 2000 + "a" + ")" * 2000)
self.refuses("@(" * 65 + "a" + ")" * 65)
self.assertTrue(SELECTOR_MODULE["matches"]("a", "@(@(a))"))

def test_many_negation_groups_is_a_selection_error(self):
started = time.monotonic()
self.refuses("quality-result-" + "!(x)" * 14)
self.refuses("quality-result-" + "!(x)" * 25)
self.refuses("a" + "!(x|y|z)" * 8)
self.assertLess(time.monotonic() - started, 2)

def test_negation_copies_of_a_long_literal_are_a_selection_error(self):
started = time.monotonic()
self.refuses("quality-result-" + "!(x)" * 10 + "a" * 60000)
matches = SELECTOR_MODULE["matches"]
self.assertTrue(matches("a" * 60000, "*" + "a" * 59999))
self.assertLess(time.monotonic() - started, 2)

def test_ordinary_negation_groups_still_match(self):
matches = SELECTOR_MODULE["matches"]
started = time.monotonic()
self.assertTrue(matches("ab", "!(a)!(b)"))
self.assertTrue(matches("xy", "!(a)!(b)"))
self.assertTrue(matches("quality-result-y", "quality-result-!(x)"))
self.assertFalse(matches("quality-result-x", "quality-result-!(x)"))
self.assertTrue(matches("pre-q-r", "pre-!(a)-!(b)"))
self.assertFalse(matches("pre-a-r", "pre-!(a)-!(a)"))
eight = "q-" + "!(x)" * 8
self.assertTrue(matches("q-yyyyyyyy", eight))
self.assertTrue(matches("q-y", eight))
self.assertLess(time.monotonic() - started, 2)

def test_escaped_pipe_is_refused_before_suffix_shortcuts(self):
self.refuses("*a\\|b")
self.refuses("??\\|b")
self.assertTrue(SELECTOR_MODULE["matches"]("xa", "*a"))
self.assertTrue(SELECTOR_MODULE["matches"]("b", "@(a|b)"))

def test_brace_expansion_cap_never_drops_alternatives_silently(self):
self.refuses("!{quality-result-{0..99999},a/../b}")
self.refuses("!{quality-result-{0..1},a/../b}")
self.refuses("{0..100000}")
self.refuses("{0..99999}{a,b}")

def test_brace_expansion_handles_nesting_and_literals(self):
expand = SELECTOR_MODULE["expand_braces"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/quality-report-aggregate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
required: true
type: string
result_artifact_pattern:
description: Artifact-name glob (* ? [] and {a,b} alternatives; extglob is not supported) containing target-result.json files
description: Artifact-name pattern containing target-result.json files, matched with minimatch 10.2.6 default options as the compatibility target (* ? [] {a,b} and extglob such as @(a|b)); the deepest extglob nesting, escaped pipes, path segments like ** and .., and oversized brace expansions fail the selection instead of matching
required: false
type: string
default: quality-result-*
Expand Down
46 changes: 33 additions & 13 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ contract tests that pin the shapes other repositories depend on.
## What lives here

- `.github/workflows/go-ci.yml`, `node-ci.yml`, `release-gate.yml`,
`greptile-summon.yml`, `quality-report-aggregate.yml` — reusable workflows
`greptile-summon.yml`, `quality-report-aggregate.yml`,
`main-is-released.yml`, `starchart-refresh.yml`: reusable workflows
consumed by other CodesWhat repositories.
- `.github/tests/` — contract tests. These are the public API of the org's
- `actions/changes-gate` and `actions/tree-receipt/{verify,record}`:
composite actions consumers pin the same way. Each has its own README and
contract test (`changes_gate_contract_test.py`,
`tree_receipt_contract_test.py`).
- `.github/tests/`: contract tests. These are the public API of the org's
shared configs (the `greptile.json` shape, the quality-report v1 contract,
the reusable CI inputs). Change a contract test and its consumers together,
never one side alone.
- `profile/` — the organization profile README plus generated SVG assets
- `profile/`: the organization profile README plus generated SVG assets
from `scripts/generate_profile_svg.py`. The untracked
`profile/font_reference.svg` is user-owned; leave it alone.

Expand All @@ -35,21 +40,36 @@ contract tests that pin the shapes other repositories depend on.
Verify promotions with tree equality
(`git diff --quiet origin/main origin/dev/repository-standards`), never
commit ancestry.
- Before opening a promotion, check dev for open code scanning alerts at
high or above. `main`'s ruleset blocks merges on them and dev PRs don't.
This must print 0:
- After opening a promotion PR, check its code scanning result before
approving. `main`'s ruleset blocks merges on open alerts at high or above,
and CodeQL here only analyzes pull requests, on `refs/pull/<n>/merge`, so a
dev-branch query always returns 0 and proves nothing. Wait for an analysis
of the PR's current test merge commit, then count the open alerts on that
ref. With `n` set to the promotion PR number, run this in bash. It must
print 0:

```sh
alerts="repos/CodesWhat/.github/code-scanning/alerts"
gh api --paginate \
"$alerts?state=open&ref=refs/heads/dev/repository-standards&per_page=100" |
```bash
repo="repos/CodesWhat/.github"
ref="refs/pull/$n/merge"
if merge="$(gh api "$repo/pulls/$n" --jq .merge_commit_sha)" &&
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
analyses="$(gh api --paginate \
"$repo/code-scanning/analyses?ref=$ref&per_page=100")" &&
jq -se --arg m "$merge" 'any(.[][]; .commit_sha == $m)' \
<<<"$analyses" >/dev/null &&
alerts="$(gh api --paginate \
"$repo/code-scanning/alerts?state=open&ref=$ref&per_page=100")" &&
[ "$(gh api "$repo/pulls/$n" --jq .merge_commit_sha)" = "$merge" ]; then
jq -s '[.[][] | .rule | select(.security_severity_level == "high"
or .security_severity_level == "critical" or .severity == "error")]
| length'
| length' <<<"$alerts"
else
echo "check failed or no code scanning analysis of the merge commit yet"
fi
```

Fix each alert, or dismiss it with a reason once it's verified as a false
positive. Never change the ruleset to get past it.
Approve only at 0, at the head the check ran on, and run it again after any
push. Fix each alert, or dismiss it with a reason once it's
verified as a false positive. Never change the ruleset to get past it.
- There is no shared admission queue; pace hosted review and heavy CI with
the maintainer directly. Add `review-ready` for a PR's first CodeRabbit
review and request subsequent fix-batch reviews explicitly.
Expand Down
7 changes: 7 additions & 0 deletions REPOSITORY_ONBOARDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ Add these only when the behavior exists:
Trace other consumers of the committed SVGs, such as a website, before
removing them or the caller. The reusable workflow keeps its interface for
existing pins.
- [ ] A dev-branch repository whose full CI is expensive can skip repeat work
with this repository's composite actions, pinned to a full commit SHA like
the reusable workflows. `actions/changes-gate` tells a PR whether any file
that matters changed, so docs-only PRs can skip heavy jobs.
`actions/tree-receipt` lets the promotion PR and the push to `main` reuse a
trusted earlier run for the same tree, and falls back to a full run on any
doubt. Their READMEs document the inputs.

### Qlty

Expand Down
16 changes: 12 additions & 4 deletions decisions/quality-reporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,18 @@ Target result JSON is always uploaded; crash forensics remain failure-only.
Completeness requires fresh results for every expected target. The aggregate
job downloads only artifacts matching `result_artifact_pattern` that were
created strictly after the current attempt started, selected by explicit
artifact ID. Results retained from an earlier attempt never count, and a
partial rerun that lacks replacements fails closed: `complete=false`,
`outcome=error`, no aggregate score, and a nonzero exit. An empty selection
downloads nothing instead of falling back to every artifact.
artifact ID. The compatibility target is minimatch 10.2.6 with its
default options, which is what `actions/download-artifact` applies to its
pattern; the selector does not promise every behavior of that action. `*`,
`?`, `[...]`, `{a,b}` and `{1..3}` braces, and extglob (`@(a|b)`, `?()`,
`+()`, `*()`, `!()`) all work. A leading `!` negates the whole pattern, so
`!(a)*` is not an extglob. Artifact names have no path separator, so a
pattern that needs `**` or `..` segments, that escapes a pipe, that nests
extglobs past the parser limit, or whose brace expansion would pass its size
cap fails the selection instead of matching. Results retained from an earlier
attempt never count, and a partial rerun that lacks replacements fails closed:
`complete=false`, `outcome=error`, no aggregate score, and a nonzero exit. An
empty selection downloads nothing instead of falling back to every artifact.
Normalized aggregate artifacts use at least 90 days of retention.

The reusable workflow checks out its own contract at the exact called-workflow
Expand Down
Loading
Loading