From 5814994b444c6f15ab59b5a7e0f2dcb674dfa54e Mon Sep 17 00:00:00 2001 From: Cameron Date: Thu, 9 Jul 2026 16:44:21 -0700 Subject: [PATCH] Finish bare-DID landing: label command + test mocks. Rebase onto main kept the write-path fix (resolveRepoDid) and main's local-scan aliases for legacy AT-URI `.repo` values. Wire label.ts the same way, and update issue tests so listRecords mocks and listIssues expectations match the merged API. Co-authored-by: Cursor --- src/commands/issue.ts | 7 +- src/commands/label.ts | 26 ++++---- tests/commands/issue.test.ts | 54 +++++++-------- tests/lib/issues-api.test.ts | 125 ++++++++++++++++++++++++----------- 4 files changed, 134 insertions(+), 78 deletions(-) diff --git a/src/commands/issue.ts b/src/commands/issue.ts index 8d8bcfb..a33b6a1 100644 --- a/src/commands/issue.ts +++ b/src/commands/issue.ts @@ -444,7 +444,12 @@ function createCreateCommand(): Command { }); // 7. Compute sequential number - const { issues: allIssues } = await listIssues({ client, repoDid, repoAliases: repoAliasesFor(context), limit: 100 }); + const { issues: allIssues } = await listIssues({ + client, + repoDid, + repoAliases, + limit: 100, + }); const sortedAll = allIssues.sort( (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() ); diff --git a/src/commands/label.ts b/src/commands/label.ts index c4c0b15..6f5e234 100644 --- a/src/commands/label.ts +++ b/src/commands/label.ts @@ -8,7 +8,7 @@ import { listLabelDefinitions, } from '../lib/labels-api.js'; import { listPulls } from '../lib/pulls-api.js'; -import { buildRepoAtUri } from '../utils/at-uri.js'; +import { resolveRepoDid } from '../utils/at-uri.js'; import { ensureAuthenticated, requireAuth } from '../utils/auth-helpers.js'; import { outputJson } from '../utils/formatting.js'; @@ -21,7 +21,7 @@ async function resolveSubjectUri( kind: SubjectKind, input: string, client: ReturnType, - repoAtUri: string, + repoDid: string, repoAliases: string[] = [] ): Promise<{ uri: string; displayId: string }> { const normalized = input.startsWith('#') ? input.slice(1) : input; @@ -33,7 +33,7 @@ async function resolveSubjectUri( } if (kind === 'issue') { - const { issues } = await listIssues({ client, repoAtUri, repoAliases, limit: 100 }); + const { issues } = await listIssues({ client, repoDid, repoAliases, limit: 100 }); const sorted = issues.sort( (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() ); @@ -42,7 +42,7 @@ async function resolveSubjectUri( return { uri: issue.uri, displayId: `#${num}` }; } - const { pulls } = await listPulls({ client, repoAtUri, limit: 100 }); + const { pulls } = await listPulls({ client, repoDid, limit: 100 }); const sorted = pulls.sort( (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() ); @@ -87,12 +87,12 @@ async function withRepoContext() { console.error('✗ Not in a Tangled repository'); process.exit(1); } - const repoAtUri = await buildRepoAtUri(context.owner, context.name, client); - // Stable DID remotes and older issue records may store the bare repo DID. + const repoDid = await resolveRepoDid(context.owner, context.name, client); + // Stable DID remotes and older issue records may store aliases in `.repo`. const repoAliases = Array.from( new Set([context.owner, context.name].filter((v) => typeof v === 'string' && v.length > 0)) ); - return { client, context, repoAtUri, repoAliases }; + return { client, context, repoDid, repoAliases }; } export function createLabelCommand(): Command { @@ -144,12 +144,12 @@ export function createLabelCommand(): Command { .action(async (kindArg: string, id: string, options: { json?: boolean }) => { try { const kind = parseKind(kindArg); - const { client, repoAtUri, repoAliases } = await withRepoContext(); + const { client, repoDid, repoAliases } = await withRepoContext(); const { uri, displayId } = await resolveSubjectUri( kind, id, client, - repoAtUri, + repoDid, repoAliases ); const labels = await getSubjectLabels(client, uri); @@ -186,12 +186,12 @@ export function createLabelCommand(): Command { .action(async (kindArg: string, id: string, name: string, options: { json?: boolean }) => { try { const kind = parseKind(kindArg); - const { client, context, repoAtUri, repoAliases } = await withRepoContext(); + const { client, context, repoDid, repoAliases } = await withRepoContext(); const { uri, displayId } = await resolveSubjectUri( kind, id, client, - repoAtUri, + repoDid, repoAliases ); @@ -231,12 +231,12 @@ export function createLabelCommand(): Command { .action(async (kindArg: string, id: string, name: string, options: { json?: boolean }) => { try { const kind = parseKind(kindArg); - const { client, context, repoAtUri, repoAliases } = await withRepoContext(); + const { client, context, repoDid, repoAliases } = await withRepoContext(); const { uri, displayId } = await resolveSubjectUri( kind, id, client, - repoAtUri, + repoDid, repoAliases ); diff --git a/tests/commands/issue.test.ts b/tests/commands/issue.test.ts index f479d35..480cbc6 100644 --- a/tests/commands/issue.test.ts +++ b/tests/commands/issue.test.ts @@ -49,9 +49,7 @@ describe('issue create command', () => { }); // Mock AT-URI builder - vi.mocked(atUri.resolveRepoDid).mockResolvedValue( - 'at://did:plc:abc123/sh.tangled.repo/test-repo' - ); + vi.mocked(atUri.resolveRepoDid).mockResolvedValue('did:plc:abc123'); // Mock body input vi.mocked(bodyInput.readBodyInput).mockResolvedValue(undefined); @@ -68,7 +66,7 @@ describe('issue create command', () => { it('should create issue with body text', async () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/test-repo', + repo: 'did:plc:abc123', title: 'Test Issue', body: 'Test body', createdAt: new Date().toISOString(), @@ -86,7 +84,7 @@ describe('issue create command', () => { expect(issuesApi.createIssue).toHaveBeenCalledWith({ client: mockClient, - repoDid: 'at://did:plc:abc123/sh.tangled.repo/test-repo', + repoDid: 'did:plc:abc123', title: 'Test Issue', body: 'Test body', }); @@ -100,7 +98,7 @@ describe('issue create command', () => { it('should create issue with body from file', async () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/test-repo', + repo: 'did:plc:abc123', title: 'Test Issue', body: 'Body from file', createdAt: new Date().toISOString(), @@ -126,7 +124,7 @@ describe('issue create command', () => { expect(bodyInput.readBodyInput).toHaveBeenCalledWith(undefined, '/tmp/body.txt'); expect(issuesApi.createIssue).toHaveBeenCalledWith({ client: mockClient, - repoDid: 'at://did:plc:abc123/sh.tangled.repo/test-repo', + repoDid: 'did:plc:abc123', title: 'Test Issue', body: 'Body from file', }); @@ -137,7 +135,7 @@ describe('issue create command', () => { it('should create issue without body', async () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/test-repo', + repo: 'did:plc:abc123', title: 'Test Issue', createdAt: new Date().toISOString(), uri: 'at://did:plc:abc123/sh.tangled.repo.issue/test123', @@ -154,7 +152,7 @@ describe('issue create command', () => { expect(issuesApi.createIssue).toHaveBeenCalledWith({ client: mockClient, - repoDid: 'at://did:plc:abc123/sh.tangled.repo/test-repo', + repoDid: 'did:plc:abc123', title: 'Test Issue', body: undefined, }); @@ -261,7 +259,7 @@ describe('issue create command', () => { describe('JSON output', () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/test-repo', + repo: 'did:plc:abc123', title: 'Test Issue', body: 'Test body', createdAt: '2024-01-01T00:00:00.000Z', @@ -341,7 +339,7 @@ describe('issue list command', () => { }); // Mock AT-URI builder - vi.mocked(atUri.resolveRepoDid).mockResolvedValue('at://did:plc:abc123/sh.tangled.repo/xyz789'); + vi.mocked(atUri.resolveRepoDid).mockResolvedValue('did:plc:abc123'); }); afterEach(() => { @@ -353,7 +351,7 @@ describe('issue list command', () => { const mockIssues: IssueWithMetadata[] = [ { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'First Issue', createdAt: new Date('2024-01-01').toISOString(), uri: 'at://did:plc:abc123/sh.tangled.repo.issue/issue1', @@ -362,7 +360,7 @@ describe('issue list command', () => { }, { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'Second Issue', createdAt: new Date('2024-01-02').toISOString(), uri: 'at://did:plc:abc123/sh.tangled.repo.issue/issue2', @@ -382,7 +380,8 @@ describe('issue list command', () => { expect(issuesApi.listIssues).toHaveBeenCalledWith({ client: mockClient, - repoDid: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repoDid: 'did:plc:abc123', + repoAliases: ['test.bsky.social', 'test-repo'], limit: 50, }); @@ -402,7 +401,8 @@ describe('issue list command', () => { expect(issuesApi.listIssues).toHaveBeenCalledWith({ client: mockClient, - repoDid: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repoDid: 'did:plc:abc123', + repoAliases: ['test.bsky.social', 'test-repo'], limit: 25, }); }); @@ -503,7 +503,7 @@ describe('issue list command', () => { const mockIssues: IssueWithMetadata[] = [ { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'First Issue', body: 'First body', createdAt: new Date('2024-01-01').toISOString(), @@ -513,7 +513,7 @@ describe('issue list command', () => { }, { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'Second Issue', createdAt: new Date('2024-01-02').toISOString(), uri: 'at://did:plc:abc123/sh.tangled.repo.issue/issue2', @@ -574,7 +574,7 @@ describe('issue view command', () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'Test Issue', body: 'Issue body', createdAt: new Date('2024-01-01').toISOString(), @@ -604,7 +604,7 @@ describe('issue view command', () => { protocol: 'ssh', }); - vi.mocked(atUri.resolveRepoDid).mockResolvedValue('at://did:plc:abc123/sh.tangled.repo/xyz789'); + vi.mocked(atUri.resolveRepoDid).mockResolvedValue('did:plc:abc123'); vi.mocked(authHelpers.requireAuth).mockResolvedValue({ did: 'did:plc:abc123', @@ -639,7 +639,7 @@ describe('issue view command', () => { mockClient, mockIssue.uri, '#1', - 'at://did:plc:abc123/sh.tangled.repo/xyz789' + 'did:plc:abc123' ); expect(consoleLogSpy).toHaveBeenCalledWith('\nIssue #1 [OPEN]'); expect(consoleLogSpy).toHaveBeenCalledWith('Title: Test Issue'); @@ -666,7 +666,7 @@ describe('issue view command', () => { mockClient, 'at://did:plc:abc123/sh.tangled.repo.issue/issue1', 'issue1', - 'at://did:plc:abc123/sh.tangled.repo/xyz789' + 'did:plc:abc123' ); expect(consoleLogSpy).toHaveBeenCalledWith('\nIssue issue1 [CLOSED]'); }); @@ -801,7 +801,7 @@ describe('issue edit command', () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'Original Title', createdAt: new Date('2024-01-01').toISOString(), uri: 'at://did:plc:abc123/sh.tangled.repo.issue/issue1', @@ -830,7 +830,7 @@ describe('issue edit command', () => { protocol: 'ssh', }); - vi.mocked(atUri.resolveRepoDid).mockResolvedValue('at://did:plc:abc123/sh.tangled.repo/xyz789'); + vi.mocked(atUri.resolveRepoDid).mockResolvedValue('did:plc:abc123'); vi.mocked(bodyInput.readBodyInput).mockResolvedValue(undefined); vi.mocked(authHelpers.requireAuth).mockResolvedValue({ @@ -975,7 +975,7 @@ describe('issue close command', () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'Test Issue', createdAt: new Date('2024-01-01').toISOString(), uri: 'at://did:plc:abc123/sh.tangled.repo.issue/issue1', @@ -1004,7 +1004,7 @@ describe('issue close command', () => { protocol: 'ssh', }); - vi.mocked(atUri.resolveRepoDid).mockResolvedValue('at://did:plc:abc123/sh.tangled.repo/xyz789'); + vi.mocked(atUri.resolveRepoDid).mockResolvedValue('did:plc:abc123'); vi.mocked(issuesApi.getCompleteIssueData).mockResolvedValue({ number: 1, title: mockIssue.title, @@ -1092,7 +1092,7 @@ describe('issue reopen command', () => { const mockIssue: IssueWithMetadata = { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:abc123/sh.tangled.repo/xyz789', + repo: 'did:plc:abc123', title: 'Test Issue', createdAt: new Date('2024-01-01').toISOString(), uri: 'at://did:plc:abc123/sh.tangled.repo.issue/issue1', @@ -1121,7 +1121,7 @@ describe('issue reopen command', () => { protocol: 'ssh', }); - vi.mocked(atUri.resolveRepoDid).mockResolvedValue('at://did:plc:abc123/sh.tangled.repo/xyz789'); + vi.mocked(atUri.resolveRepoDid).mockResolvedValue('did:plc:abc123'); vi.mocked(issuesApi.getCompleteIssueData).mockResolvedValue({ number: 1, title: mockIssue.title, diff --git a/tests/lib/issues-api.test.ts b/tests/lib/issues-api.test.ts index 35b747d..f4716a6 100644 --- a/tests/lib/issues-api.test.ts +++ b/tests/lib/issues-api.test.ts @@ -22,7 +22,7 @@ const createMockClient = (authenticated = true): TangledApiClient => { atproto: { repo: { createRecord: vi.fn(), - listRecords: vi.fn(), + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: vi.fn(), putRecord: vi.fn(), deleteRecord: vi.fn(), @@ -67,13 +67,13 @@ describe('createIssue', () => { const result = await createIssue({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', title: 'Bug: Login fails', body: 'Detailed description of the bug', }); expect(result).toMatchObject({ - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Bug: Login fails', body: 'Detailed description of the bug', uri: 'at://did:plc:test123/sh.tangled.repo.issue/abc123', @@ -86,7 +86,7 @@ describe('createIssue', () => { collection: 'sh.tangled.repo.issue', record: expect.objectContaining({ $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Bug: Login fails', body: 'Detailed description of the bug', createdAt: expect.any(String), @@ -114,7 +114,7 @@ describe('createIssue', () => { const result = await createIssue({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', title: 'Simple issue', }); @@ -128,7 +128,7 @@ describe('createIssue', () => { await expect( createIssue({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', title: 'Test', }) ).rejects.toThrow('Must be authenticated'); @@ -150,7 +150,7 @@ describe('createIssue', () => { await expect( createIssue({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', title: 'Test', }) ).rejects.toThrow('Failed to create issue: API error'); @@ -182,7 +182,7 @@ describe('listIssues', () => { cid: 'cid1', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Issue 1', body: 'Description 1', createdAt: '2024-01-01T00:00:00.000Z', @@ -195,7 +195,7 @@ describe('listIssues', () => { cid: 'cid2', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Issue 2', createdAt: '2024-01-02T00:00:00.000Z', }, @@ -203,12 +203,19 @@ describe('listIssues', () => { }); vi.mocked(mockClient.getAgent).mockReturnValue({ - com: { atproto: { repo: { getRecord: mockGetRecord } } }, + com: { + atproto: { + repo: { + getRecord: mockGetRecord, + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), + }, + }, + }, } as never); const result = await listIssues({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', }); expect(result.issues).toHaveLength(2); @@ -225,7 +232,7 @@ describe('listIssues', () => { }); expect(getBacklinks).toHaveBeenCalledWith( - 'at://did:plc:owner/sh.tangled.repo/my-repo', + 'did:plc:owner', 'sh.tangled.repo.issue', '.repo', 50, @@ -238,7 +245,7 @@ describe('listIssues', () => { const result = await listIssues({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', }); expect(result.issues).toEqual([]); @@ -249,7 +256,7 @@ describe('listIssues', () => { const result = await listIssues({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', }); expect(result.cursor).toBe('nextpage'); @@ -261,7 +268,7 @@ describe('listIssues', () => { await expect( listIssues({ client: mockClient, - repoDid: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repoDid: 'did:plc:owner', }) ).rejects.toThrow('Must be authenticated'); }); @@ -281,7 +288,7 @@ describe('getIssue', () => { cid: 'cid1', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Test Issue', body: 'Test Description', createdAt: '2024-01-01T00:00:00.000Z', @@ -293,6 +300,7 @@ describe('getIssue', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: mockGetRecord, }, }, @@ -325,6 +333,7 @@ describe('getIssue', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: mockGetRecord, }, }, @@ -373,7 +382,7 @@ describe('updateIssue', () => { uri: 'at://did:plc:test123/sh.tangled.repo.issue/issue1', cid: 'old-cid', value: { - repo: 'at://did:plc:test123/sh.tangled.repo/my-repo', + repo: 'did:plc:test123', title: 'Old Title', body: 'Original body', createdAt: '2024-01-01T00:00:00.000Z', @@ -392,6 +401,7 @@ describe('updateIssue', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: mockGetRecord, putRecord: mockPutRecord, }, @@ -426,7 +436,7 @@ describe('updateIssue', () => { uri: 'at://did:plc:test123/sh.tangled.repo.issue/issue1', cid: 'old-cid', value: { - repo: 'at://did:plc:test123/sh.tangled.repo/my-repo', + repo: 'did:plc:test123', title: 'Title', body: 'Old body', createdAt: '2024-01-01T00:00:00.000Z', @@ -444,6 +454,7 @@ describe('updateIssue', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: mockGetRecord, putRecord: mockPutRecord, }, @@ -497,7 +508,7 @@ describe('closeIssue', () => { uri: 'at://did:plc:owner/sh.tangled.repo.issue/issue1', cid: 'cid1', value: { - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Test Issue', createdAt: '2024-01-01T00:00:00.000Z', }, @@ -515,6 +526,7 @@ describe('closeIssue', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: mockGetRecord, createRecord: mockCreateRecord, }, @@ -587,6 +599,7 @@ describe('getIssueState', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: vi.fn().mockResolvedValue({ data: { uri: 'at://did:plc:owner/sh.tangled.repo.issue.state/state1', @@ -621,6 +634,7 @@ describe('getIssueState', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: vi .fn() .mockResolvedValueOnce({ @@ -665,6 +679,7 @@ describe('getIssueState', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: vi .fn() .mockResolvedValueOnce({ @@ -719,7 +734,7 @@ describe('reopenIssue', () => { uri: 'at://did:plc:owner/sh.tangled.repo.issue/issue1', cid: 'cid1', value: { - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Test Issue', createdAt: '2024-01-01T00:00:00.000Z', }, @@ -737,6 +752,7 @@ describe('reopenIssue', () => { com: { atproto: { repo: { + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), getRecord: mockGetRecord, createRecord: mockCreateRecord, }, @@ -784,7 +800,7 @@ describe('resolveSequentialNumber', () => { '#3', 'at://did:plc:owner/sh.tangled.repo.issue/issue3', mockClient, - 'at://did:plc:owner/sh.tangled.repo/my-repo' + 'did:plc:owner' ); expect(result).toBe(3); }); @@ -807,7 +823,7 @@ describe('resolveSequentialNumber', () => { cid: 'cid1', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'First', createdAt: '2024-01-01T00:00:00.000Z', }, @@ -819,7 +835,7 @@ describe('resolveSequentialNumber', () => { cid: 'cid2', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Second', createdAt: '2024-01-02T00:00:00.000Z', }, @@ -827,14 +843,21 @@ describe('resolveSequentialNumber', () => { }); vi.mocked(mockClient.getAgent).mockReturnValue({ - com: { atproto: { repo: { getRecord: mockGetRecord } } }, + com: { + atproto: { + repo: { + getRecord: mockGetRecord, + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), + }, + }, + }, } as never); const result = await resolveSequentialNumber( 'issue-b', 'at://did:plc:owner/sh.tangled.repo.issue/issue-b', mockClient, - 'at://did:plc:owner/sh.tangled.repo/my-repo' + 'did:plc:owner' ); expect(result).toBe(2); }); @@ -852,7 +875,7 @@ describe('resolveSequentialNumber', () => { cid: 'cid1', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'First', createdAt: '2024-01-01T00:00:00.000Z', }, @@ -860,14 +883,21 @@ describe('resolveSequentialNumber', () => { }); vi.mocked(mockClient.getAgent).mockReturnValue({ - com: { atproto: { repo: { getRecord: mockGetRecord } } }, + com: { + atproto: { + repo: { + getRecord: mockGetRecord, + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), + }, + }, + }, } as never); const result = await resolveSequentialNumber( 'nonexistent', 'at://did:plc:owner/sh.tangled.repo.issue/nonexistent', mockClient, - 'at://did:plc:owner/sh.tangled.repo/my-repo' + 'did:plc:owner' ); expect(result).toBeUndefined(); }); @@ -896,7 +926,7 @@ describe('getCompleteIssueData', () => { cid: 'cid1', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Test Issue', body: 'Test body', createdAt: '2024-01-01T00:00:00.000Z', @@ -912,14 +942,21 @@ describe('getCompleteIssueData', () => { }); vi.mocked(mockClient.getAgent).mockReturnValue({ - com: { atproto: { repo: { getRecord: mockGetRecord } } }, + com: { + atproto: { + repo: { + getRecord: mockGetRecord, + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), + }, + }, + }, } as never); const result = await getCompleteIssueData( mockClient, 'at://did:plc:owner/sh.tangled.repo.issue/issue1', '#1', // fast-path for number - 'at://did:plc:owner/sh.tangled.repo/my-repo' + 'did:plc:owner' ); expect(result).toEqual({ @@ -941,7 +978,7 @@ describe('getCompleteIssueData', () => { cid: 'cid1', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'Test Issue', createdAt: '2024-01-01T00:00:00.000Z', }, @@ -949,14 +986,21 @@ describe('getCompleteIssueData', () => { }); vi.mocked(mockClient.getAgent).mockReturnValue({ - com: { atproto: { repo: { getRecord: mockGetRecord } } }, + com: { + atproto: { + repo: { + getRecord: mockGetRecord, + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), + }, + }, + }, } as never); const result = await getCompleteIssueData( mockClient, 'at://did:plc:owner/sh.tangled.repo.issue/issue1', '#2', - 'at://did:plc:owner/sh.tangled.repo/my-repo', + 'did:plc:owner', 'closed' ); @@ -974,7 +1018,7 @@ describe('getCompleteIssueData', () => { cid: 'cid1', value: { $type: 'sh.tangled.repo.issue', - repo: 'at://did:plc:owner/sh.tangled.repo/my-repo', + repo: 'did:plc:owner', title: 'No body issue', createdAt: '2024-01-01T00:00:00.000Z', }, @@ -982,14 +1026,21 @@ describe('getCompleteIssueData', () => { }); vi.mocked(mockClient.getAgent).mockReturnValue({ - com: { atproto: { repo: { getRecord: mockGetRecord } } }, + com: { + atproto: { + repo: { + getRecord: mockGetRecord, + listRecords: vi.fn().mockResolvedValue({ data: { records: [] } }), + }, + }, + }, } as never); const result = await getCompleteIssueData( mockClient, 'at://did:plc:owner/sh.tangled.repo.issue/issue1', '#1', - 'at://did:plc:owner/sh.tangled.repo/my-repo' + 'did:plc:owner' ); expect(result.body).toBeUndefined(); -- 2.51.2