diff --git a/.github/workflows/discussion-draft.lock.yml b/.github/workflows/discussion-draft.lock.yml index 872920b8..b321cb82 100644 --- a/.github/workflows/discussion-draft.lock.yml +++ b/.github/workflows/discussion-draft.lock.yml @@ -1,4 +1,4 @@ -# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"b3e5c051b1bfaff6a729a15c438248e7d4f2f32e783c8cfec7d47d321009367f","body_hash":"e55e7fae6d5aa41a4f8265903890ddb3474f9a49ffc1854e7cbc423d2077c30b","compiler_version":"v0.93.5","strict":true,"agent_id":"copilot","agent_model":"gpt-6.1-sol","engine_versions":{"copilot":"1.0.101"}} +# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"a6472b4a4d36874d4b92ae7b03dbd77a17fdf8d5f60c379b06aee4e64475c62d","body_hash":"2fdb281965f78dc8fe852f4ff5d0e5dd1700fcedbd8fcf1a67f82868805b9e45","compiler_version":"v0.93.5","strict":true,"agent_id":"copilot","agent_model":"gpt-6.1-sol","engine_versions":{"copilot":"1.0.101"}} # gh-aw-manifest: {"version":1,"secrets":["GH_AW_DEFAULT_OTLP_ENDPOINT","GH_AW_DEFAULT_OTLP_HEADERS","GH_AW_GITHUB_MCP_SERVER_TOKEN","GH_AW_GITHUB_TOKEN","GITHUB_TOKEN"],"actions":[{"repo":"actions/checkout","sha":"3d3c42e5aac5ba805825da76410c181273ba90b1","version":"v7.0.1"},{"repo":"actions/checkout","sha":"d23441a48e516b6c34aea4fa41551a30e30af803","version":"d23441a48e516b6c34aea4fa41551a30e30af803"},{"repo":"actions/download-artifact","sha":"9000827ccba6bdab643e8b6fd33ac0654aef8333","version":"9000827ccba6bdab643e8b6fd33ac0654aef8333"},{"repo":"actions/github-script","sha":"3a2844b7e9c422d3c10d287c895573f7108da1b3","version":"3a2844b7e9c422d3c10d287c895573f7108da1b3"},{"repo":"actions/setup-node","sha":"949feb2413d6458794dcd2491c4babbbce0c15c1","version":"v7.1.0"},{"repo":"actions/upload-artifact","sha":"cf430e030ddbb5b0abf93d22962f4752f3646cd9","version":"cf430e030ddbb5b0abf93d22962f4752f3646cd9"},{"repo":"github/gh-aw/actions/setup","sha":"32ecafbc061c9af57e9361942099e381102ae304","version":"32ecafbc061c9af57e9361942099e381102ae304"}],"containers":[{"image":"ghcr.io/github/gh-aw-firewall/agent:0.28.70","digest":"sha256:b15ab48cbbab02904eb9bbd359a398db59690eebbea1e6934d47ed2bb407dd34","pinned_image":"ghcr.io/github/gh-aw-firewall/agent:0.28.70@sha256:b15ab48cbbab02904eb9bbd359a398db59690eebbea1e6934d47ed2bb407dd34"},{"image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.28.70","digest":"sha256:9ac8f9c7294e892c916de3da9d2588dfd8cd4931e5c39b00143266d7ed9fd52a","pinned_image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.28.70@sha256:9ac8f9c7294e892c916de3da9d2588dfd8cd4931e5c39b00143266d7ed9fd52a"},{"image":"ghcr.io/github/gh-aw-firewall/squid:0.28.70","digest":"sha256:b5bc53f4becfd96e926e63c83831f1b3c9512f713c83161d2b8c9b7204b3e917","pinned_image":"ghcr.io/github/gh-aw-firewall/squid:0.28.70@sha256:b5bc53f4becfd96e926e63c83831f1b3c9512f713c83161d2b8c9b7204b3e917"},{"image":"ghcr.io/github/gh-aw-mcpg:v0.4.37","digest":"sha256:9c7f242f6dec2d7d7b55d4c9e07872d59b85377c6cb3de46c915a5d1ffb91442","pinned_image":"ghcr.io/github/gh-aw-mcpg:v0.4.37@sha256:9c7f242f6dec2d7d7b55d4c9e07872d59b85377c6cb3de46c915a5d1ffb91442"},{"image":"ghcr.io/github/gh-aw-node","digest":"sha256:23746305eeded20dc2726ab18bb081962d66ee3b2e09a54291afd1869ab3ef6d","pinned_image":"ghcr.io/github/gh-aw-node@sha256:23746305eeded20dc2726ab18bb081962d66ee3b2e09a54291afd1869ab3ef6d"},{"image":"ghcr.io/github/github-mcp-server:v2.0.3","digest":"sha256:250bc6ce70788207608ef74cef4397230ff2e8481218da74d6093e4bd9101132","pinned_image":"ghcr.io/github/github-mcp-server:v2.0.3@sha256:250bc6ce70788207608ef74cef4397230ff2e8481218da74d6093e4bd9101132"}],"mcp_servers":[{"name":"github","tools":["get_discussion","get_discussion_comments","get_file_contents","issue_read","list_issues","list_pull_requests","pull_request_read","search_issues","search_pull_requests"]},{"name":"safeoutputs","tools":["noop","report_incomplete","report_missing_data"]}],"threat_detection":{"mode":"enabled"},"admission":false} # This file was automatically generated by gh-aw (v0.93.5). DO NOT EDIT. To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md # @@ -47,7 +47,6 @@ on: discussion_comment: types: - created - # github-token: ${{ secrets.GITHUB_TOKEN }} # GitHub token used for reactions and status comments in activation issue_comment: types: - created @@ -94,6 +93,9 @@ jobs: permissions: actions: read contents: read + discussions: write + issues: write + pull-requests: write env: GH_AW_MAX_DAILY_AI_CREDITS: ${{ vars.GH_AW_DEFAULT_MAX_DAILY_AI_CREDITS || '5000' }} GH_AW_RUNTIME_FEATURES: ${{ vars.GH_AW_RUNTIME_FEATURES }} @@ -219,6 +221,21 @@ jobs: overwrite: true if-no-files-found: ignore retention-days: ${{ vars.GH_AW_DEFAULT_ARTIFACT_RETENTION_DAYS || '3' }} + - name: Add eyes reaction for immediate feedback + id: react + if: github.event_name == 'issues' || github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment' || github.event_name == 'discussion' || github.event_name == 'discussion_comment' || github.event_name == 'pull_request' && github.event.pull_request.head.repo.id == github.repository_id + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + GH_AW_REACTION: "eyes" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const path = require('path'); + const actionsDir = path.join(process.env.RUNNER_TEMP, 'gh-aw', 'actions'); + const { setupGlobals } = require(path.join(actionsDir, 'setup_globals.cjs')); + setupGlobals(core, github, context, exec, io, getOctokit); + const { main } = require(path.join(actionsDir, 'add_reaction.cjs')); + await main(); - name: Check for OAuth tokens id: check-oauth-tokens run: bash "${RUNNER_TEMP}/gh-aw/actions/check_oauth_tokens.sh" @@ -305,7 +322,7 @@ jobs: GH_AW_GITHUB_RUN_ID: ${{ github.run_id }} GH_AW_GITHUB_WORKSPACE: ${{ github.workspace }} GH_AW_PROMPT_CONTENT_0000: "\n" - GH_AW_PROMPT_CONTENT_0001: "\nTools: report_missing_data, noop(max:3)\n" + GH_AW_PROMPT_CONTENT_0001: "\nTools: report_missing_data, noop(max:2)\n" GH_AW_PROMPT_CONTENT_0002: "\n" GH_AW_PROMPT_CONTENT_0003: "\nThe following GitHub context information is available for this workflow:\n{{#if github.actor}}\n- **actor**: __GH_AW_GITHUB_ACTOR__\n{{/if}}\n{{#if github.repository}}\n- **repository**: __GH_AW_GITHUB_REPOSITORY__\n{{/if}}\n{{#if github.workspace}}\n- **workspace**: __GH_AW_GITHUB_WORKSPACE__\n{{/if}}\n{{#if github.event.issue.number || (github.aw.context.item_type == 'issue' && github.aw.context.item_number)}}\n- **issue-number**: #__GH_AW_EXPR_7C248226__\n{{/if}}\n{{#if github.event.discussion.number || (github.aw.context.item_type == 'discussion' && github.aw.context.item_number)}}\n- **discussion-number**: #__GH_AW_EXPR_C19C384F__\n{{/if}}\n{{#if github.event.pull_request.number || (github.aw.context.item_type == 'pull_request' && github.aw.context.item_number)}}\n- **pull-request-number**: #__GH_AW_EXPR_76DF9333__\n{{/if}}\n{{#if github.event.comment.id || github.aw.context.comment_id}}\n- **comment-id**: __GH_AW_EXPR_77C1A4D2__\n{{/if}}\n{{#if github.run_id}}\n- **workflow-run-id**: __GH_AW_GITHUB_RUN_ID__\n{{/if}}\n\n\n" GH_AW_PROMPT_CONTENT_0004: "\n" @@ -574,13 +591,6 @@ jobs: env: GH_AW_SKILL_DIR: ".github/skills" run: bash "${RUNNER_TEMP}/gh-aw/actions/restore_inline_skills.sh" - - env: - GH_AW_SAFE_OUTPUTS: ${{ steps.set-runtime-paths.outputs.GH_AW_SAFE_OUTPUTS }} - id: require_candidate_detection - name: Require candidate threat detection - run: "const fs = require(\"node:fs\");\nconst path = require(\"node:path\");\nfs.mkdirSync(path.dirname(process.env.GH_AW_SAFE_OUTPUTS), { recursive: true });\nfs.appendFileSync(process.env.GH_AW_SAFE_OUTPUTS, JSON.stringify({\n type: \"noop\",\n message: \"This read-only workflow requires threat detection of its candidate artifact before sealing.\"\n}) + \"\\n\");\n" - shell: node {0} - - name: Download container images run: bash "${RUNNER_TEMP}/gh-aw/actions/download_docker_images.sh" ghcr.io/github/gh-aw-firewall/agent:0.28.70@sha256:b15ab48cbbab02904eb9bbd359a398db59690eebbea1e6934d47ed2bb407dd34 ghcr.io/github/gh-aw-firewall/api-proxy:0.28.70@sha256:9ac8f9c7294e892c916de3da9d2588dfd8cd4931e5c39b00143266d7ed9fd52a ghcr.io/github/gh-aw-firewall/squid:0.28.70@sha256:b5bc53f4becfd96e926e63c83831f1b3c9512f713c83161d2b8c9b7204b3e917 ghcr.io/github/gh-aw-mcpg:v0.4.37@sha256:9c7f242f6dec2d7d7b55d4c9e07872d59b85377c6cb3de46c915a5d1ffb91442 ghcr.io/github/gh-aw-node@sha256:23746305eeded20dc2726ab18bb081962d66ee3b2e09a54291afd1869ab3ef6d ghcr.io/github/github-mcp-server:v2.0.3@sha256:250bc6ce70788207608ef74cef4397230ff2e8481218da74d6093e4bd9101132 - name: Prepare Safe Outputs Directories @@ -593,7 +603,7 @@ jobs: env: GH_AW_FILE_ROOT: "${{ runner.temp }}/gh-aw" GH_AW_FILE_CONFIG: "{\"files\":[{\"path\":\"safeoutputs/config.json\",\"content_env\":\"GH_AW_SAFE_OUTPUTS_CONFIG\"}]}" - GH_AW_SAFE_OUTPUTS_CONFIG: "{\"noop\":{\"max\":3,\"report-as-issue\":\"false\"},\"report_incomplete\":{},\"report_missing_data\":{}}" + GH_AW_SAFE_OUTPUTS_CONFIG: "{\"noop\":{\"max\":2,\"report-as-issue\":\"false\"},\"report_incomplete\":{},\"report_missing_data\":{}}" with: script: | const path = require('path'); @@ -1295,7 +1305,7 @@ jobs: uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: GH_AW_AGENT_OUTPUT: ${{ steps.setup-agent-output-env.outputs.GH_AW_AGENT_OUTPUT }} - GH_AW_NOOP_MAX: "3" + GH_AW_NOOP_MAX: "2" GH_AW_WORKFLOW_NAME: "Prepare discussion draft" GH_AW_WORKFLOW_SOURCE_URL: "${{ github.server_url }}/${{ github.repository }}/blob/${{ github.ref_name }}/.github/workflows/discussion-draft.md" GH_AW_ENGINE_ID: "copilot" @@ -1944,9 +1954,10 @@ jobs: pre_activation: name: pre_activation if: > - github.repository == 'microsoft/TypeChat' && github.event.sender.type == 'User' && github.event.sender.id == 25374553 && + (github.event_name != 'issue_comment' || contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) && + (github.repository == 'microsoft/TypeChat' && github.event.sender.type == 'User' && github.event.sender.id == 25374553 && github.event.comment.user.id == 25374553 && github.triggering_actor == 'robgruen' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && - !github.event.issue.pull_request && startsWith(github.event.comment.body, '/typechat draft') + !github.event.issue.pull_request && startsWith(github.event.comment.body, '/typechat draft')) runs-on: ubuntu-latest env: GH_AW_RUNTIME_FEATURES: ${{ vars.GH_AW_RUNTIME_FEATURES }} @@ -2134,7 +2145,7 @@ jobs: GH_AW_ALLOWED_DOMAINS: "api.snapcraft.io,archive.ubuntu.com,azure.archive.ubuntu.com,crl.geotrust.com,crl.globalsign.com,crl.identrust.com,crl.sectigo.com,crl.thawte.com,crl.usertrust.com,crl.verisign.com,crl3.digicert.com,crl4.digicert.com,crls.ssl.com,json-schema.org,json.schemastore.org,keyserver.ubuntu.com,ocsp.digicert.com,ocsp.geotrust.com,ocsp.globalsign.com,ocsp.identrust.com,ocsp.sectigo.com,ocsp.ssl.com,ocsp.thawte.com,ocsp.usertrust.com,ocsp.verisign.com,packagecloud.io,packages.cloud.google.com,packages.microsoft.com,ppa.launchpad.net,s.symcb.com,s.symcd.com,security.ubuntu.com,ts-crl.ws.symantec.com,ts-ocsp.ws.symantec.com,www.googleapis.com" GITHUB_SERVER_URL: ${{ github.server_url }} GITHUB_API_URL: ${{ github.api_url }} - GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG: "{\"noop\":{\"max\":3,\"report-as-issue\":\"false\"},\"report_incomplete\":{},\"report_missing_data\":{}}" + GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG: "{\"noop\":{\"max\":2,\"report-as-issue\":\"false\"},\"report_incomplete\":{},\"report_missing_data\":{}}" GH_AW_GITHUB_TOKEN_SOURCE: "github_actions" with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/discussion-draft.md b/.github/workflows/discussion-draft.md index 1360971a..e0514123 100644 --- a/.github/workflows/discussion-draft.md +++ b/.github/workflows/discussion-draft.md @@ -9,6 +9,8 @@ on: types: [created] roles: [admin, maintain, write] github-token: ${{ secrets.GITHUB_TOKEN }} + reaction: eyes + status-comment: false if: &draft_request >- github.repository == 'microsoft/TypeChat' && github.event.sender.type == 'User' && @@ -28,10 +30,6 @@ imports: - shared/read-only-analysis.md safe-outputs: report-missing-tool: false - noop: - # One trusted scan signal plus the two existing model no-ops. - max: 3 - report-as-issue: false threat-detection: continue-on-error: false report-as-issue: false @@ -229,21 +227,6 @@ steps: artifact-ids: ${{ needs.prepare.outputs.context_artifact_id }} merge-multiple: true path: .typechat-draft -pre-agent-steps: - # The pinned detection guard only sees native output types, not file artifacts. - - name: Require candidate threat detection - id: require_candidate_detection - env: - GH_AW_SAFE_OUTPUTS: ${{ steps.set-runtime-paths.outputs.GH_AW_SAFE_OUTPUTS }} - shell: node {0} - run: | - const fs = require("node:fs"); - const path = require("node:path"); - fs.mkdirSync(path.dirname(process.env.GH_AW_SAFE_OUTPUTS), { recursive: true }); - fs.appendFileSync(process.env.GH_AW_SAFE_OUTPUTS, JSON.stringify({ - type: "noop", - message: "This read-only workflow requires threat detection of its candidate artifact before sealing." - }) + "\n"); post-steps: - name: Verify candidate draft file if: success() @@ -348,6 +331,10 @@ exactly `number`, `headSha` (the full inspected commit), and `updatedAt` (the inspected API update timestamp). Include at most eight PRs. Do not invent references or claim tests were executed. +After writing `discussion-draft.json`, call `safeoutputs-noop` with a brief +completion summary. Do not report completion before the file exists. This +native completion signal does not publish a comment or approve the draft. + The workflow will validate and freeze the exact rendered comment. Only a later -human-owner publish command can authorize posting it. Finish with a brief -summary; do not claim that anything was posted or accepted. +human-owner publish command can authorize posting it. Do not claim that anything +was posted or accepted. diff --git a/AUTOMATION.md b/AUTOMATION.md index 12d38c0a..0a580209 100644 --- a/AUTOMATION.md +++ b/AUTOMATION.md @@ -467,7 +467,7 @@ by `npm test`), including checks that the runtime pin matches the compilation command, generated drafting jobs cannot write to issues or pull requests, and the separate publisher has only its target-specific comment permission. The discussion tests execute the compiled detection guard with Bash (Git Bash -on Windows), including a candidate with no model-emitted safe outputs or patch. +on Windows), covering collected completion/incomplete signals and a missing signal. The assessment itself remains report-only and does not change existing maintenance and deployment workflows. The separate @@ -501,7 +501,16 @@ Editing a command does not trigger or authorize a run. Other users, bots, PR comments, non-default-branch code, and changed or deleted commands cannot authorize drafting or publication. Comment events may still show ignored or skipped workflow runs; they do not authorize model inference or posting. +An `eyes` reaction on the triggering command comment acknowledges that the +workflow has started processing the request. It is not confirmation that a draft +is ready, that scanning succeeded, or that work was accepted. Check Actions for +completion and errors. Native workflow code handles the reaction; the model +retains read-only access. No new public bot comment is made just to acknowledge a draft request. +The pinned compiler grants reaction-write permissions to trusted activation, +including `pull-requests: write` because GitHub also uses `issue_comment` for PR +comments. The owner-only workflow guard still excludes PR comments. These write +permissions are not granted to model execution, detection, or sealing. If the wording is wrong, do not approve it. Add clarification to the thread and request a new draft. There is no force-publish or editable-artifact shortcut. @@ -518,11 +527,19 @@ recorded requirements, suggested criteria, and a readiness recommendation. Thread context is bounded at 1 MiB and 1,000 comments, including replies; incomplete or oversized context is an error, not silent truncation. -Before model execution, a trusted step adds a read-only no-op to the native -safe-output stream. This makes the pinned runtime's detection guard run even -when the model writes only the candidate file and emits no safe outputs or patch. -The no-op limit reserves one slot for that signal in addition to the two existing -model no-ops; no-op issue reporting remains disabled. +Do not seed a native `noop` before model execution: the pinned runtime interprets +it as completed work and skips the model. The model writes the candidate first, +then emits its native completion signal. If it emits no terminal safe output, +the pinned collector records an explicit `report_incomplete` signal rather than +treating silence as successful work. The detection guard consumes the collected +output types; a missing signal cannot authorize sealing. + +The first owner-commanded [draft run](https://github.com/microsoft/TypeChat/actions/runs/41136773812) +on 2026-10-30 exposed this preflight behavior. The synthetic pre-agent no-op caused +the model to be skipped, so no candidate or sealed draft was produced. Detection +and sealing failed closed, and nothing was published. Removing that premature +completion signal needs a fresh owner-commanded live verification after merge; +the failed run is not evidence that drafting or scanning succeeded. The detector downloads the attempt-specific, immutable candidate artifact. Trusted code adds its complete JSON text to the detector's agent-output input, diff --git a/OWNER-CHEATSHEET.md b/OWNER-CHEATSHEET.md index e57903d0..0a5ef821 100644 --- a/OWNER-CHEATSHEET.md +++ b/OWNER-CHEATSHEET.md @@ -51,6 +51,10 @@ the command**, with no leading text. Editing an old comment does not trigger it. /typechat draft ``` +The Actions bot acknowledges the command comment with an `eyes` reaction when +the workflow starts processing it. This is not a success or acceptance signal; +check Actions for progress and errors. + **2. Review:** Open **Actions > Prepare discussion draft**, wait for the run to succeed, and read its summary's exact preview. Check factual accuracy, scope, existing contributions, unanswered questions, and suggested criteria. diff --git a/tools/tests/discussion-workflows.test.mjs b/tools/tests/discussion-workflows.test.mjs index 9fc12acd..df146588 100644 --- a/tools/tests/discussion-workflows.test.mjs +++ b/tools/tests/discussion-workflows.test.mjs @@ -58,13 +58,34 @@ test("discussion commands are created-comment events guarded by owner and truste } }); +test("draft requests use the native eyes acknowledgment without public status comments", () => { + assert.equal(source.on.reaction, "eyes"); + assert.equal(source.on["status-comment"], false); + assert.equal(source.on["github-token"], "${{ secrets.GITHUB_TOKEN }}"); + const activation = compiled.jobs.activation; + const reaction = activation.steps.find(step => step.name === "Add eyes reaction for immediate feedback"); + assert.ok(reaction); + assert.equal(reaction.env.GH_AW_REACTION, "eyes"); + assert.equal(reaction.with["github-token"], "${{ secrets.GITHUB_TOKEN }}"); + assert.match(reaction.with.script, /require\(path\.join\(actionsDir, 'add_reaction\.cjs'\)\)/); + for (const event of ["issue_comment", "discussion_comment"]) { + assert.ok(reaction.if.includes(`github.event_name == '${event}'`)); + } + assert.ok(activation.if.includes(source.if)); + assert.ok(!activation.steps.some(step => /status.*comment/i.test(step.name ?? ""))); + assert.deepEqual(activation.permissions, { + actions: "read", contents: "read", discussions: "write", issues: "write", "pull-requests": "write", + }); + assert.ok(activation.if.includes("!github.event.issue.pull_request")); + assert.equal(compiled.on.pull_request, undefined); +}); + test("drafting reuses the proven tools and model without enabling the future build budget", () => { assert.deepEqual(source.imports, ["shared/read-only-analysis.md"]); for (const key of Object.keys(shared)) { if (key === "safe-outputs") { - assert.deepEqual(Object.keys(source[key]), ["report-missing-tool", "noop", "threat-detection"]); + assert.deepEqual(Object.keys(source[key]), ["report-missing-tool", "threat-detection"]); assert.equal(source[key]["report-missing-tool"], shared[key]["report-missing-tool"]); - assert.deepEqual(source[key].noop, { max: 3, "report-as-issue": false }); } else { assert.equal(Object.hasOwn(source, key), false, `Do not override shared ${key} controls`); } @@ -97,13 +118,15 @@ test("drafting reuses the proven tools and model without enabling the future bui assert.ok(!agent.steps.some(step => step.uses?.startsWith("actions/checkout@"))); }); -test("only the main agent and detector can infer, and no drafting job can publish", () => { +test("only the main agent and detector can infer, and reaction writes stay in trusted activation", () => { assert.deepEqual(compiled.permissions, {}); for (const [name, job] of Object.entries(compiled.jobs)) { const permissions = job.permissions ?? compiled.permissions; assert.equal(typeof permissions, "object", `${name} must inherit no permissions or declare them explicitly`); for (const [scope, level] of Object.entries(permissions)) { - if (scope === "copilot-requests") { + if (name === "activation" && ["issues", "discussions", "pull-requests"].includes(scope)) { + assert.equal(level, "write"); + } else if (scope === "copilot-requests") { assert.ok(["agent", "detection"].includes(name)); assert.equal(level, "write"); } else { @@ -176,27 +199,23 @@ test("file-only candidates are explicit inputs to the pinned detector", () => { assert.equal(detectionCommand.env.GH_AW_DETECTION_CONTINUE_ON_ERROR, "false"); }); -test("a file-only model response triggers the compiled detection guard without native model outputs or a patch", () => { +test("draft preparation must not pre-complete the model with a native noop", () => { + assert.equal(source["pre-agent-steps"], undefined); + assert.ok(!agent.steps.some(step => step.id === "require_candidate_detection")); + const collector = agent.steps.find(step => step.id === "collect_output"); + assert.ok(agent.steps.indexOf(agentCommand) < agent.steps.indexOf(collector)); + const handler = compiled.jobs.safe_outputs.steps.find(step => step.id === "process_safe_outputs"); + const config = JSON.parse(handler.env.GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG); + assert.deepEqual(config.noop, { max: 2, "report-as-issue": "false" }); + assert.ok(Object.hasOwn(config, "report_incomplete")); + const text = fs.readFileSync(new URL("discussion-draft.md", directory), "utf8"); + assert.ok(text.includes("After writing `discussion-draft.json`, call `safeoutputs-noop`")); +}); + +test("the compiled detection guard accepts collected outputs but never treats a missing signal as success", () => { const working = fs.mkdtempSync(path.join(os.tmpdir(), "typechat-detection-guard-")); try { - const safeOutputs = path.join(working, "gh-aw", "safeoutputs", "outputs.jsonl"); const githubOutput = path.join(working, "github-output"); - const signal = agent.steps.find(step => step.id === "require_candidate_detection"); - if (signal) { - const result = spawnSync(process.execPath, ["--eval", signal.run], { - cwd: working, encoding: "utf8", env: { ...process.env, GH_AW_SAFE_OUTPUTS: safeOutputs }, - }); - assert.equal(result.status, 0, result.stderr); - } - fs.writeFileSync(path.join(working, "discussion-draft.json"), JSON.stringify({ - summary: "File-only model output.", scope: "in_scope", scopeReason: "Clarify the existing API.", - readiness: "needs_clarification", readinessReason: "A human decision is needed.", - questions: ["Which usage data is needed?"], existingRequirements: [], suggestedCriteria: [], - limitations: ["No implementation was tested."], pullRequests: [], - })); - const records = fs.existsSync(safeOutputs) ? - fs.readFileSync(safeOutputs, "utf8").trim().split("\n").map(line => JSON.parse(line)) : []; - const outputTypes = [...new Set(records.map(record => record.type))].join(","); const guard = compiled.jobs.detection.steps.find(step => step.id === "detection_guard"); assert.equal(guard.env.OUTPUT_TYPES, "${{ needs.agent.outputs.output_types }}"); assert.equal(agent.outputs.output_types, "${{ steps.collect_output.outputs.output_types }}"); @@ -206,24 +225,18 @@ test("a file-only model response triggers the compiled detection guard without n assert.equal(git.status, 0, git.error?.message ?? git.stderr); bash = path.resolve(git.stdout.trim(), "..", "..", "..", "bin", "bash.exe"); } - const result = spawnSync(bash, ["--noprofile", "--norc", "-c", guard.run], { - cwd: working, encoding: "utf8", - env: { - ...process.env, OUTPUT_TYPES: outputTypes, HAS_PATCH: "false", - GITHUB_OUTPUT: githubOutput.replaceAll("\\", "/"), - }, - }); - assert.equal(result.status, 0, result.error?.message ?? result.stderr); - assert.match(fs.readFileSync(githubOutput, "utf8"), /^run_detection=true$/m); - assert.deepEqual(records.map(record => record.type), ["noop"]); - const signalIndex = agent.steps.indexOf(signal); - assert.ok(signalIndex >= 0 && signalIndex < agent.steps.indexOf(agentCommand)); - const collector = agent.steps.find(step => step.id === "collect_output"); - assert.equal(signal.env.GH_AW_SAFE_OUTPUTS, collector.env.GH_AW_SAFE_OUTPUTS); - assert.ok(agent.steps.indexOf(agentCommand) < agent.steps.indexOf(collector)); - const handler = compiled.jobs.safe_outputs.steps.find(step => step.id === "process_safe_outputs"); - const config = JSON.parse(handler.env.GH_AW_SAFE_OUTPUTS_HANDLER_CONFIG); - assert.deepEqual(config.noop, { max: 3, "report-as-issue": "false" }); + for (const outputTypes of ["noop", "report_incomplete", ""]) { + fs.writeFileSync(githubOutput, ""); + const result = spawnSync(bash, ["--noprofile", "--norc", "-c", guard.run], { + cwd: working, encoding: "utf8", + env: { + ...process.env, OUTPUT_TYPES: outputTypes, HAS_PATCH: "false", + GITHUB_OUTPUT: githubOutput.replaceAll("\\", "/"), + }, + }); + assert.equal(result.status, 0, result.error?.message ?? result.stderr); + assert.equal(fs.readFileSync(githubOutput, "utf8").trim(), `run_detection=${outputTypes !== ""}`); + } } finally { fs.rmSync(working, { recursive: true });