-
Notifications
You must be signed in to change notification settings - Fork 424
[jsweep] Clean validate_lockdown_requirements_templates.cjs #40730
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
github-actions
wants to merge
3
commits into
main
Choose a base branch
from
signed/jsweep/validate-lockdown-requirements-templates-08adb426f258e135
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.
+167
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
b827104
jsweep: add JSDoc and tests for validate_lockdown_requirements_templa…
github-actions[bot] 6f6b008
fix: address review feedback on validate_lockdown_requirements_templa…
Copilot d37b6a9
fix: use arrayContaining + toHaveLength for module-surface export check
Copilot 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
164 changes: 164 additions & 0 deletions
164
actions/setup/js/validate_lockdown_requirements_templates.test.cjs
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,164 @@ | ||
| // @ts-check | ||
| const { renderLockdownTokenErrorMessage, renderPublicStrictModeErrorMessage, renderPullRequestTargetErrorMessage } = require("./validate_lockdown_requirements_templates.cjs"); | ||
|
|
||
| describe("validate_lockdown_requirements_templates", () => { | ||
| describe("renderLockdownTokenErrorMessage", () => { | ||
| it("returns a non-empty string", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).toBeTypeOf("string"); | ||
| expect(message.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it("includes the auth documentation URL", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).toContain("https://github.com/github/gh-aw/blob/main/docs/src/content/docs/reference/auth.mdx"); | ||
| }); | ||
|
|
||
| it("includes GH_AW_GITHUB_TOKEN recommendation", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).toContain("GH_AW_GITHUB_TOKEN (recommended)"); | ||
| }); | ||
|
|
||
| it("includes GH_AW_GITHUB_MCP_SERVER_TOKEN as alternative", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).toContain("GH_AW_GITHUB_MCP_SERVER_TOKEN (alternative)"); | ||
| }); | ||
|
|
||
| it("includes the gh aw secrets set command", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).toContain("gh aw secrets set GH_AW_GITHUB_TOKEN"); | ||
| }); | ||
|
|
||
| it("mentions lockdown mode is enabled", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).toContain("Lockdown mode is enabled"); | ||
| }); | ||
|
|
||
| it("does not contain unreplaced {auth_docs_url} placeholder", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).not.toContain("{auth_docs_url}"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("renderPublicStrictModeErrorMessage", () => { | ||
| it("returns a non-empty string", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).toBeTypeOf("string"); | ||
| expect(message.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it("includes the security documentation URL", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).toContain("https://github.com/github/gh-aw/blob/main/docs/src/content/docs/reference/security.mdx"); | ||
| }); | ||
|
|
||
| it("includes the strict compile command", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).toContain("gh aw compile --strict"); | ||
| }); | ||
|
|
||
| it("mentions public repository context", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).toContain("public repository"); | ||
| }); | ||
|
|
||
| it("mentions strict mode", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).toContain("strict mode"); | ||
| }); | ||
|
|
||
| it("does not contain unreplaced {strict_compile_command} placeholder", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).not.toContain("{strict_compile_command}"); | ||
| }); | ||
|
|
||
| it("does not contain unreplaced {security_docs_url} placeholder", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).not.toContain("{security_docs_url}"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("renderPullRequestTargetErrorMessage", () => { | ||
| it("returns a non-empty string", () => { | ||
| const message = renderPullRequestTargetErrorMessage(); | ||
| expect(message).toBeTypeOf("string"); | ||
| expect(message.length).toBeGreaterThan(0); | ||
| }); | ||
|
|
||
| it("includes the security documentation URL", () => { | ||
| const message = renderPullRequestTargetErrorMessage(); | ||
| expect(message).toContain("https://github.com/github/gh-aw/blob/main/docs/src/content/docs/reference/security.mdx"); | ||
| }); | ||
|
|
||
| it("mentions the pull_request_target event", () => { | ||
| const message = renderPullRequestTargetErrorMessage(); | ||
| expect(message).toContain("pull_request_target"); | ||
| }); | ||
|
|
||
| it("mentions pwn request security risk", () => { | ||
| const message = renderPullRequestTargetErrorMessage(); | ||
| expect(message).toContain("pwn request"); | ||
| }); | ||
|
|
||
| it("mentions public repositories", () => { | ||
| const message = renderPullRequestTargetErrorMessage(); | ||
| expect(message).toContain("public repositories"); | ||
| }); | ||
|
|
||
| it("suggests using the pull_request event instead", () => { | ||
| const message = renderPullRequestTargetErrorMessage(); | ||
| expect(message).toContain("pull_request event instead"); | ||
| }); | ||
|
|
||
| it("does not contain unreplaced {security_docs_url} placeholder", () => { | ||
| const message = renderPullRequestTargetErrorMessage(); | ||
| expect(message).not.toContain("{security_docs_url}"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("cross-function checks", () => { | ||
| it("each render function returns a distinct message", () => { | ||
| const lockdown = renderLockdownTokenErrorMessage(); | ||
| const strictMode = renderPublicStrictModeErrorMessage(); | ||
| const prTarget = renderPullRequestTargetErrorMessage(); | ||
|
|
||
| expect(lockdown).not.toBe(strictMode); | ||
| expect(lockdown).not.toBe(prTarget); | ||
| expect(strictMode).not.toBe(prTarget); | ||
| }); | ||
|
|
||
| it("lockdown message does not contain strict mode content", () => { | ||
| const message = renderLockdownTokenErrorMessage(); | ||
| expect(message).not.toContain("gh aw compile --strict"); | ||
| }); | ||
|
|
||
| it("strict mode message does not contain lockdown token content", () => { | ||
| const message = renderPublicStrictModeErrorMessage(); | ||
| expect(message).not.toContain("GH_AW_GITHUB_TOKEN"); | ||
| }); | ||
|
|
||
| it("module exposes exactly the expected exports", () => { | ||
| const mod = require("./validate_lockdown_requirements_templates.cjs"); | ||
| const keys = Object.keys(mod); | ||
| expect(keys).toHaveLength(3); | ||
| expect(keys).toEqual( | ||
| expect.arrayContaining([ | ||
| "renderLockdownTokenErrorMessage", | ||
| "renderPublicStrictModeErrorMessage", | ||
| "renderPullRequestTargetErrorMessage", | ||
| ]), | ||
| ); | ||
| }); | ||
|
|
||
| it("no message contains unreplaced placeholders", () => { | ||
| const messages = [ | ||
| renderLockdownTokenErrorMessage(), | ||
| renderPublicStrictModeErrorMessage(), | ||
| renderPullRequestTargetErrorMessage(), | ||
| ]; | ||
| for (const message of messages) { | ||
| expect(message).not.toMatch(/\{[A-Za-z][A-Za-z0-9_]*\}/); | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
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.
[/tdd] This and similar tests ("includes GH_AW_GITHUB_TOKEN recommendation", "mentions public repository context", etc.) assert exact static phrases from the templates rather than substituted tokens. Any intentional reword (e.g.
"Lockdown mode is enabled"→"Lockdown mode is active") will break these tests without indicating a real regression.💡 Recommendation
The placeholder-substitution tests —
expect(message).not.toContain("{auth_docs_url}")and the final regex sweep — are the real behavioral contract here. The static-phrase tests above those add documentation value but also brittleness.Consider one of:
expect(message).toMatchInlineSnapshot(...)) so rewrites show a clear diff./\{[a-z_]+\}/) as the primary contract.