Skip to content

Commit 45214ce

Browse files
committed
fix(workflow-code): a table declaration edited since the last write types from the kept manifest in the type check's base
1 parent 333769d commit 45214ce

2 files changed

Lines changed: 70 additions & 10 deletions

File tree

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ export function localDeclarations(files: Readonly<Record<string, string>>): Loca
253253

254254
/**
255255
* What the workspace directory `root` declared as the last get or apply wrote it: the paths that
256-
* write recorded (`written`), each folder kind's keys from them, and a root file's names only
257-
* while its text is unchanged since; an edited one's earlier text is gone, so it declares none.
256+
* write recorded (`written`), each folder kind's keys from them. A file `workspace.d.ts` reads
257+
* its types from (a root file, a table's declaration) counts only while its text is unchanged
258+
* since: an edited one's earlier text is gone, so it declares nothing, and a table it declared
259+
* types from the kept manifest instead.
258260
*/
259261
export async function writtenLocalDeclarations(
260262
root: string,
@@ -264,14 +266,16 @@ export async function writtenLocalDeclarations(
264266
for (const path of Object.keys(written.digests)) {
265267
if (kindOfPath(path) !== null) files[path] = ''
266268
}
267-
const rootFiles = APPLY_ORDER.filter(isFileKind)
268-
.map((kind) => KIND_DIRS[kind])
269-
.filter((file) => Object.hasOwn(files, file))
270-
const unchanged = await unchangedTexts(root, rootFiles, written.digests)
271-
for (const file of rootFiles) {
272-
const text = unchanged.get(file)
273-
if (text === undefined) delete files[file]
274-
else files[file] = text
269+
const rootFiles = new Set<string>(APPLY_ORDER.filter(isFileKind).map((kind) => KIND_DIRS[kind]))
270+
const typedFrom = Object.keys(files).filter(
271+
(path) =>
272+
rootFiles.has(path) || (kindOfPath(path) === 'table' && path.endsWith(DECLARATION_EXTENSION))
273+
)
274+
const unchanged = await unchangedTexts(root, typedFrom, written.digests)
275+
for (const path of typedFrom) {
276+
const text = unchanged.get(path)
277+
if (text === undefined) delete files[path]
278+
else if (rootFiles.has(path)) files[path] = text
275279
}
276280
return localDeclarations(files)
277281
}

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,6 +1515,62 @@ describe('the type check of workspaces source check', () => {
15151515
}
15161516
)
15171517

1518+
it.each([
1519+
['a kept resource listing', true],
1520+
['no resource listing', false],
1521+
])("reports one a table declaration's edit caused, with %s", async (_listing, listed) => {
1522+
const table = (type: string) =>
1523+
[
1524+
'// @sim-sdk 1',
1525+
"import { column, defineTable } from '@sim/workflow-sdk/workspace'",
1526+
`export default defineTable({ name: 'leads', columns: { score: column.${type}() } })`,
1527+
'',
1528+
].join('\n')
1529+
serve(
1530+
{
1531+
'tables/leads.ts': table('number'),
1532+
'workflows/save/workflow.ts': [
1533+
'// @sim-sdk 1',
1534+
"import { table, trigger, workflow } from '@sim/workflow-sdk'",
1535+
"export default workflow('Save', {}, () => {",
1536+
" const start = trigger.start('Start', {})",
1537+
" const save = table.insertRow('Save', { tableId: table('leads'), data: { score: 5 } })",
1538+
' start.to(save)',
1539+
'})',
1540+
'',
1541+
].join('\n'),
1542+
},
1543+
{
1544+
kinds: ['table', 'workflow'],
1545+
...(listed
1546+
? {
1547+
manifest: {
1548+
...manifestWith('number'),
1549+
workflows: [{ key: 'save', inputs: [] }],
1550+
tables: [
1551+
{
1552+
key: 'leads',
1553+
id: 'tbl-1',
1554+
name: 'leads',
1555+
columns: [{ name: 'score', type: 'number' }],
1556+
},
1557+
],
1558+
},
1559+
}
1560+
: {}),
1561+
}
1562+
)
1563+
await get()
1564+
writeFileSync(join(dir, 'tables/leads.ts'), table('boolean'))
1565+
1566+
await runWorkspaceSource('check', dir)
1567+
1568+
expect(result().diagnostics).toEqual([
1569+
expect.objectContaining({ code: 'E_TYPE', file: 'workflows/save/workflow.ts', line: 5 }),
1570+
])
1571+
expect(process.exitCode).toBe(1)
1572+
})
1573+
15181574
it.each([
15191575
['a kept resource listing', true],
15201576
['no resource listing', false],

0 commit comments

Comments
 (0)