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
32 changes: 32 additions & 0 deletions .github/workflows/run-role.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ jobs:
private-key: ${{ secrets.HARNESS_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Explain a failed App token
if: failure() && steps.app.outcome == 'failure'
run: |
echo "::error::Cannot create the harness App token: HARNESS_APP_ID or HARNESS_APP_PRIVATE_KEY is wrong (G32)."
echo "::error::'Invalid keyData' means the key text changed when it was pasted. Set it from the .pem file:"
echo "::error::gh secret set HARNESS_APP_PRIVATE_KEY --org $GITHUB_REPOSITORY_OWNER --visibility selected --repos <specs repo>,<code repo> < key.pem"
echo "::error::Then run gate.py doctor from the specs repo."

- name: Check out the harness (outside the workspace)
env:
TOKEN: ${{ steps.app.outputs.token }}
Expand Down Expand Up @@ -146,6 +154,14 @@ jobs:
private-key: ${{ secrets.HARNESS_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Explain a failed App token
if: failure() && steps.app.outcome == 'failure'
run: |
echo "::error::Cannot create the harness App token: HARNESS_APP_ID or HARNESS_APP_PRIVATE_KEY is wrong (G32)."
echo "::error::'Invalid keyData' means the key text changed when it was pasted. Set it from the .pem file:"
echo "::error::gh secret set HARNESS_APP_PRIVATE_KEY --org $GITHUB_REPOSITORY_OWNER --visibility selected --repos <specs repo>,<code repo> < key.pem"
echo "::error::Then run gate.py doctor from the specs repo."

- name: Check out the harness (outside the workspace)
env:
TOKEN: ${{ steps.app.outputs.token }}
Expand Down Expand Up @@ -250,6 +266,14 @@ jobs:
private-key: ${{ secrets.HARNESS_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Explain a failed App token
if: failure() && steps.app.outcome == 'failure'
run: |
echo "::error::Cannot create the harness App token: HARNESS_APP_ID or HARNESS_APP_PRIVATE_KEY is wrong (G32)."
echo "::error::'Invalid keyData' means the key text changed when it was pasted. Set it from the .pem file:"
echo "::error::gh secret set HARNESS_APP_PRIVATE_KEY --org $GITHUB_REPOSITORY_OWNER --visibility selected --repos <specs repo>,<code repo> < key.pem"
echo "::error::Then run gate.py doctor from the specs repo."

- name: Check out the harness
env:
TOKEN: ${{ steps.app.outputs.token }}
Expand Down Expand Up @@ -292,6 +316,14 @@ jobs:
owner: ${{ steps.cfg.outputs.audit_owner }}
repositories: ${{ steps.cfg.outputs.audit_name }}

- name: Explain a failed App token
if: failure() && steps.audit.outcome == 'failure'
run: |
echo "::error::Cannot create the audit App token: HARNESS_AUDIT_APP_ID or HARNESS_AUDIT_APP_PRIVATE_KEY is wrong (G32)."
echo "::error::'Invalid keyData' means the key text changed when it was pasted. Set it from the .pem file:"
echo "::error::gh secret set HARNESS_AUDIT_APP_PRIVATE_KEY --org $GITHUB_REPOSITORY_OWNER --visibility selected --repos <specs repo>,<code repo> < key.pem"
echo "::error::Then run gate.py doctor from the specs repo."

- name: Check the hash chain and publish
env:
HARNESS_AUDIT_TOKEN: ${{ steps.audit.outputs.token }}
Expand Down
33 changes: 30 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ on:
description: Optional shell command to install the code toolchain (code PRs)
type: string
default: ""
specs_repo:
description: owner/name of the specs repo (code PRs). Its config and specs are read from its default branch
type: string
default: ""
secrets:
HARNESS_APP_ID:
required: true
Expand All @@ -45,6 +49,14 @@ jobs:
private-key: ${{ secrets.HARNESS_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Explain a failed App token
if: failure() && steps.app.outcome == 'failure'
run: |
echo "::error::Cannot create the harness App token: HARNESS_APP_ID or HARNESS_APP_PRIVATE_KEY is wrong (G32)."
echo "::error::'Invalid keyData' means the key text changed when it was pasted. Set it from the .pem file:"
echo "::error::gh secret set HARNESS_APP_PRIVATE_KEY --org $GITHUB_REPOSITORY_OWNER --visibility selected --repos <specs repo>,<code repo> < key.pem"
echo "::error::Then run gate.py doctor from the specs repo."

- name: Check out the harness (outside the workspace)
env:
TOKEN: ${{ steps.app.outputs.token }}
Expand All @@ -58,6 +70,21 @@ jobs:
fetch-depth: 0
persist-credentials: false

- name: Check out the specs repo (code PRs; outside the workspace)
env:
TOKEN: ${{ steps.app.outputs.token }}
KIND: ${{ inputs.kind }}
SPECS_REPO: ${{ inputs.specs_repo }}
run: |
if [ "$KIND" != "code" ]; then echo "SPECS_DIR=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"; exit 0; fi
if [ -z "$SPECS_REPO" ]; then
echo "::error::kind: code needs the specs_repo input: the config (harness-overrides.yaml) and the specs live there (G33)"
exit 2
fi
git -c "http.extraheader=AUTHORIZATION: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" \
clone --quiet --depth 1 "https://github.com/$SPECS_REPO.git" "$RUNNER_TEMP/specs"
echo "SPECS_DIR=$RUNNER_TEMP/specs" >> "$GITHUB_ENV"

- uses: actions/setup-python@v5
with:
python-version: "3.12"
Expand All @@ -69,7 +96,7 @@ jobs:
run: ${{ inputs.setup_command }}

- name: Config check
run: python "$HARNESS_HOME/harness/gates/gate.py" config-check
run: python "$HARNESS_HOME/harness/gates/gate.py" config-check --repo "$SPECS_DIR"

- name: Validators
env:
Expand All @@ -79,11 +106,11 @@ jobs:
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
printf '%s\n' "$PR_BODY" > "$RUNNER_TEMP/pr-body.md"
python "$HARNESS_HOME/harness/gates/gate.py" ci --kind "${{ inputs.kind }}" \
--base "origin/$GITHUB_BASE_REF" --head HEAD --branch "$GITHUB_HEAD_REF" \
--repo "$SPECS_DIR" --code-repo "$GITHUB_WORKSPACE" --base "origin/$GITHUB_BASE_REF" --head HEAD --branch "$GITHUB_HEAD_REF" \
--event pull_request --pr-body-file "$RUNNER_TEMP/pr-body.md"
else
base="$BEFORE"
if [ -z "$base" ] || [ "$base" = "0000000000000000000000000000000000000000" ]; then base="HEAD~1"; fi
python "$HARNESS_HOME/harness/gates/gate.py" ci --kind "${{ inputs.kind }}" \
--base "$base" --head HEAD --branch "$GITHUB_REF_NAME" --event push
--repo "$SPECS_DIR" --code-repo "$GITHUB_WORKSPACE" --base "$base" --head HEAD --branch "$GITHUB_REF_NAME" --event push
fi
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ pushes, secret reads and audit-folder access. Use `harness run` for a role step:
1. Create the GitHub App with the permissions in section 5.1. Install it on the issue, specs, code **and harness**
repos (the workflows clone the harness with it).
2. Add org secrets `HARNESS_APP_ID`, `HARNESS_APP_PRIVATE_KEY`, `ANTHROPIC_API_KEY`.
Set the private keys from the `.pem` file, not by pasting into the web form. A pasted key often loses its
line breaks, and every run then stops with `Invalid keyData`:
```
gh secret set HARNESS_APP_PRIVATE_KEY --org <org> --visibility selected --repos <specs>,<code> < harness-app.pem
gh secret set HARNESS_AUDIT_APP_PRIVATE_KEY --org <org> --visibility selected --repos <specs> < audit-app.pem
```
`doctor` sees only the secret names. When a key is wrong, the workflow step after the App token says which
secret to set again.
3. Rulesets on `main`, `develop`, `release/*`, `hotfix/*`: PR, human approval, green checks. The App is not a bypass actor.
4. Add the Project Status options from `pbi.github.project.status_map`.
5. Create the audit repo and the `harness-audit` App (Contents: write on that repo only). Add
Expand Down
2 changes: 2 additions & 0 deletions docs/trial-shoplite/gaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ Status: `open`, `confirmed`, `fixed`, `rejected`.
| G29 | Phase A | A local agent session loaded the person's own setup: `~/AGENTS.md` (the agent tried `npx openskills`), ~70 personal skills, and the claude.ai connectors (Gmail, Drive). Local and CI runs differed. | local PO run 20261128T142904Z-po-pbi1 init event | security | `harness` starts `claude` with `--setting-sources project,local`, `--strict-mcp-config` and no MCP servers, and turns off the built-in AGENTS.md plugin | `harness/runner.py` | fixed |
| G30 | Phase A | The live log printed dozens of empty `· thinking_tokens:` lines | local PO run 20261128T142904Z-po-pbi1 | friction | Skip system events with no text | `harness/runner.py` | fixed |
| G31 | Phase A | The network guard blocked a Bash command that only wrote the PR description: the heredoc text held a link (`https://claude.com/claude-code`). The agent had to retry with Write. | local PO run 20261128T143758Z-po-pbi1 | friction | URLs in a heredoc fed to `cat` or `tee` are not scanned. A heredoc fed to `python3 -` or `sh` still is | `harness/hooks/pre_tool_use.py` | fixed |
| G32 | Phase A | Every run stopped at the App token step with `Invalid keyData`: the private key secret was pasted into the web form and changed. `doctor` sees only secret names, and the error does not say which secret is wrong or how to set it. | ai-sdlc-spec runs 14:31 to 14:49 | blocker | README: set the keys with `gh secret set … < key.pem`. A step after each App token step names the secret and prints that command when the token fails | `README.md`, `.github/workflows/validate.yml`, `.github/workflows/run-role.yml` | fixed |
| G33 | Phase A | The code repo validators never worked: `validate.yml` loaded the config from the code repo, which has no `harness-overrides.yaml`, so the `$GITHUB_ORG`/`$REPO_*` placeholders stayed undefined. The dev exit gate also needs the specs. | ai-sdlc-code1#3: "config uses undefined variable(s)" | blocker | `validate.yml` input `specs_repo`: code PRs clone the specs repo and run `gate.py ci --repo <specs> --code-repo .`. `doctor` FAILs when the code repo does not pass `specs_repo` | `.github/workflows/validate.yml`, `harness/gates/gate.py`, `harness/gates/doctor.py` | fixed |
5 changes: 3 additions & 2 deletions examples/code-repo/.github/workflows/harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ jobs:
if: >-
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.action != 'closed')
uses: <org>/ai-sdlc-harness/.github/workflows/validate.yml@v1.3.0
uses: <org>/ai-sdlc-harness/.github/workflows/validate.yml@v1.3.2
with:
kind: code
harness_repo: <org>/ai-sdlc-harness
harness_ref: v1.3.0
harness_ref: v1.3.2
specs_repo: <org>/<specs-repo> # the config and the specs live there
setup_command: "" # for example: dotnet restore && npm ci
secrets: inherit

Expand Down
10 changes: 5 additions & 5 deletions examples/specs-repo/.github/workflows/harness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ permissions:
jobs:
validate:
if: github.event_name == 'pull_request' || github.event_name == 'push'
uses: <org>/ai-sdlc-harness/.github/workflows/validate.yml@v1.3.0
uses: <org>/ai-sdlc-harness/.github/workflows/validate.yml@v1.3.2
with:
kind: specs
harness_repo: <org>/ai-sdlc-harness
harness_ref: v1.3.0
harness_ref: v1.3.2
secrets: inherit

route:
Expand All @@ -58,7 +58,7 @@ jobs:
run: |
echo "HARNESS_HOME=$RUNNER_TEMP/harness" >> "$GITHUB_ENV"
git -c "http.extraheader=AUTHORIZATION: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" \
clone --quiet --depth 1 --branch v1.3.0 "https://github.com/<org>/ai-sdlc-harness.git" "$RUNNER_TEMP/harness"
clone --quiet --depth 1 --branch v1.3.2 "https://github.com/<org>/ai-sdlc-harness.git" "$RUNNER_TEMP/harness"
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -81,12 +81,12 @@ jobs:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.route.outputs.matrix) }}
uses: <org>/ai-sdlc-harness/.github/workflows/run-role.yml@v1.3.0
uses: <org>/ai-sdlc-harness/.github/workflows/run-role.yml@v1.3.2
with:
role: ${{ matrix.role }}
pbi: ${{ matrix.pbi }}
task: ${{ matrix.task }}
pr_number: ${{ matrix.pr_number }}
harness_repo: <org>/ai-sdlc-harness
harness_ref: v1.3.0
harness_ref: v1.3.2
secrets: inherit
13 changes: 13 additions & 0 deletions harness/gates/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def run(cfg: dict, gh: GitHub | None, specs_dir: Path | None = None) -> list[tup
branch = repos.get("code_default_branch", "develop")
texts[code] = _remote_workflows(gh, code, branch)
rows += default_branch_check(gh, code, branch)
rows += code_validate_check(code, texts[code])
rows += workflow_access(gh, {repo: workflow_refs(files) for repo, files in texts.items()})
rows += secrets_check(gh, texts)
return rows
Expand Down Expand Up @@ -161,6 +162,18 @@ def secrets_check(gh: GitHub, texts: dict[str, list[str]]) -> list[tuple[str, st
return rows


def code_validate_check(repo: str, texts: list[str]) -> list[tuple[str, str, str]]:
"""A code repo calls validate.yml with `kind: code` and `specs_repo`: the config and the specs
live in the specs repo. Without it the validators stop on the config placeholders (G33)."""
calls = [t for t in texts if "workflows/validate.yml@" in t and re.search(r"^\s*kind:\s*code\b", t, re.M)]
if not calls:
return []
if all(re.search(r"^\s*specs_repo:\s*\S+/\S+", t, re.M) for t in calls):
return [("code validate", "PASS", f"{repo}: validate.yml gets specs_repo")]
return [("code validate", "FAIL", f"{repo}: validate.yml (kind: code) needs `specs_repo: <owner>/<specs repo>`. "
"Copy it from examples/code-repo/.github/workflows/harness.yml")]


def default_branch_check(gh: GitHub, repo: str, branch: str) -> list[tuple[str, str, str]]:
"""GitHub runs `issue_comment` and `repository_dispatch` with the workflow file of the
repo's default branch. When that is not `branch` and has no harness workflow, comments on
Expand Down
11 changes: 7 additions & 4 deletions harness/gates/gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ def cmd_next(args) -> int:
def cmd_ci(args) -> int:
"""CI on every PR (section 9): run all validators again. Stops what got past the hooks."""
cfg = _load(args)
repo = Path(args.repo).resolve()
changed = [f for f in gitutil.git(repo, "diff", "--name-only", f"{args.base}...{args.head}").splitlines() if f]
repo = Path(args.repo).resolve() # the specs repo: config and specs
# A code PR: the diff, commits, lint and tests are in the code repo (G33)
code = Path(args.code_repo).resolve() if args.kind == "code" and args.code_repo else repo
changed = [f for f in gitutil.git(code, "diff", "--name-only", f"{args.base}...{args.head}").splitlines() if f]
branch = args.branch or ""
reports: list[ops.OutputReport] = []
failed = False
Expand Down Expand Up @@ -215,9 +217,9 @@ def fail(msg: str) -> None:
m = ops.FEATURE_BRANCH_RE.fullmatch(branch)
if m:
reports += ops.exit_gate(cfg, "dev", m.group("pbi"), repo, task=m.group("task"),
code_repo=repo, base=args.base, head=args.head)
code_repo=code, base=args.base, head=args.head)
else:
ctx = v.Context(cfg=cfg, repo_dir=repo, code_repo=repo)
ctx = v.Context(cfg=cfg, repo_dir=code, code_repo=code)
reports.append(ops.OutputReport("code:lint+tests", v.run(["lint", "tests"], ctx)))

harness_branch = ops.SPEC_BRANCH_RE.fullmatch(branch) or ops.FEATURE_BRANCH_RE.fullmatch(branch)
Expand Down Expand Up @@ -326,6 +328,7 @@ def common(sp, role=True, pbi=True):
sp.add_argument("--branch", help="PR head branch (spec/<pbi>/<role> or feature/<pbi>-<task>)")
sp.add_argument("--event", default="pull_request", choices=["pull_request", "push"])
sp.add_argument("--pr-body-file")
sp.add_argument("--code-repo", help="code repo folder (--kind code); --repo is then the specs repo")
sp.set_defaults(fn=cmd_ci)

sp = common(sub.add_parser("config-check", help="check harness.yaml + overrides"), role=False, pbi=False)
Expand Down
2 changes: 1 addition & 1 deletion harness/harness.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Harness defaults. A consumer repo overrides values in harness-overrides.yaml.
# Merge rule: maps merge key by key, lists and scalars are replaced.
harness_version: 1.3.0
harness_version: 1.3.2
template_version: 1.1.0

pbi:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,11 @@ def test_secrets_unreadable_warn():
r["/repos/acme/specs/actions/secrets"] = GitHubError(403, "Must have admin rights")
[(n, s, d)] = doctor.secrets_check(FakeGH(r), {"acme/specs": [CALLER]})
assert s == "WARN" and "ANTHROPIC_API_KEY, HARNESS_APP_ID" in d


def test_code_validate_needs_specs_repo():
without = "jobs:\n v:\n uses: acme/h/.github/workflows/validate.yml@v1\n with:\n kind: code\n"
with_it = without + " specs_repo: acme/specs\n"
assert doctor.code_validate_check("acme/code", [without])[0][1] == "FAIL"
assert doctor.code_validate_check("acme/code", [with_it])[0][1] == "PASS"
assert doctor.code_validate_check("acme/code", ["jobs: {}\n"]) == []
21 changes: 21 additions & 0 deletions tests/test_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,24 @@ def test_ci_specs_pr(specs_repo, merge_role, tmp_path):
proc = subprocess.run(GATE + args, capture_output=True, text=True)
assert proc.returncode == 1
assert "status is draft" in proc.stdout and "may not change specs/123/product.md" in proc.stdout


def test_ci_code_pr_reads_config_from_the_specs_repo(specs_repo, tmp_path):
"""G33: a code PR runs in the code repo, with the config and specs of the specs repo."""
code = tmp_path / "code"
code.mkdir()
git(code, "init", "-q", "-b", "develop")
(code / "README.md").write_text("code\n")
git(code, "add", ".")
git(code, "commit", "-q", "-m", "chore: init")
git(code, "checkout", "-q", "-b", "chore/readme")
(code / "README.md").write_text("code, more\n")
git(code, "commit", "-qam", "docs: readme")
args = ["ci", "--kind", "code", "--repo", str(specs_repo), "--code-repo", str(code),
"--base", "develop", "--branch", "chore/readme", "--event", "pull_request"]
proc = subprocess.run(GATE + args, capture_output=True, text=True)
out = proc.stdout + proc.stderr
# The config loaded (no usage error), and lint and tests ran in the code repo: they fail here
# only because this code repo is empty.
assert proc.returncode == 1, out # 2 would be a usage or config error
assert "code:lint+tests" in out and str(code / "package.json") in out
Loading