Repository navigation
feat(version-manager): add side-effect-free version resolution #1290
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
Changes from all commits
ea6a248
e62aa94
1a978e5
d7f0e8f
d7ee4e8
cbe2421
8353fa0
305bb54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,11 @@ export class VersionManagerController { | |||||
| .description('set version to use') | ||||||
| .action((tags) => this.set(tags)); | ||||||
|
|
||||||
| private readonly resolveCommand = this.mainCommand | ||||||
| .command('resolve <versionTags...>') | ||||||
| .description('resolve version tags to a version') | ||||||
| .action((tags) => this.resolve(tags)); | ||||||
|
|
||||||
| constructor( | ||||||
| @Inject(LOGGER) private readonly logger: LOGGER, | ||||||
| @Inject(COMMANDER_PROGRAM) private readonly program: Command, | ||||||
|
|
@@ -95,6 +100,22 @@ export class VersionManagerController { | |||||
| ); | ||||||
| }; | ||||||
|
|
||||||
| private resolve = async (versionTags: string[]) => { | ||||||
| const versions = await this.service.search(versionTags).toPromise(); | ||||||
|
|
||||||
| if (versions.length > 0) { | ||||||
| this.logger.log(versions[0].version); | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| this.logger.error( | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This edit lands in Prompt for AI agents
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to be stale or misattributed. In the current code, set still uses logger.log, while only resolve uses logger.error, so no further change is needed. |
||||||
| chalk.red( | ||||||
| `Unable to find version matching criteria "${versionTags.join(' ')}"`, | ||||||
| ), | ||||||
| ); | ||||||
| process.exitCode = 1; | ||||||
| }; | ||||||
|
|
||||||
| private table = (versions: Version[]) => { | ||||||
| // Keep row order identical to the order returned in versions. | ||||||
| const rows = versions.map((version) => { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,12 @@ describe('ConfigService', () => { | |
| it('can return a default value', () => { | ||
| expect(fixture.get('unknown', 'foo')).toEqual('foo'); | ||
| }); | ||
|
|
||
| it('does not create or modify the config file', () => { | ||
| fixture.get('some-path'); | ||
| expect(fs.ensureFileSync).toHaveBeenCalledTimes(0); | ||
| expect(fs.writeJSONSync).toHaveBeenCalledTimes(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('the config has values', () => { | ||
|
|
@@ -69,12 +75,10 @@ describe('ConfigService', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('ensures the config file', () => { | ||
| it('does not create or modify the config file', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This regression test does not cover the absent-config case: its setup always returns an existing configuration object. Add a case with Prompt for AI agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d7f0e8f. The tests now cover an absent configuration (readJSONSync returns undefined) and verify that no file creation or write occurs. |
||
| fixture.get('some-path'); | ||
| expect(fs.ensureFileSync).toHaveBeenNthCalledWith( | ||
| 1, | ||
| fixture.configFile | ||
| ); | ||
| expect(fs.ensureFileSync).toHaveBeenCalledTimes(0); | ||
| expect(fs.writeJSONSync).toHaveBeenCalledTimes(0); | ||
| }); | ||
|
|
||
| it.each([ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.