-
Notifications
You must be signed in to change notification settings - Fork 227
feat(reporter): add suppressible Pro conversion CTA to human-facing reports #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
affaan-m
wants to merge
1
commit into
main
Choose a base branch
from
feat/pro-cta-footer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * Pro conversion CTA shown at the foot of human-facing reports (terminal, | ||
| * markdown, and — via renderMarkdownReport — the GitHub Action job summary). | ||
| * | ||
| * Deliberately NOT added to JSON or SARIF output: those are machine-consumed and | ||
| * must stay clean. The CTA leads with the privacy + low-noise wedge (the free, | ||
| * local-first, zero-account scanner stays the moat) and points at the real | ||
| * ECC Tools GitHub App. Suppressible via env so CI logs and scripted use can | ||
| * silence it. | ||
| */ | ||
|
|
||
| const OPT_OUT_ENV_VARS = ["ECC_NO_CTA", "AGENTSHIELD_NO_CTA"] as const; | ||
|
|
||
| const PRO_URL = "https://github.com/apps/ecc-tools"; | ||
|
|
||
| export const PRO_CTA_PLAIN = | ||
| "Scans run locally; nothing leaves your machine. " + | ||
| `Track fleet posture and drift over time with ECC Tools Pro: ${PRO_URL}`; | ||
|
|
||
| export const PRO_CTA_MARKDOWN = | ||
| "_Scans run locally; nothing leaves your machine. " + | ||
| `Track fleet posture and drift over time with [ECC Tools Pro](${PRO_URL})._`; | ||
|
|
||
| /** | ||
| * True when the operator has opted out of the CTA via an env var. Any non-empty | ||
| * value other than "0" / "false" counts as opt-out. | ||
| */ | ||
| export function ctaSuppressed(env: NodeJS.ProcessEnv = process.env): boolean { | ||
| return OPT_OUT_ENV_VARS.some((key) => { | ||
| const value = env[key]; | ||
| return ( | ||
| value !== undefined && | ||
| value !== "" && | ||
| value !== "0" && | ||
| value.toLowerCase() !== "false" | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| /** Plain-text CTA footer lines, or [] when suppressed. */ | ||
| export function proCtaPlainLines(env: NodeJS.ProcessEnv = process.env): ReadonlyArray<string> { | ||
| return ctaSuppressed(env) ? [] : [PRO_CTA_PLAIN]; | ||
| } | ||
|
|
||
| /** Markdown CTA footer lines, or [] when suppressed. */ | ||
| export function proCtaMarkdownLines(env: NodeJS.ProcessEnv = process.env): ReadonlyArray<string> { | ||
| return ctaSuppressed(env) ? [] : ["---", "", PRO_CTA_MARKDOWN]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { | ||
| ctaSuppressed, | ||
| proCtaPlainLines, | ||
| proCtaMarkdownLines, | ||
| PRO_CTA_PLAIN, | ||
| PRO_CTA_MARKDOWN, | ||
| } from "../../src/reporter/cta.js"; | ||
|
|
||
| describe("pro CTA", () => { | ||
| it("leads with the privacy wedge and points at the real ECC Tools app", () => { | ||
| expect(PRO_CTA_PLAIN).toMatch(/locally/i); | ||
| expect(PRO_CTA_PLAIN).toContain("https://github.com/apps/ecc-tools"); | ||
| expect(PRO_CTA_MARKDOWN).toContain("[ECC Tools Pro](https://github.com/apps/ecc-tools)"); | ||
| }); | ||
|
|
||
| it("is shown by default", () => { | ||
| expect(ctaSuppressed({})).toBe(false); | ||
| expect(proCtaPlainLines({})).toEqual([PRO_CTA_PLAIN]); | ||
| expect(proCtaMarkdownLines({})).toContain(PRO_CTA_MARKDOWN); | ||
| }); | ||
|
|
||
| it("is suppressed by ECC_NO_CTA / AGENTSHIELD_NO_CTA", () => { | ||
| expect(ctaSuppressed({ ECC_NO_CTA: "1" })).toBe(true); | ||
| expect(ctaSuppressed({ AGENTSHIELD_NO_CTA: "true" })).toBe(true); | ||
| expect(proCtaPlainLines({ ECC_NO_CTA: "1" })).toEqual([]); | ||
| expect(proCtaMarkdownLines({ AGENTSHIELD_NO_CTA: "yes" })).toEqual([]); | ||
| }); | ||
|
|
||
| it("treats empty / 0 / false as not-suppressed", () => { | ||
| expect(ctaSuppressed({ ECC_NO_CTA: "" })).toBe(false); | ||
| expect(ctaSuppressed({ ECC_NO_CTA: "0" })).toBe(false); | ||
| expect(ctaSuppressed({ AGENTSHIELD_NO_CTA: "false" })).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renderMarkdownReportcallsproCtaMarkdownLines()with no argument, so it reads fromprocess.envdirectly. The assertionexpect(output).toContain("ECC Tools Pro")will therefore fail wheneverECC_NO_CTA=1orAGENTSHIELD_NO_CTA=1is present in the test environment — which is exactly what the PR's own documented opt-out guidance tells CI users to set. A developer or CI pipeline that follows the suppression guidance and then runsnpm testwill see this test break.The unit tests in
cta.test.tscorrectly inject a controlled env object, but this integration test bypasses that isolation. The fix is to either usevi.stubEnv/vi.unstubAllEnvsaround this test, or delete the two env vars fromprocess.envfor the duration of the test.