Skip to content

Fake agent raising pr comments automatically - #203

Open
niharika3715 wants to merge 13 commits into
secfoo-com:mainfrom
niharika3715:pr-comment-demo
Open

niharika3715 wants to merge 13 commits into
secfoo-com:mainfrom
niharika3715:pr-comment-demo

Conversation

@niharika3715

@niharika3715 niharika3715 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #108

What does this change, and why?

Completes the GitHub Action integration by adding an automated self-test workflow, sticky PR comments, cached findings storage, YAML linting, and updated documentation.

The action can now be tested automatically on pull requests, retain findings between runs, and provide security scan results directly in PR comments.

Code Flow

  1. Pass identifier → User provides agent ID (e.g., fake, --agent fake, or IN_AGENT=fake env var)
  2. Create adapter → System looks up the adapter by ID (→ FakeAdapter for "fake")
  3. Run adapter → FakeAdapter.run() reads the static fixture tests/fixtures/ci/fake-report.md
  4. Return raw report → Returns AgentResult with:
  • raw_report = the markdown content
  • cost_usd = 0.0
  • status = "success"
  • exit_code = 0
  1. Serialization → JSON result is produced (per-skill data + totals)
  2. GitHub Action summary → The action's post-step code formats the JSON into the PR comment/table summary

Temporary changes for testing

  • Switched installation from PyPI to our PR branch to test the latest code.
  • Added a fake agent and a fixture report under tests/fixtures/ci/.
  • Ran the workflow and verified that the fake agent generated the expected report.
    After testing: We reverted the installation change. Once the PR is merged and the package is published, the fake agent will be available in the package.

Reason for failed Checks

  • CI/Docs will be failing because that particular directory is not yet created.
  • Self test was failing because it is not able to find the fake agent in current existing package. Once new version is released with my code changes this will get fixed.

Testing

  • pytest tests passes
  • ruff check . passes
  • Self-test workflow passes, including all four exit-code checks
  • SARIF validates against the 2.1.0 schema
  • PR comment is created and updated without duplicates
  • Cache restore and save work correctly
  • actionlint passes
  • Documentation updated with inputs and PR comment screenshot

dummy pr that is tested: niharika3715/upskill-tracker#1

@niharika3715
niharika3715 requested a review from vsn411 as a code owner November 27, 2026 04:27
Comment thread action.yml Fixed
Comment thread action.yml

# Link to code-scanning alerts
body_lines+=("")
body_lines+=("[View code-scanning alerts](${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}/security/code-scanning)")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive that is safe. and same comment is coming twice please check

Comment thread action.yml

# Link to code-scanning alerts
body_lines+=("")
body_lines+=("[View code-scanning alerts](${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}/security/code-scanning)")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false positive that is safe.

Comment thread src/secfoo/agents/fake.py Fixed
Comment thread src/secfoo/agents/fake.py Fixed
Comment thread src/secfoo/agents/fake.py Fixed
Comment thread src/secfoo/agents/fake.py Fixed
Comment thread src/secfoo/agents/fake.py Fixed
Comment thread src/secfoo/agents/fake.py Fixed

@vsn411 vsn411 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking on #108, and for testing it end to end on a scratch repo. That is exactly the proof the issue asks for. The fake-agent idea and the sticky-comment flow are the right shape. Some of the action logic needs another pass before this can merge, though, and a few items from the issue are still open. The list below goes in order of importance.

