Repository navigation
docs(mcpx): re-sync story.md's AGENTS.md quote and guard it with a test #374
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
Merged
Merged
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
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,92 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "os" | ||
| "regexp" | ||
| "strconv" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| const ( | ||
| storyPath = "../../docs/story.md" | ||
| agentsPath = "../../AGENTS.md" | ||
| ) | ||
|
|
||
| // TestStoryDocumentIsCurrent fails when docs/story.md's claims about | ||
| // AGENTS.md drift from the file itself: the line counts it states, or the | ||
| // block it presents as a quote of AGENTS.md. The quote is abridged, but | ||
| // every line it does quote must be a line of AGENTS.md verbatim, and the | ||
| // counts it states ("the full file is N lines", "N lines today") must be | ||
| // the file's real length. #365: both had silently rotted once already | ||
| // (109 stated, 120 actual), the same failure TestParityDocumentIsCurrent | ||
| // guards docs/parity.md against. | ||
| func TestStoryDocumentIsCurrent(t *testing.T) { | ||
| agents, err := os.ReadFile(agentsPath) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| story, err := os.ReadFile(storyPath) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| agentLines := strings.Split(strings.TrimSuffix(string(agents), "\n"), "\n") | ||
| inAgents := make(map[string]bool, len(agentLines)) | ||
| for _, l := range agentLines { | ||
| inAgents[l] = true | ||
| } | ||
|
|
||
| // The quoted block: the first ```markdown fence in story.md. | ||
| storyLines := strings.Split(string(story), "\n") | ||
| start := -1 | ||
| for i, l := range storyLines { | ||
| if l == "```markdown" { | ||
| start = i + 1 | ||
| break | ||
| } | ||
| } | ||
| if start < 0 { | ||
| t.Fatal("docs/story.md has no ```markdown quote of AGENTS.md") | ||
| } | ||
| quoted := 0 | ||
| closed := false | ||
| for _, l := range storyLines[start:] { | ||
| if l == "```" { | ||
| closed = true | ||
| break | ||
| } | ||
| if strings.TrimSpace(l) == "" { | ||
| continue | ||
| } | ||
| quoted++ | ||
| if !inAgents[l] { | ||
| t.Errorf("docs/story.md quotes AGENTS.md as %q, which is not a line of AGENTS.md; re-sync the quote with the file", l) | ||
| } | ||
| } | ||
| if !closed { | ||
| t.Error("docs/story.md's AGENTS.md quote is never closed") | ||
| } | ||
| if quoted == 0 { | ||
| t.Error("docs/story.md's AGENTS.md quote is empty") | ||
| } | ||
|
|
||
| // The stated line counts. | ||
| for _, claim := range []struct { | ||
| name string | ||
| re *regexp.Regexp | ||
| }{ | ||
| {"the full file is", regexp.MustCompile(`the full file is (\d+) lines`)}, | ||
| {"lines today", regexp.MustCompile(`(\d+) lines today`)}, | ||
| } { | ||
| for _, m := range claim.re.FindAllStringSubmatch(string(story), -1) { | ||
| n, err := strconv.Atoi(m[1]) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if n != len(agentLines) { | ||
| t.Errorf("docs/story.md says AGENTS.md is %d lines (%q claim); it is %d lines", n, claim.name, len(agentLines)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
If
AGENTS.mdlater reorders existing lines whilestory.mdretains their old order, this test still passes because it reduces the source to an unordered set and checks only membership; the same is true if the quote duplicates any valid line. That leaves the new drift guard green even though the fenced block no longer represents an abridged verbatim quote. Validate the quoted lines as an ordered subsequence ofAGENTS.mdinstead.Useful? React with 👍 / 👎.