48 lines
3.6 KiB
Python
48 lines
3.6 KiB
Python
# Row 77 round 3 review (Darkwing): sites Rocko's r2/mutants.py doesn't name.
|
|
# Same loop as theirs: each edit alone on <tree>, the service and
|
|
# pinned-copy tests run, the file restored. Usage: python3 -I mine.py <tree>
|
|
import subprocess, shutil, sys
|
|
W=sys.argv[1]
|
|
S='scripts/webui-service.sh'
|
|
ORDER_A=''' bus_on_copy "$COPIES/$COPY_ID"
|
|
# N1: a running unit would take the new ExecStart at its next restart.
|
|
local state
|
|
state="$(running)" || exit 1
|
|
[ -z "$state" ] || die "refusing: $UNIT_NAME is running ($state); Jason or Mos stops it first (systemctl --user stop mosaic-webui), then install, then start it"
|
|
'''
|
|
ORDER_B=''' # N1: a running unit would take the new ExecStart at its next restart.
|
|
local state
|
|
state="$(running)" || exit 1
|
|
[ -z "$state" ] || die "refusing: $UNIT_NAME is running ($state); Jason or Mos stops it first (systemctl --user stop mosaic-webui), then install, then start it"
|
|
bus_on_copy "$COPIES/$COPY_ID"
|
|
'''
|
|
M=[
|
|
('bus checked after the state read', S, ORDER_A, ORDER_B),
|
|
('any copy will do for the bus', S, ' bus_on_copy "$COPIES/$COPY_ID"\n', ' bus_on_copy "$COPIES"\n'),
|
|
('bus check before render', S, ' unit="$(render)" || exit 1\n bus_on_copy "$COPIES/$COPY_ID"\n', ' bus_on_copy "$COPIES/$COPY_ID"\n unit="$(render)" || exit 1\n'),
|
|
('only the first ExecStart path checked', S, "sed 's/^path=//' || true)\"", "sed 's/^path=//' | head -1 || true)\""),
|
|
('a non-bus unit name accepted', S, "awk '$1 ~ /^mosaic-bus@.+\\.service$/ {print $1}'", "awk '{print $1}'"),
|
|
('uninstall takes --copy', S, '[ "$SERVE_SET" = 0 ] && [ "$COPY_FLAGS" = 0 ] && [ "$ALLOW_WORKTREE" = 0 ] || usage\n local target="$UNIT_DIR/$UNIT_NAME"\n # N3', '[ "$SERVE_SET" = 0 ] || usage\n local target="$UNIT_DIR/$UNIT_NAME"\n # N3'),
|
|
('status takes --copy', S, '[ "$SERVE_SET" = 0 ] && [ "$RELOAD" = 1 ] && [ "$COPY_FLAGS" = 0 ] && [ "$ALLOW_WORKTREE" = 0 ] || usage', '[ "$SERVE_SET" = 0 ] && [ "$RELOAD" = 1 ] || usage'),
|
|
('render takes --copies alone', S, '{ [ -n "$COPY_ID" ] || [ "$COPY_FLAGS" = 0 ]; } || usage', 'true || usage'),
|
|
('render takes --allow-worktree', S, '[ "$DIR_FLAGS" = 0 ] && [ "$ALLOW_WORKTREE" = 0 ] || usage\n { [', '[ "$DIR_FLAGS" = 0 ] || usage\n { ['),
|
|
('copies dir may be relative', S, 'case "$COPIES" in /*) ;; *) die', 'case "$COPIES" in *) ;; /*) die'),
|
|
('short copy id accepted', S, '[ "${#COPY_ID}" -eq 40 ] ||', 'true ||'),
|
|
('copy takes --dir', S, '[ "$SERVE_SET" = 0 ] && [ "$DIR_FLAGS" = 0 ] && [ -z "$COPY_ID" ] || usage\n canonical', '[ "$SERVE_SET" = 0 ] && [ -z "$COPY_ID" ] || usage\n canonical'),
|
|
('copy without mv -T fallback check', S, ' [ -e "$target" ] || die "could not rename the copy into $target"\n', ''),
|
|
('dirs 0755', S, '-type d -exec chmod 0555 {} +', '-type d -exec chmod 0755 {} +'),
|
|
('status copy not anchored', S, 'if [[ "$copy" =~ ^[0-9a-f]{40}$ ]]; then', 'if [[ "$copy" =~ [0-9a-f]{40} ]]; then'),
|
|
]
|
|
res=[]
|
|
for name,f,a,b in M:
|
|
p=f'{W}/{f}'; s=open(p).read()
|
|
if s.count(a)!=1: res.append(f'NOMATCH({s.count(a)}) {name}'); continue
|
|
shutil.copy(p,p+'.bak'); open(p,'w').write(s.replace(a,b))
|
|
try:
|
|
r=subprocess.run(['node','--test','tests/service.test.mjs','tests/pinned-copy.test.mjs'],cwd=f'{W}/packages/webui',capture_output=True,text=True,timeout=300,start_new_session=True)
|
|
fails=sorted({l[:110] for l in r.stdout.splitlines() if l.startswith('✖') and 'failing tests' not in l})
|
|
res.append(f"{'KILLED' if r.returncode else 'SURVIVED'} {name}: {len(fails)} failing{' | '+fails[0] if fails else ''}")
|
|
print(res[-1], flush=True)
|
|
finally:
|
|
shutil.move(p+'.bak',p)
|