-
Notifications
You must be signed in to change notification settings - Fork 424
[jsweep] Clean validate_lockdown_requirements.cjs #39498
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
4
commits into
main
Choose a base branch
from
signed/jsweep/validate-lockdown-requirements-628d174c9a4092dd
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.
+156
−45
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
52122d0
chore: narrow POC scope to PR outcomes and safe output outcomes only …
github-actions[bot] 0c964b4
jsweep: clean validate_lockdown_requirements.cjs
github-actions[bot] 4052555
refactor lockdown validation messages into templates
Copilot 22aa72f
style: move lockdown template import to file top
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
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
59 changes: 59 additions & 0 deletions
59
actions/setup/js/validate_lockdown_requirements_templates.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,59 @@ | ||
| // @ts-check | ||
|
|
||
| const { renderTemplate } = require("./messages_core.cjs"); | ||
|
|
||
| const LOCKDOWN_TOKEN_ERROR_TEMPLATE = `Lockdown mode is enabled (lockdown: true) but no custom GitHub token is configured. | ||
|
|
||
| Please configure one of the following as a repository secret: | ||
| - GH_AW_GITHUB_TOKEN (recommended) | ||
| - GH_AW_GITHUB_MCP_SERVER_TOKEN (alternative) | ||
| - Custom github-token in your workflow frontmatter | ||
|
|
||
| See: {auth_docs_url} | ||
|
|
||
| To set a token: | ||
| gh aw secrets set GH_AW_GITHUB_TOKEN --value "YOUR_FINE_GRAINED_PAT"`; | ||
|
|
||
| const PUBLIC_STRICT_MODE_ERROR_TEMPLATE = `This workflow is running on a public repository but was not compiled with strict mode. | ||
|
|
||
| Public repository workflows must be compiled with strict mode enabled to meet | ||
| the security requirements for public exposure. | ||
|
|
||
| To fix this, recompile the workflow with strict mode: | ||
| {strict_compile_command} | ||
|
|
||
| See: {security_docs_url}`; | ||
|
|
||
| const PULL_REQUEST_TARGET_ERROR_TEMPLATE = `This workflow is triggered by the pull_request_target event on a public repository. | ||
|
|
||
| The pull_request_target event is not allowed on public repositories because it runs | ||
| workflows with access to repository secrets even when triggered from a fork, which | ||
| creates a significant security risk (known as a "pwn request"). | ||
|
|
||
| To fix this, use the pull_request event instead, or migrate to a private repository. | ||
|
|
||
| See: {security_docs_url}`; | ||
|
|
||
| const TEMPLATE_CONTEXT = { | ||
| auth_docs_url: "https://github.com/github/gh-aw/blob/main/docs/src/content/docs/reference/auth.mdx", | ||
| security_docs_url: "https://github.com/github/gh-aw/blob/main/docs/src/content/docs/reference/security.mdx", | ||
| strict_compile_command: "gh aw compile --strict", | ||
| }; | ||
|
|
||
| function renderLockdownTokenErrorMessage() { | ||
| return renderTemplate(LOCKDOWN_TOKEN_ERROR_TEMPLATE, TEMPLATE_CONTEXT); | ||
| } | ||
|
|
||
| function renderPublicStrictModeErrorMessage() { | ||
| return renderTemplate(PUBLIC_STRICT_MODE_ERROR_TEMPLATE, TEMPLATE_CONTEXT); | ||
| } | ||
|
|
||
| function renderPullRequestTargetErrorMessage() { | ||
| return renderTemplate(PULL_REQUEST_TARGET_ERROR_TEMPLATE, TEMPLATE_CONTEXT); | ||
| } | ||
|
|
||
| module.exports = { | ||
| renderLockdownTokenErrorMessage, | ||
| renderPublicStrictModeErrorMessage, | ||
| renderPullRequestTargetErrorMessage, | ||
| }; |
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]
.toThrow()without an argument does not verify which error is thrown — inconsistent with the existing suite (line 301 uses.toThrow("not compiled with strict mode")).💡 Match the specificity of existing tests
The pre-existing test block uses:
Applying the same pattern here makes all three new formatting tests consistent and catches regressions in the thrown message, not just the fact that something was thrown: