Skip to content

Commit b539715

Browse files
authored
fix(workspace-source): count a key-taken refusal on a folder sent by its base in status (#10603)
* fix(workspace-source): keep a key-taken refusal on a workflow folder sent by its base in status counts isFolderEvaluationFinding treated a shared-code finding pinned to a file as compile/lint output. Since kindFinding defaults the file to the declaration, a workspace E_NAME_TAKEN on an unchanged folder carried a file too, so status dropped the error the apply refuses with. Folder evaluation findings always carry a line; workspace findings never do, so key on the line. * fix(workspace-source): key a folder-evaluation shared code on its line alone Test that a shared code the compile pins to a line of a folder sent by its base is still left out of status, and note at kindFinding that a shared code never carries a line.
1 parent 2b19744 commit b539715

3 files changed

Lines changed: 57 additions & 6 deletions

File tree

‎apps/sim/lib/workspace-source/application/findings.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ type FindingLocation = Pick<FlatDiagnostic, 'file' | 'line' | 'column' | 'endLin
7171
/**
7272
* A finding about one resource, its severity fixed by the code's prefix. It points at the file
7373
* that declares the resource unless `extras` points it elsewhere (a table's rows file, the line of
74-
* a workflow that uses the resource).
74+
* a workflow that uses the resource). A shared code never carries a line: `sim workspaces source
75+
* status` reads a line as the output of evaluating a workflow folder (`isFolderEvaluationFinding`).
7576
*/
7677
export function kindFinding(
7778
kind: WorkspaceKind,

‎packages/sim-cli/src/commands/protocol/workspace-source-status.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,31 @@ describe('workspaces source status', () => {
644644
expect(report.diagnostics ?? []).toEqual([])
645645
})
646646

647+
it('leaves out a key-taken finding the compile pins to a line of a workflow an apply sends by its base', async () => {
648+
mockRequest.mockResolvedValue(
649+
dry(
650+
[{ kind: 'workflow', key: 'ingest', action: 'noop' }],
651+
[
652+
{
653+
code: 'E_NAME_TAKEN',
654+
severity: 'error',
655+
message: 'Two blocks are named "Agent".',
656+
file: 'workflows/ingest/workflow.ts',
657+
line: 1,
658+
kind: 'workflow',
659+
key: 'ingest',
660+
},
661+
]
662+
)
663+
)
664+
665+
await run('status')
666+
667+
const report = printed()
668+
expect(report.plan).toMatchObject({ errors: 0 })
669+
expect(report.diagnostics ?? []).toEqual([])
670+
})
671+
647672
it('keeps a plan refusal about a workflow an apply sends by its base: status counts the error the apply refuses with', async () => {
648673
mockRequest.mockResolvedValue(
649674
dry(
@@ -670,6 +695,30 @@ describe('workspaces source status', () => {
670695
expect(report.diagnostics).toEqual([expect.objectContaining({ code: 'E_PLAN_REF_DELETED' })])
671696
})
672697

698+
it('keeps a key-taken refusal pinned to the folder of a workflow an apply sends by its base', async () => {
699+
mockRequest.mockResolvedValue(
700+
dry(
701+
[{ kind: 'workflow', key: 'ingest', action: 'noop' }],
702+
[
703+
{
704+
code: 'E_NAME_TAKEN',
705+
severity: 'error',
706+
message: 'The workflow key "ingest" belongs to "Other".',
707+
file: 'workflows/ingest/workflow.ts',
708+
kind: 'workflow',
709+
key: 'ingest',
710+
},
711+
]
712+
)
713+
)
714+
715+
await run('status')
716+
717+
const report = printed()
718+
expect(report.plan).toMatchObject({ errors: 1 })
719+
expect(report.diagnostics).toEqual([expect.objectContaining({ code: 'E_NAME_TAKEN' })])
720+
})
721+
673722
it('keeps lint findings on a workflow edited here, which an apply sends whole', async () => {
674723
write('workflows/ingest/workflow.ts', INGEST.replace("'Ingest'", "'Ingest v2'"))
675724
mockRequest.mockResolvedValue(

‎packages/workspace-code/src/diagnostics/codes.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,14 @@ const SHARED_CODE_SET: ReadonlySet<string> = new Set(SHARED_CODES)
358358

359359
/**
360360
* Whether a finding comes from evaluating a workflow folder's files (compile, lint): a workflow
361-
* pipeline code, or one {@link SHARED_CODES} holds pinned to a file. The server reports these only
362-
* for a folder sent whole; a workspace code (a plan check such as `E_PLAN_REF_DELETED`, a held
363-
* reference, a stale resource) can be about any folder, sent whole or by its base.
361+
* pipeline code, or one {@link SHARED_CODES} holds pinned to a line of a file. The server reports
362+
* these only for a folder sent whole; a workspace code (a plan check such as `E_PLAN_REF_DELETED`,
363+
* a held reference, a stale resource) can be about any folder, sent whole or by its base. A
364+
* workspace finding of a shared code points at the resource's file but never at a line in it.
364365
*/
365-
export function isFolderEvaluationFinding(finding: { code: string; file?: string }): boolean {
366+
export function isFolderEvaluationFinding(finding: { code: string; line?: number }): boolean {
366367
if (OWN_CODE_SET.has(finding.code)) return false
367-
return !SHARED_CODE_SET.has(finding.code) || finding.file !== undefined
368+
return !SHARED_CODE_SET.has(finding.code) || finding.line !== undefined
368369
}
369370

370371
/**

0 commit comments

Comments
 (0)