-
Notifications
You must be signed in to change notification settings - Fork 449
fix: disambiguate shared rules files via footer agent name #617
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
RyanNg1403
wants to merge
2
commits into
main
Choose a base branch
from
fix/ENG-2221
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.
+207
−7
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
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,96 @@ | ||
| import {expect} from 'chai' | ||
| import {mkdir, rm, writeFile} from 'node:fs/promises' | ||
| import {tmpdir} from 'node:os' | ||
| import path from 'node:path' | ||
|
|
||
| import type {Agent} from '../../../../../src/server/core/domain/entities/agent.js' | ||
| import type {ConnectorType} from '../../../../../src/server/core/domain/entities/connector-type.js' | ||
| import type {IRuleTemplateService} from '../../../../../src/server/core/interfaces/services/i-rule-template-service.js' | ||
|
|
||
| import {RulesConnector} from '../../../../../src/server/infra/connectors/rules/rules-connector.js' | ||
| import {BRV_RULE_MARKERS, BRV_RULE_TAG} from '../../../../../src/server/infra/connectors/shared/constants.js' | ||
| import {FsFileService} from '../../../../../src/server/infra/file/fs-file-service.js' | ||
|
|
||
| class StubTemplateService implements IRuleTemplateService { | ||
| async generateRuleContent(_agent: Agent, _type?: ConnectorType): Promise<string> { | ||
| throw new Error('StubTemplateService.generateRuleContent should not be called from status flow') | ||
| } | ||
|
RyanNg1403 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const buildAgentsMd = (footerAgent?: Agent): string => { | ||
| const footer = footerAgent === undefined ? '' : `\n---\n${BRV_RULE_TAG} ${footerAgent}` | ||
| return `${BRV_RULE_MARKERS.START}\nrule body${footer}\n${BRV_RULE_MARKERS.END}\n` | ||
| } | ||
|
RyanNg1403 marked this conversation as resolved.
|
||
|
|
||
| describe('RulesConnector.status (shared AGENTS.md disambiguation)', () => { | ||
| let testDir: string | ||
| let connector: RulesConnector | ||
|
|
||
| beforeEach(async () => { | ||
| testDir = path.join(tmpdir(), `rules-connector-test-${Date.now()}-${Math.random().toString(36).slice(2)}`) | ||
| await mkdir(testDir, {recursive: true}) | ||
| connector = new RulesConnector({ | ||
| fileService: new FsFileService(), | ||
| projectRoot: testDir, | ||
| templateService: new StubTemplateService(), | ||
| }) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await rm(testDir, {force: true, recursive: true}) | ||
| }) | ||
|
|
||
| it('reports installed:true only for the agent named in the footer (Codex)', async () => { | ||
| await writeFile(path.join(testDir, 'AGENTS.md'), buildAgentsMd('Codex')) | ||
|
|
||
| const codex = await connector.status('Codex') | ||
| const amp = await connector.status('Amp') | ||
| const opencode = await connector.status('OpenCode') | ||
|
|
||
| expect(codex.installed, 'Codex should be reported installed').to.equal(true) | ||
| expect(amp.installed, 'Amp should NOT be reported installed for a Codex-authored AGENTS.md').to.equal(false) | ||
| expect(opencode.installed, 'OpenCode should NOT be reported installed for a Codex-authored AGENTS.md').to.equal(false) | ||
| }) | ||
|
|
||
| it('reports installed:true for the agent named in the footer (Amp)', async () => { | ||
| await writeFile(path.join(testDir, 'AGENTS.md'), buildAgentsMd('Amp')) | ||
|
|
||
| const codex = await connector.status('Codex') | ||
| const amp = await connector.status('Amp') | ||
|
|
||
| expect(amp.installed).to.equal(true) | ||
| expect(codex.installed).to.equal(false) | ||
| }) | ||
|
|
||
| it('falls back to the legacy behavior when the BRV section has no footer (markers => installed for all sharing agents)', async () => { | ||
| await writeFile(path.join(testDir, 'AGENTS.md'), buildAgentsMd()) | ||
|
|
||
| const codex = await connector.status('Codex') | ||
| const amp = await connector.status('Amp') | ||
| const opencode = await connector.status('OpenCode') | ||
|
|
||
| expect(codex.installed, 'legacy footer-less file should remain installed for Codex').to.equal(true) | ||
| expect(amp.installed, 'legacy footer-less file should remain installed for Amp').to.equal(true) | ||
| expect(opencode.installed, 'legacy footer-less file should remain installed for OpenCode').to.equal(true) | ||
| }) | ||
|
|
||
| it('does not mistakenly mark Amp installed when only Claude Code (CLAUDE.md) was installed', async () => { | ||
| await writeFile(path.join(testDir, 'CLAUDE.md'), buildAgentsMd('Claude Code')) | ||
|
|
||
| const claudeCode = await connector.status('Claude Code') | ||
| const amp = await connector.status('Amp') | ||
|
|
||
| expect(claudeCode.installed).to.equal(true) | ||
| expect(amp.installed).to.equal(false) | ||
| expect(amp.configExists, 'Amp\'s AGENTS.md does not exist in this project').to.equal(false) | ||
| }) | ||
|
|
||
| it('still reports installed:false when MCP tool markers are present (existing rule)', async () => { | ||
| const content = `${BRV_RULE_MARKERS.START}\nuse the brv-query tool\n---\n${BRV_RULE_TAG} Codex\n${BRV_RULE_MARKERS.END}\n` | ||
| await writeFile(path.join(testDir, 'AGENTS.md'), content) | ||
|
|
||
| const codex = await connector.status('Codex') | ||
|
|
||
| expect(codex.installed, 'a section that contains brv-query should not count as a rules install').to.equal(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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import {expect} from 'chai' | ||
|
|
||
| import { | ||
| BRV_RULE_MARKERS, | ||
| BRV_RULE_TAG, | ||
| extractInstalledAgentFromBrvSection, | ||
| hasMcpToolsInBrvSection, | ||
| } from '../../../../../src/server/infra/connectors/shared/constants.js' | ||
|
|
||
| const wrapWithBrvSection = (footer: string): string => | ||
| `Some user content\n${BRV_RULE_MARKERS.START}\nrule body\n---\n${footer}\n${BRV_RULE_MARKERS.END}\nMore content` | ||
|
|
||
| describe('shared/constants', () => { | ||
| describe('extractInstalledAgentFromBrvSection', () => { | ||
| it('returns the agent name when the footer is present inside the BRV section', () => { | ||
| const content = wrapWithBrvSection(`${BRV_RULE_TAG} Codex`) | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal('Codex') | ||
| }) | ||
|
|
||
| it('returns multi-word agent names verbatim (e.g. "Augment Code")', () => { | ||
| const content = wrapWithBrvSection(`${BRV_RULE_TAG} Augment Code`) | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal('Augment Code') | ||
| }) | ||
|
|
||
| it('returns undefined when the BRV section has no footer (legacy file)', () => { | ||
| const content = `${BRV_RULE_MARKERS.START}\nrule body without footer\n${BRV_RULE_MARKERS.END}` | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal(undefined) | ||
| }) | ||
|
|
||
| it('returns undefined when start marker is missing', () => { | ||
| const content = `rule body\n---\n${BRV_RULE_TAG} Codex\n${BRV_RULE_MARKERS.END}` | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal(undefined) | ||
| }) | ||
|
|
||
| it('returns undefined when end marker is missing', () => { | ||
| const content = `${BRV_RULE_MARKERS.START}\nrule body\n---\n${BRV_RULE_TAG} Codex` | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal(undefined) | ||
| }) | ||
|
|
||
| it('ignores a footer that appears outside the BRV section', () => { | ||
| const content = `Earlier in the file: ${BRV_RULE_TAG} Codex\n${BRV_RULE_MARKERS.START}\nrule body\n${BRV_RULE_MARKERS.END}` | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal(undefined) | ||
| }) | ||
|
|
||
| it('returns undefined when end marker precedes start marker', () => { | ||
| const content = `${BRV_RULE_MARKERS.END}\nstuff\n${BRV_RULE_MARKERS.START}\n${BRV_RULE_TAG} Codex` | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal(undefined) | ||
| }) | ||
|
|
||
| it('returns undefined when the footer line is blank after the tag', () => { | ||
| const content = wrapWithBrvSection(`${BRV_RULE_TAG} `) | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal(undefined) | ||
|
RyanNg1403 marked this conversation as resolved.
|
||
| }) | ||
|
|
||
| it('does not match a malformed tag with no space delimiter (e.g. "...CLI forXxx")', () => { | ||
| const content = wrapWithBrvSection(`${BRV_RULE_TAG}Xxx`) | ||
| expect(extractInstalledAgentFromBrvSection(content)).to.equal(undefined) | ||
| }) | ||
| }) | ||
|
|
||
| describe('hasMcpToolsInBrvSection (regression guard)', () => { | ||
| it('detects brv-query inside the BRV section', () => { | ||
| const content = `${BRV_RULE_MARKERS.START}\nuse the brv-query tool\n${BRV_RULE_MARKERS.END}` | ||
| expect(hasMcpToolsInBrvSection(content)).to.equal(true) | ||
| }) | ||
|
|
||
| it('does not flag brv-query that appears only outside the BRV section', () => { | ||
| const content = `brv-query mentioned outside\n${BRV_RULE_MARKERS.START}\nno tools here\n${BRV_RULE_MARKERS.END}` | ||
| expect(hasMcpToolsInBrvSection(content)).to.equal(false) | ||
| }) | ||
| }) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.