Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
sim/scripts/check-script-test-coverage.ts at main · simstudioai/sim · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
simstudioai
sim
Repository navigation
Code
Issues
128
(128)
Pull requests
220
(220)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
sim
/
scripts
/
check-script-test-coverage.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
93 lines (84 loc) · 3.71 KB
main
Breadcrumbs
sim
/
scripts
/
check-script-test-coverage.ts
Copy path
Top
File metadata and controls
Code
Blame
93 lines (84 loc) · 3.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env bun
/**
* Asserts every script test is collected by the scripts Vitest config.
*
* The root `test` script once chained a hand-maintained list of `test:*` entries, and a
* hand-maintained list silently drifts from the files on disk: a test added without a matching
* entry never runs, in CI or locally, and nothing reports it. `scripts/check-migrations-safety.test.ts`
* sat unreferenced and green for exactly that reason. `scripts/vitest.config.ts` now collects
* the directory by glob, so drift can only come from a file the glob does not match (a test in a
* subdirectory, a different suffix) or from the test commands no longer running that config.
* This guard checks the command contract and asks Vitest which files it would run.
*
* `run-audits.ts` derives its own list from the `check:*` namespace precisely so a new audit is
* picked up by default, so this guard registers itself simply by being named `check:*` — it cannot
* drift out of the runner it belongs to.
*/
import
{
readdirSync
}
from
'node:fs'
import
path
from
'node:path'
import
{
localBin
}
from
'./local-bin'
const
ROOT
=
path
.
resolve
(
import
.
meta
.
dir
,
'..'
)
const
SUB_SCRIPT_PATTERN
=
/
b
u
n
r
u
n
(
[
\w
:
-
]
+
)
/
g
const
SCRIPTS_TEST_CONFIG
=
'scripts/vitest.config.ts'
const
SCRIPTS_TEST_COMMAND
=
`vitest run --config
${
SCRIPTS_TEST_CONFIG
}
`
const
manifest
=
await
Bun
.
file
(
path
.
join
(
ROOT
,
'package.json'
)
)
.
json
(
)
const
commands
=
manifest
.
scripts
as
Record
<
string
,
string
>
/** Walks the `test` script and every entry it chains. */
function
reachableScripts
(
entry
:
string
)
:
Set
<
string
>
{
const
seen
=
new
Set
<
string
>
(
)
const
queue
=
[
entry
]
while
(
queue
.
length
>
0
)
{
const
name
=
queue
.
pop
(
)
as
string
if
(
seen
.
has
(
name
)
)
continue
seen
.
add
(
name
)
for
(
const
match
of
(
commands
[
name
]
??
''
)
.
matchAll
(
SUB_SCRIPT_PATTERN
)
)
queue
.
push
(
match
[
1
]
)
}
return
seen
}
if
(
!
reachableScripts
(
'test'
)
.
has
(
'test:scripts'
)
)
{
console
.
error
(
'The root `test` script no longer chains `test:scripts`, so no script test runs.'
)
process
.
exit
(
1
)
}
// Keep collection tied to the actual runner; filters or another config can silently skip tests.
if
(
commands
[
'test:scripts'
]
?.
trim
(
)
!==
SCRIPTS_TEST_COMMAND
)
{
console
.
error
(
`test:scripts must run the complete scripts Vitest config:
${
SCRIPTS_TEST_COMMAND
}
`
)
process
.
exit
(
1
)
}
const
listed
=
Bun
.
spawnSync
(
[
localBin
(
'vitest'
)
,
'list'
,
'--json'
,
'--filesOnly'
,
'--config'
,
SCRIPTS_TEST_CONFIG
]
,
{
cwd
:
ROOT
,
}
)
if
(
listed
.
exitCode
!==
0
)
{
console
.
error
(
`\`vitest list\` failed:\n
${
listed
.
stderr
.
toString
(
)
}
`
)
process
.
exit
(
1
)
}
const
collected
=
new
Set
(
(
JSON
.
parse
(
listed
.
stdout
.
toString
(
)
)
as
Array
<
{
file
:
string
}
>
)
.
map
(
(
entry
)
=>
path
.
relative
(
ROOT
,
entry
.
file
)
.
split
(
path
.
sep
)
.
join
(
'/'
)
)
)
/** Inventory independently of the include globs so a narrowed config cannot hide its omissions. */
function
testFiles
(
dir
:
string
)
:
string
[
]
{
return
readdirSync
(
dir
,
{
withFileTypes
:
true
}
)
.
flatMap
(
(
entry
)
=>
{
if
(
[
'node_modules'
,
'.git'
,
'dist'
]
.
includes
(
entry
.
name
)
)
return
[
]
const
file
=
path
.
join
(
dir
,
entry
.
name
)
if
(
entry
.
isDirectory
(
)
)
return
testFiles
(
file
)
return
/
\.
(
t
e
s
t
|
s
p
e
c
)
\.
(?:
[
c
m
]
?
[
j
t
]
s
|
[
j
t
]
s
x
)
$
/
.
test
(
entry
.
name
)
?
[
path
.
relative
(
ROOT
,
file
)
.
split
(
path
.
sep
)
.
join
(
'/'
)
]
:
[
]
}
)
}
const
onDisk
=
testFiles
(
path
.
join
(
ROOT
,
'scripts'
)
)
.
sort
(
)
const
orphaned
=
onDisk
.
filter
(
(
file
)
=>
!
collected
.
has
(
file
)
)
if
(
orphaned
.
length
>
0
)
{
console
.
error
(
`Script tests never run by \`bun run test\`:\n
${
orphaned
.
map
(
(
file
)
=>
` -
${
file
}
`
)
.
join
(
'\n'
)
}
\n`
+
'Make sure the scripts Vitest config collects them.'
)
process
.
exit
(
1
)
}
console
.
log
(
`Script test coverage passed:
${
onDisk
.
length
}
script tests collected by the scripts Vitest config.`
)
You can’t perform that action at this time.