Skip to content

Commit a2e090f

Browse files
committed
chore(audits): exempt Mothership contract copies from the relative-import rule
contracts:sync copies these files byte for byte from the worker, whose sibling imports are relative, so they cannot use the app's aliases. Exempt only files in lib/mothership/generated that carry the sync header, and drop their baseline entries.
1 parent 9e4cd91 commit a2e090f

3 files changed

Lines changed: 34 additions & 8 deletions

File tree

‎scripts/check-source-conventions.baseline.json‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@
165165
"apps/sim/lib/core/async-jobs/types.test.ts": 1,
166166
"apps/sim/lib/core/config/cost-multiplier.ts": 1,
167167
"apps/sim/lib/core/config/env-flags.ts": 3,
168+
"apps/sim/lib/core/rate-limiter/hosted-key/queue.test.ts": 1,
168169
"apps/sim/lib/core/rate-limiter/hosted-key/rate-limiter.test.ts": 3,
169170
"apps/sim/lib/core/rate-limiter/hosted-key/rate-limiter.ts": 2,
170-
"apps/sim/lib/core/rate-limiter/hosted-key/queue.test.ts": 1,
171171
"apps/sim/lib/core/rate-limiter/rate-limiter.test.ts": 2,
172172
"apps/sim/lib/core/rate-limiter/rate-limiter.ts": 2,
173173
"apps/sim/lib/core/rate-limiter/route-helpers.test.ts": 1,
@@ -207,11 +207,6 @@
207207
"apps/sim/lib/mothership/chat/selection-context.test.ts": 1,
208208
"apps/sim/lib/mothership/chat/sim-key-redaction.test.ts": 1,
209209
"apps/sim/lib/mothership/chat/terminal-state.test.ts": 1,
210-
"apps/sim/lib/mothership/generated/agent-cli.ts": 2,
211-
"apps/sim/lib/mothership/generated/assistant.ts": 1,
212-
"apps/sim/lib/mothership/generated/protocol.ts": 3,
213-
"apps/sim/lib/mothership/generated/resources.ts": 1,
214-
"apps/sim/lib/mothership/generated/sim-transport.ts": 4,
215210
"apps/sim/lib/mothership/request/go/inline-images.test.ts": 1,
216211
"apps/sim/lib/mothership/request/handlers/complete.ts": 2,
217212
"apps/sim/lib/mothership/request/handlers/error.ts": 2,
@@ -280,9 +275,9 @@
280275
"apps/sim/lib/pptx-renderer/shapes/presets.ts": 1,
281276
"apps/sim/lib/table/workflow-columns.ts": 1,
282277
"apps/sim/lib/tools/falai-pricing.test.ts": 1,
283-
"apps/sim/lib/uploads/contexts/workspace/track-chat-upload.test.ts": 1,
284278
"apps/sim/lib/uploads/contexts/workspace/file-manager-errors.test.ts": 1,
285279
"apps/sim/lib/uploads/contexts/workspace/file-manager.test.ts": 1,
280+
"apps/sim/lib/uploads/contexts/workspace/track-chat-upload.test.ts": 1,
286281
"apps/sim/lib/webhooks/providers/table.ts": 1,
287282
"apps/sim/lib/webhooks/providers/whatsapp.test.ts": 1,
288283
"apps/sim/lib/workflows/comparison/normalize.test.ts": 1,

‎scripts/check-source-conventions.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ describe('relative-import', () => {
103103
hits('packages/utils/src/object.ts', "import { a } from './a'", 'relative-import')
104104
).toEqual([])
105105
})
106+
107+
it('exempts a Mothership contract copy only where contracts:sync writes it', () => {
108+
const copy = [
109+
'// GENERATED — do not edit. Source of truth: mothership worker packages/contracts/src/sim-transport.ts',
110+
"import { MemoryNotesAccessInput } from './memory-notes-access'",
111+
].join('\n')
112+
expect(
113+
hits('apps/sim/lib/mothership/generated/sim-transport.ts', copy, 'relative-import')
114+
).toEqual([])
115+
expect(hits('apps/sim/lib/feature/service.ts', copy, 'relative-import')).toEqual([
116+
'./memory-notes-access',
117+
])
118+
expect(
119+
hits(
120+
'apps/sim/lib/mothership/generated/handwritten.ts',
121+
"import { a } from './a'",
122+
'relative-import'
123+
)
124+
).toEqual(['./a'])
125+
})
106126
})
107127

108128
describe('text-size-literal', () => {

‎scripts/check-source-conventions.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* import whose every binding the barrel then exports (`export { X }`, or renamed with
1010
* `export const Y = X`). A path that leaves the folder (`../x`,
1111
* `./../x`), a side-effect import, and an import the barrel keeps for itself are all flagged.
12+
* A verbatim Mothership contract copy in `lib/mothership/generated/` is exempt: its imports mirror
13+
* the worker source it is synced from, so it cannot use the app's aliases.
1214
* - `text-size-literal` (`.claude/rules/sim-styling.md` "Tailwind" 3): an `apps/sim` string or
1315
* template literal sets type size with `text-[Npx]` where the documented text scale has a token
1416
* for that size (`text-[13px]` → `text-small`). The literal also drops the token's line-height.
@@ -522,6 +524,15 @@ function findBareRouteHandlers(file: string, program: Node): Violation[] {
522524
return violations
523525
}
524526

527+
const CONTRACT_COPY_DIR = 'apps/sim/lib/mothership/generated/'
528+
const CONTRACT_COPY_HEADER =
529+
'// GENERATED — do not edit. Source of truth: mothership worker packages/contracts/'
530+
531+
/** A file `contracts:sync` copies byte for byte from the Mothership worker. */
532+
function isContractCopy(file: string, source: string): boolean {
533+
return file.startsWith(CONTRACT_COPY_DIR) && source.startsWith(CONTRACT_COPY_HEADER)
534+
}
535+
525536
/** Unit, integration and live tests, plus fixtures: they bind real boundaries on purpose. */
526537
function isTestFile(file: string): boolean {
527538
return /\.(?:test|spec|integration)\.tsx?$/.test(file) || file.includes('/__fixtures__/')
@@ -533,7 +544,7 @@ export function findViolations(file: string, source: string): Violation[] {
533544
const test = isTestFile(file)
534545
const isApi = file.startsWith('apps/sim/app/api/') && !test
535546
// Cheap textual gates; each is a superset of what its rule can match, and the AST decides.
536-
const wantsRelative = /['"`]\.\.?\//.test(source)
547+
const wantsRelative = !isContractCopy(file, source) && /['"`]\.\.?\//.test(source)
537548
const wantsTextSize = !test && /text-\[\d/.test(source)
538549
const wantsStyle = !test && file.endsWith('.tsx') && /\bstyle\s*=\s*\{/.test(source)
539550
const wantsDb = isApi && source.includes('@sim/db')

0 commit comments

Comments
 (0)