Must fix

  1. The comment content is hard-coded.

    • "Findings gate: Passed", "Cost gate: Passed" and "AI spend: $0.00" are fixed strings, so a PR whose gate failed would still get a comment saying "Passed".
    • The "fallback" row (SAST … 1 / 1 / 1 / 1 | $0.00) is added every time the result file exists.
    • The Python heredoc prints the real per-skill rows to the step log, not into body_lines, so they never reach the comment.

    Suggestion: build the whole body in one Python script from secfoo-result.json, write it to a file, and post it with gh api … -F [email protected]. Main's "Run secfoo" step already does most of this for the job summary: the per-skill table and the gate lines from doc["gates"]. The cost is doc["total_cost_usd"].

  2. Exit-code handling. exit "$code" in the scan step, together with removing the "Apply secfoo's exit code" step, means a tripped gate skips everything after the scan. You can see it in this PR's selftest log: Export SARIF … outcome=skipped. That loses the SARIF upload and the comment exactly when they matter.

    • Keep main's deferred exit 0 and the final "Apply exit code" step.
    • Give the comment step if: ${{ !cancelled() && ... }} so it runs when the gate fails.
  3. The fake agent can't work from a PyPI install.

    • FakeAdapter reads parents[3]/tests/fixtures/ci/fake-report.md, but tests/ isn't in the wheel. So the selftest would stay red even after a release.
    • AgentId.FAKE is added to the CLI enum for everyone, so --agent fake shows in secfoo run --help, but without SECFOO_FAKE_AGENT=1 it fails.

    Suggestions:

    • Add an action input such as install-from (empty = PyPI, as today). The selftest passes install-from: ., so it tests this PR's code. That also removes the "will pass after the next release" problem.
    • Have the fake adapter read the report from a path in an env var (e.g. SECFOO_FAKE_REPORT), which the selftest sets to tests/fixtures/ci/fake-report.md.
    • Accept fake only when SECFOO_FAKE_AGENT=1, and keep it out of --help and secfoo agents, as the issue says.
  4. extra-args is appended twice. The new block before the skills loop duplicates the one main already has further down. Please drop the new one.

  5. Cache.

    • The key is fixed per branch. actions/cache entries are immutable, so after the first save the store never updates. Use a unique key with a prefix restore, e.g. key: secfoo-${{ github.repository }}-${{ github.ref_name }}-${{ github.run_id }} and restore-keys: secfoo-${{ github.repository }}-${{ github.ref_name }}-.
    • The cache-key input isn't used: env: cache-key: on a uses: step doesn't change the key.
    • The ${{ runner.os }}-secfoo- restore key would pull in another branch's store.
    • Please exclude the files that can hold credentials (!~/.secfoo/memory.toml, !~/.secfoo/config.toml).
    • Please pin actions/cache to a commit SHA like the other actions in action.yml.
  6. Links.

    • The docs link to https://github.com/secfoo-com/secfoo/security/code-scanning returns 404 to anonymous users, which is why Docs (links, version) fails. Please describe the link instead of linking this repo's alerts page.
    • In the comment, ${{ env.REPO_OWNER }}/${{ env.REPO_NAME }}/security/code-scanning is a relative URL. Use $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/security/code-scanning from the environment, without ${{ }} inside run:.

Smaller things

  • github-token defaults to empty, so gh has no token. Please default it to ${{ github.token }}.
  • The comment step says it must never fail the job but uses set -e. set -uo pipefail with the existing || echo "::notice::…" is enough.
  • The if [ -d "$HOME/.secfoo" ] … : else : fi block does nothing, so please remove it. With --json, secfoo run always scans and never prompts, so --rescan can simply stay as it was. The docs line "New findings may appear as closed" isn't right either.
  • tests/fixtures/ci/fake-report.md ends with a stray EOF line, and several files have no trailing newline.

Still open from #108

  • The four exit-code jobs (0, 1, 2, 3).
  • SARIF validation against the 2.1.0 schema.
  • actionlint in CI.

Splitting the PR

This is a lot for one PR, and splitting it would get your work merged sooner:

  1. Fake agent, install-from, self-test workflow with the exit-code jobs, and actionlint.
  2. Sticky PR comment.
  3. Cache.

Each would be small enough to review and merge in a day. We'd be glad to see the first one up whenever you're ready, and happy to help if anything here is unclear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prove the GitHub Action end to end: self-test workflow, sticky PR comment, cached store

3 participants