mirror of
https://github.com/simstudioai/sim.git
synced 2026-11-22 21:28:37 +08:00
* chore(skills): vendor codebase-design deep-module vocabulary skill * chore(cleanup): remove dead client hooks, query exports, and orphaned scheduled-tasks utils * refactor(queries): concentrate workflow search MCP list fetches into two helpers * chore(cleanup): dedupe app copies of shared package helpers - import subflow helpers from @sim/workflow-persistence/subflow-helpers - drop env-capabilities and service-account-metadata re-export shims - use isWorkflowBlockProtected in block-enablement - move anonymous user identity into @sim/auth/principal - reuse isLightTileColor from @sim/workflow-renderer/tile-icon-color - use @sim/utils sleep/getErrorMessage in sim-cli (bundled) - remove dead normalizeSandboxProvider export * chore(cleanup): trim log-views to toOverview and use interruptibleSleep in data drains * chore(cleanup): use @sim/utils/object helpers in internal clients and drop dead vanta input-size * chore(cleanup): remove dead logs types, organization utils, and workspace permission queries * chore(cleanup): remove dead custom-tool use cases and unused folder, slack-search, skills, and selector helpers * chore(cleanup): remove unreachable application use cases and API helpers Delete test-only Copilot/executor use cases (bulk table rows by filter, credential delete-many, credential-group invite send/link, sandbox and connected-accounts adapters) with their operation entries, the unused public API route wrapper, parseToolRequest, the invitation management error policy, the execution invitation rate limit, and dead table/chat route helpers. * chore(cleanup): remove dead application use cases and utils, share workflow context resolver - Delete unreachable platform-context, workflow VFS, deployment-overview, chat undeploy, and Copilot block-output/upstream-reference use cases plus their workflowOperations entries - Delete dead fetch-deadline and scheduling utils and unused exported helpers - Add resolvePrincipalWorkflowContext and use it at the 16 identical resolvers - Share processCodeFailure between the Daytona and E2B adapters - Use escapeRegExp and generateId in place of inline equivalents * chore(cleanup): remove unreferenced Copilot table commands, workflow mutation handlers, and param types chore(cleanup): drop unused billing client usage-pill and plan-view exports * chore(cleanup): share webhook provider config, notification URL, and credential token helpers * chore(cleanup): remove dead billing, credential, MCP, and API key exports * chore(cleanup): remove dead executor helpers and redundant LoopConfigWithNodes type * refactor(executor): export subflow node-id codec functions directly and drop forwarders * refactor(providers): drop pass-through model wrappers and share the json_schema response format builder * chore(cleanup): remove dead executor, tools, and block registry exports * chore(cleanup): remove unreachable workspace-file and table use cases * chore(cleanup): reuse knowledge tag slot constants in the tags service * chore(cleanup): share escapeLikePattern from @sim/utils/string * chore(cleanup): reuse zip-guard EOCD parsing in the file sniffer * chore(cleanup): use isRecordLike for inline record guards * chore(cleanup): remove dead uploads, tokenization, table, knowledge, and search exports * chore(cleanup): use shared escapeLikePattern in list-query and logs filters * docs(skills): align codebase-design testing guidance with repo rules and add its license * chore(cleanup): cascade-remove use cases, helpers, and mocks orphaned by deleted Copilot commands * chore(cleanup): consolidate shared helpers and restore TSDoc on moved codec and subflow helpers * test(cleanup): port storage-cleanup ownership tests and drop stale mock keys * test(scripts): follow model-access import move in application-graph fixture * chore(skills): drop vendored codebase-design skill from the repo
87 lines
3.4 KiB
TypeScript
87 lines
3.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
||
import { FORBIDDEN_PREFIXES, findViolations, runtimeSpecifiers } from './check-application-graph'
|
||
|
||
describe('runtimeSpecifiers', () => {
|
||
/**
|
||
* The heaviest edge of all — the module is loaded purely to run — and the one
|
||
* nothing in the importing file names, so it was walked straight past.
|
||
*/
|
||
it('collects a side-effect import, in source order', () => {
|
||
expect(
|
||
runtimeSpecifiers("import '@/lib/uploads/core/setup.server'\nimport { a } from '@/lib/a'\n")
|
||
).toEqual(['@/lib/uploads/core/setup.server', '@/lib/a'])
|
||
})
|
||
|
||
it('ignores type-only statements, which the compiler erases', () => {
|
||
expect(
|
||
runtimeSpecifiers(
|
||
"import type { A } from '@/lib/a'\nimport type B from '@/lib/b'\nexport type { C } from '@/lib/c'\n"
|
||
)
|
||
).toEqual([])
|
||
})
|
||
})
|
||
|
||
describe('the guarded roots', () => {
|
||
it('reports the shortest chain when a forbidden module is reachable', () => {
|
||
/**
|
||
* Walked from a module that legitimately imports the provider registry, so
|
||
* the walker is proven able to fail. Without this the suite above would
|
||
* still pass if `findViolations` silently stopped finding anything.
|
||
*/
|
||
const violations = findViolations({
|
||
root: 'lib/permission-groups/model-access.ts',
|
||
forbidden: FORBIDDEN_PREFIXES,
|
||
})
|
||
expect(violations).toHaveLength(1)
|
||
expect(violations[0].forbidden).toBe('providers/models.ts')
|
||
expect(violations[0].reason).toBe(FORBIDDEN_PREFIXES['providers/'])
|
||
expect(violations[0].path).toEqual([
|
||
'lib/permission-groups/model-access.ts',
|
||
'providers/models.ts',
|
||
])
|
||
})
|
||
})
|
||
|
||
describe('a deferred edge into a forbidden tree', () => {
|
||
/**
|
||
* The evasion: a root that goes red on a static import is one keystroke from
|
||
* green if `await import(…)` produces no edge. On the funnel's hot path the
|
||
* deferral moves nothing — the registry loads on the first gated request
|
||
* instead of on the first import — so the edge is reported.
|
||
*/
|
||
it('is reported when a root defers the load of a forbidden module', () => {
|
||
/**
|
||
* Walked from a live chat payload module that defers `@/tools/params`. A root's own
|
||
* deferred edges are checked before its static imports, so the reported chain
|
||
* is that single deferred hop, whatever else the root reaches.
|
||
*/
|
||
const root = 'lib/mothership/chat/payload.ts'
|
||
const violations = findViolations({
|
||
root,
|
||
forbidden: { 'tools/': FORBIDDEN_PREFIXES['tools/'] },
|
||
})
|
||
|
||
expect(violations).toHaveLength(1)
|
||
expect(violations[0].forbidden).toBe('tools/params.ts')
|
||
expect(violations[0].reason).toContain('deferred')
|
||
expect(violations[0].path).toEqual([root, 'tools/params.ts'])
|
||
})
|
||
|
||
/**
|
||
* The other half of the rule, and the reason it is not "walk dynamic imports
|
||
* like static ones": `lib/billing/core/subscription.ts` sits in the funnel's
|
||
* static graph and lazily loads `@/components/emails` on a plan-upgrade
|
||
* webhook — a template that statically imports the workflow graph. Walking
|
||
* past the deferred hop reports a module nothing loads until that webhook
|
||
* fires, which is a false alarm about what an authorization decision costs.
|
||
*/
|
||
it('is not walked through, so a deferred module’s own graph stays out', () => {
|
||
expect(
|
||
findViolations({
|
||
root: 'lib/billing/core/subscription.ts',
|
||
forbidden: { 'lib/workflows/': FORBIDDEN_PREFIXES['lib/workflows/'] },
|
||
})
|
||
).toEqual([])
|
||
})
|
||
})
|