diff --git a/.github/issue-investigation/tests/test_entrypoint.py b/.github/issue-investigation/tests/test_entrypoint.py new file mode 100644 index 000000000..0b966db53 --- /dev/null +++ b/.github/issue-investigation/tests/test_entrypoint.py @@ -0,0 +1,105 @@ +"""Offline policy checks for the thin AdvancedCore caller; no model/API calls.""" +from pathlib import Path +import re +import unittest + +ROOT = Path(__file__).resolve().parents[2] +WORKFLOW = ROOT / "workflows" / "investigate-issue.yml" +PIN = "68cd96bce3684462baffa569a26295965af36339" + + +def validate(text): + triggers = text.split("\non:\n", 1)[1].split("\npermissions:", 1)[0] + if re.findall(r"^ ([A-Za-z_]+):", triggers, re.M) != ["workflow_dispatch"]: + raise ValueError("Only manual dispatch is allowed") + for required in ( + "github.repository == 'BenCodez/AdvancedCore'", + "github.ref == 'refs/heads/master'", + "github.event_name == 'workflow_dispatch'", + "uses: BenCodez/VotingPlugin/.github/workflows/investigate-issue-reusable.yml@" + PIN, + "issue_number: ${{ inputs.issue_number }}", + "timeout_minutes: ${{ inputs.timeout_minutes }}", + "openai_project_id: ${{ vars.OPENAI_PROJECT_ID }}", + "OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}", + ): + if required not in text: + raise ValueError("Caller binding changed") + jobs = text.split("\njobs:\n", 1)[1] + if re.findall(r"^ (\w+):$", jobs, re.M) != ["investigate"]: + raise ValueError("Only the shared investigation job is allowed") + if len(re.findall(r"^ uses:", jobs, re.M)) != 1 or "run:" in jobs or "steps:" in jobs: + raise ValueError("No local engine or additional execution") + if re.findall(r"^ (\w+):", jobs, re.M) != [ + "issue_number", "timeout_minutes", "openai_project_id", "OPENAI_API_KEY" + ]: + raise ValueError("Only the explicit shared interface is allowed") + if "write" in text or "inherit" in text or "post_comment" in text: + raise ValueError("Caller must not publish or inherit credentials") + if re.findall(r"^ (actions|contents|issues): (\w+)$", text, re.M) != [ + ("actions", "read"), ("contents", "read"), ("issues", "read") + ]: + raise ValueError("Read-only permissions required") + if re.findall(r"^ (\w+):$", triggers, re.M) != ["issue_number", "timeout_minutes"]: + raise ValueError("Issue data cannot choose execution policy") + if "default: '15'" not in triggers: + raise ValueError("Bounded manual default required") + + +class EntrypointTests(unittest.TestCase): + def setUp(self): + self.text = WORKFLOW.read_text() + + def test_exact_manual_no_post_caller(self): + validate(self.text) + + def test_automatic_event_rejected(self): + with self.assertRaises(ValueError): + validate(self.text.replace(" workflow_dispatch:", " issues:\n types: [opened]\n workflow_dispatch:")) + + def test_mutable_or_changed_pin_rejected(self): + for changed in ("master", "0" * 40): + with self.subTest(changed=changed), self.assertRaises(ValueError): + validate(self.text.replace(PIN, changed)) + + def test_issue_write_and_inherited_secrets_rejected(self): + for changed in ( + self.text.replace("issues: read", "issues: write"), + self.text.replace(" secrets:", " secrets: inherit\n unused:"), + ): + with self.assertRaises(ValueError): + validate(changed) + + def test_post_option_and_ref_input_rejected(self): + for added in ("post_comment", "engine_ref"): + with self.subTest(added=added), self.assertRaises(ValueError): + validate(self.text.replace(" inputs:", " inputs:\n " + added + ":\n type: string")) + + def test_forwarded_inputs_cannot_be_overridden_or_swapped(self): + for original, changed in ( + ("issue_number: ${{ inputs.issue_number }}", "issue_number: '42'"), + ("timeout_minutes: ${{ inputs.timeout_minutes }}", "timeout_minutes: '30'"), + ("issue_number: ${{ inputs.issue_number }}", "issue_number: ${{ inputs.timeout_minutes }}"), + ("timeout_minutes: ${{ inputs.timeout_minutes }}", "timeout_minutes: ${{ inputs.issue_number }}"), + ): + with self.subTest(changed=changed), self.assertRaises(ValueError): + validate(self.text.replace(original, changed)) + + def test_extra_job_or_execution_rejected(self): + for extra in ( + "\n extra:\n runs-on: ubuntu-latest\n", + "\n steps:\n - run: echo unsafe\n", + ): + with self.subTest(extra=extra), self.assertRaises(ValueError): + validate(self.text + extra) + + def test_operator_key_name_and_canonical_caller_preserved(self): + for old, new in ( + ("OPENAI_API_KEY", "OTHER_KEY"), + ("BenCodez/AdvancedCore", "BenCodez/Other"), + ): + with self.subTest(old=old), self.assertRaises(ValueError): + validate(self.text.replace(old, new)) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/investigate-issue.yml b/.github/workflows/investigate-issue.yml new file mode 100644 index 000000000..e5df053f3 --- /dev/null +++ b/.github/workflows/investigate-issue.yml @@ -0,0 +1,30 @@ +name: Investigate issue without posting + +on: + workflow_dispatch: + inputs: + issue_number: + description: AdvancedCore issue number to investigate + required: true + type: string + timeout_minutes: + description: Maximum agent runtime (5 to 30 minutes; not a spending cap) + required: true + default: '15' + type: string + +permissions: + actions: read + contents: read + issues: read + +jobs: + investigate: + if: ${{ github.repository == 'BenCodez/AdvancedCore' && github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch' }} + uses: BenCodez/VotingPlugin/.github/workflows/investigate-issue-reusable.yml@68cd96bce3684462baffa569a26295965af36339 + with: + issue_number: ${{ inputs.issue_number }} + timeout_minutes: ${{ inputs.timeout_minutes }} + openai_project_id: ${{ vars.OPENAI_PROJECT_ID }} + secrets: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} diff --git a/docs/issue-investigation.md b/docs/issue-investigation.md new file mode 100644 index 000000000..0075dcd83 --- /dev/null +++ b/docs/issue-investigation.md @@ -0,0 +1,83 @@ +# Manual issue investigation + +The **Investigate issue without posting** workflow is a manual entrypoint to the +shared VotingPlugin investigator. It has no issue, push or scheduled trigger and +never posts a public issue comment. The caller pins the shared workflow to an +immutable revision; it does not copy the engine into AdvancedCore. + +## Before activation + +Merging the caller does not provision or verify hosted prerequisites. An +authorized custodian must verify the existing configuration and protection rules: + +- The existing secret name is `OPENAI_API_KEY`. No key is created by this change. +- `OPENAI_PROJECT_ID` must identify the approved project. +- `ISSUE_INVESTIGATION_POLICY_URL` and + `ISSUE_INVESTIGATION_DISCLOSURE_SHA256` must identify the approved policy. +- The shared runner's budget, persistent claim ledger, artifact storage, + authentication and cleanup requirements must be qualified for this repository. + +Do not infer missing credentials from an inventory permission error. The caller +passes only the named key, with read-only Actions, contents and issue permissions. +It does not use inherited secrets or grant issue-write permission. Issue text +cannot select the shared revision, project or workflow command. + +Only an independently approved, bounded hosted smoke run can establish actual +Actions provenance, configuration, model accounting and artifact receipt behavior. +Local fixtures and a merged workflow are not hosted acceptance. + +## Manual use after approval + +Run from the default `master` branch using **Actions → Investigate issue without +posting → Run workflow**. Enter an AdvancedCore issue number and a runtime limit +between 5 and 30 minutes; the default is 15. This limit is not a dollar cap. +There is no posting opt-in in this caller. A public reply requires a separately +authorized, reviewed publication route. + +Successful shared runs emit outcome, artifact ID, evidence revision, source SHA +and engine SHA receipts. Reports are unreviewed analysis, not proof a defect was +reproduced. Skipped or failed admission must not be described as an investigation. +Use the exact producing run/attempt and source/engine identities when accepting +an artifact; do not substitute a report from another revision. + +## AdvancedCore evidence and builds + +AdvancedCore is a library embedded by plugins. Establish the reported consumer, +AdvancedCore version and actual loaded artifact before attributing runtime +behavior. Compare reported-version source separately from current development +source. A SNAPSHOT label or Maven dependency declaration does not identify JAR +bytes. SimpleAPI is a dependency and VotingPlugin is a consumer; verify their +actual revisions and artifacts independently. + +The project is `AdvancedCore/pom.xml` and currently builds with JDK 21: + +```sh +mvn -B -f AdvancedCore/pom.xml test +mvn -B -f AdvancedCore/pom.xml package +``` + +Use focused tests first where appropriate. Do not use deployment, install or +developer-copy profiles for investigation. Build success does not establish +acceptance on the affected server or consumer. + +See the [README](https://github.com/BenCodez/AdvancedCore/blob/master/README.md), +[release tags](https://github.com/BenCodez/AdvancedCore/tags), +[development source](https://github.com/BenCodez/AdvancedCore/tree/master) and +[reward documentation](https://github.com/BenCodez/AdvancedCore/wiki/Rewards). +Reports must pin source citations to the actual inspected revision. A source-tree +link is not a verified successful development build or downloadable JAR receipt. + +## Rollback + +Stop new dispatches through the authorized workflow controls. Reconcile in-flight +remote sessions, claims, artifacts and pending charges with their existing owner; +disabling the entrypoint does not prove work stopped. Preserve ambiguous claims +and deduplication/budget evidence. Do not delete or rotate credentials as part of +rollback. An approved source revert of this thin caller must leave the shared +engine and unrelated workflows unchanged. + +## Local validation + +Run `python3 -m unittest discover -s .github/issue-investigation/tests -v` and lint +the caller with Actionlint. Shared admission, artifact, budget and posting tests +belong to the exact pinned shared revision; caller checks do not replace them.