Skip to content

Commit ac21f40

Browse files
claude-code-bestglm-5.2
andcommitted
fix(artifact): scanner type narrowing and url regex
- Use double assertion (`as unknown as Record<string, unknown>`) at lines 30 and 90 to fix TS2352 per project convention - Tighten URL_REGEX to avoid capturing trailing punctuation (parens, quotes, commas) when URL is embedded in text - Add test case for array-form tool_result content path Co-Authored-By: glm-5.2 <zai-org@claude-code-best.win>
1 parent bdd023d commit ac21f40

2 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/commands/artifacts/__tests__/scanner.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@ describe('extractArtifacts', () => {
9999
expect(result[0].url).toBeUndefined()
100100
})
101101

102+
test('parses url/id/expires from array-form tool_result content', () => {
103+
const messages: Message[] = [
104+
assistantToolUse('tu1', { file_path: '/tmp/report.html', ttl: 7 }),
105+
{
106+
type: 'user',
107+
uuid: crypto.randomUUID(),
108+
message: {
109+
role: 'user',
110+
content: [
111+
{
112+
type: 'tool_result' as const,
113+
tool_use_id: 'tu1',
114+
content: [
115+
{ type: 'text' as const, text: 'Artifact uploaded: ' },
116+
{
117+
type: 'text' as const,
118+
text: 'https://x.test/7d/def.html (id: def, expires: 2026-06-27T10:00:00.000Z)',
119+
},
120+
],
121+
},
122+
],
123+
},
124+
},
125+
]
126+
127+
const result = extractArtifacts(messages)
128+
129+
expect(result).toHaveLength(1)
130+
expect(result[0]).toMatchObject({
131+
filePath: '/tmp/report.html',
132+
hash: 'def',
133+
url: 'https://x.test/7d/def.html',
134+
expiresAt: '2026-06-27T10:00:00.000Z',
135+
basename: 'report.html',
136+
isError: false,
137+
})
138+
})
139+
102140
test('orders newest first (last in conversation appears at top)', () => {
103141
const messages: Message[] = [
104142
assistantToolUse('tu1', { file_path: '/tmp/a.html', ttl: 7 }),

src/commands/artifacts/scanner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type ArtifactInfo = {
1212
isError: boolean
1313
}
1414

15-
const URL_REGEX = /https?:\/\/\S+\.html\b/
15+
const URL_REGEX = /https?:\/\/[^\s)"',]+\.html\b/
1616
const ID_REGEX = /\bid:\s*([A-Za-z0-9_-]+)/
1717
const EXPIRES_REGEX = /\bexpires:\s*([0-9T:.Z+-]+)/
1818

@@ -27,7 +27,7 @@ export function extractArtifacts(messages: Message[]): ArtifactInfo[] {
2727
for (const block of content) {
2828
if (typeof block !== 'object' || block === null) continue
2929
if (!('type' in block)) continue
30-
const b = block as Record<string, unknown>
30+
const b = block as unknown as Record<string, unknown>
3131
if (b.type !== 'tool_use') continue
3232
if (b.name !== 'artifact') continue
3333

@@ -87,7 +87,7 @@ function findToolResult(
8787
for (const block of content) {
8888
if (typeof block !== 'object' || block === null) continue
8989
if (!('type' in block)) continue
90-
const b = block as Record<string, unknown>
90+
const b = block as unknown as Record<string, unknown>
9191
if (b.type !== 'tool_result') continue
9292
if (b.tool_use_id !== toolUseId) continue
9393
return { content: b.content, is_error: b.is_error as boolean | undefined }

0 commit comments

Comments
 (0)