|
7 | 7 | generateHooksToken, |
8 | 8 | configureGitHub, |
9 | 9 | runOnboardOrDoctor, |
| 10 | + updateToolsMd1PasswordSection, |
10 | 11 | buildGatewayArgs, |
11 | 12 | bootstrap, |
12 | 13 | } from './bootstrap'; |
@@ -567,6 +568,79 @@ describe('runOnboardOrDoctor', () => { |
567 | 568 | }); |
568 | 569 | }); |
569 | 570 |
|
| 571 | +// ---- updateToolsMd1PasswordSection ---- |
| 572 | + |
| 573 | +describe('updateToolsMd1PasswordSection', () => { |
| 574 | + it('adds 1Password section when OP_SERVICE_ACCOUNT_TOKEN is set', () => { |
| 575 | + const harness = fakeDeps(); |
| 576 | + (harness.deps.readFileSync as ReturnType<typeof vi.fn>).mockReturnValue('# TOOLS\n'); |
| 577 | + |
| 578 | + const env: Record<string, string | undefined> = { |
| 579 | + OP_SERVICE_ACCOUNT_TOKEN: 'ops_test123', |
| 580 | + }; |
| 581 | + |
| 582 | + updateToolsMd1PasswordSection(env, harness.deps); |
| 583 | + |
| 584 | + expect(harness.writeCalls).toHaveLength(1); |
| 585 | + expect(harness.writeCalls[0]!.data).toContain('<!-- BEGIN:1password -->'); |
| 586 | + expect(harness.writeCalls[0]!.data).toContain('op vault list'); |
| 587 | + expect(harness.writeCalls[0]!.data).toContain('<!-- END:1password -->'); |
| 588 | + }); |
| 589 | + |
| 590 | + it('skips adding when section already present', () => { |
| 591 | + const harness = fakeDeps(); |
| 592 | + (harness.deps.readFileSync as ReturnType<typeof vi.fn>).mockReturnValue( |
| 593 | + '# TOOLS\n<!-- BEGIN:1password -->\nexisting\n<!-- END:1password -->' |
| 594 | + ); |
| 595 | + |
| 596 | + const env: Record<string, string | undefined> = { |
| 597 | + OP_SERVICE_ACCOUNT_TOKEN: 'ops_test123', |
| 598 | + }; |
| 599 | + |
| 600 | + updateToolsMd1PasswordSection(env, harness.deps); |
| 601 | + |
| 602 | + expect(harness.writeCalls).toHaveLength(0); |
| 603 | + }); |
| 604 | + |
| 605 | + it('removes stale section when token is absent', () => { |
| 606 | + const harness = fakeDeps(); |
| 607 | + (harness.deps.readFileSync as ReturnType<typeof vi.fn>).mockReturnValue( |
| 608 | + '# TOOLS\n<!-- BEGIN:1password -->\nold section\n<!-- END:1password -->\n' |
| 609 | + ); |
| 610 | + |
| 611 | + const env: Record<string, string | undefined> = {}; |
| 612 | + |
| 613 | + updateToolsMd1PasswordSection(env, harness.deps); |
| 614 | + |
| 615 | + expect(harness.writeCalls).toHaveLength(1); |
| 616 | + expect(harness.writeCalls[0]!.data).not.toContain('<!-- BEGIN:1password -->'); |
| 617 | + }); |
| 618 | + |
| 619 | + it('no-ops when TOOLS.md does not exist', () => { |
| 620 | + const harness = fakeDeps(); |
| 621 | + (harness.deps.existsSync as ReturnType<typeof vi.fn>).mockReturnValue(false); |
| 622 | + |
| 623 | + const env: Record<string, string | undefined> = { |
| 624 | + OP_SERVICE_ACCOUNT_TOKEN: 'ops_test123', |
| 625 | + }; |
| 626 | + |
| 627 | + updateToolsMd1PasswordSection(env, harness.deps); |
| 628 | + |
| 629 | + expect(harness.writeCalls).toHaveLength(0); |
| 630 | + }); |
| 631 | + |
| 632 | + it('no-ops when token absent and no stale section exists', () => { |
| 633 | + const harness = fakeDeps(); |
| 634 | + (harness.deps.readFileSync as ReturnType<typeof vi.fn>).mockReturnValue('# TOOLS\n'); |
| 635 | + |
| 636 | + const env: Record<string, string | undefined> = {}; |
| 637 | + |
| 638 | + updateToolsMd1PasswordSection(env, harness.deps); |
| 639 | + |
| 640 | + expect(harness.writeCalls).toHaveLength(0); |
| 641 | + }); |
| 642 | +}); |
| 643 | + |
570 | 644 | // ---- buildGatewayArgs ---- |
571 | 645 |
|
572 | 646 | describe('buildGatewayArgs', () => { |
|
0 commit comments