mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-10-21 05:01:26 -07:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be65241cc2
|
||
|
|
7c1c674313
|
||
|
|
01613f1be5 | ||
|
|
bf4e5bb609 | ||
|
|
7909fcd2cf | ||
|
|
8fc20b2499 | ||
|
|
ea2b3a9507 | ||
|
|
a6d96e9966 | ||
|
|
7108e086ba | ||
|
|
78a9b6346f | ||
|
|
78eca52b7e | ||
|
|
b48083ddd8 | ||
|
|
4b6842d034 |
No files matched your search
@@ -27,6 +27,7 @@ Do not use hidden wrapper commands. Verification commands are owned by `package.
|
|||||||
- Launcher or mpv plugin: `bun run test:launcher` or `bun run test:env`, based on the behavior changed
|
- Launcher or mpv plugin: `bun run test:launcher` or `bun run test:env`, based on the behavior changed
|
||||||
- Runtime compatibility or dist-sensitive wiring: `bun run test:runtime:compat`
|
- Runtime compatibility or dist-sensitive wiring: `bun run test:runtime:compat`
|
||||||
- Stats dashboard: `bun run test:stats`
|
- Stats dashboard: `bun run test:stats`
|
||||||
|
- Overlay, renderer, mpv, or mining behavior in the running app: `bun run build`, then `bun run test:e2e`
|
||||||
- Build/release scripts: `bun run test:scripts`
|
- Build/release scripts: `bun run test:scripts`
|
||||||
|
|
||||||
For substantial changes, use the full gate documented in `AGENTS.md` and `docs/workflow/verification.md`.
|
For substantial changes, use the full gate documented in `AGENTS.md` and `docs/workflow/verification.md`.
|
||||||
|
|||||||
@@ -9,3 +9,79 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build-test-audit:
|
build-test-audit:
|
||||||
uses: ./.github/workflows/quality-gate.yml
|
uses: ./.github/workflows/quality-gate.yml
|
||||||
|
|
||||||
|
# Boots the built app with a real mpv on each platform. Kept outside the
|
||||||
|
# reusable quality gate so releases do not depend on it while the lane is new.
|
||||||
|
e2e:
|
||||||
|
name: E2E (${{ matrix.os }})
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
timeout-minutes: 30
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
SUBMINER_E2E_KEEP: '1'
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: 1.3.5
|
||||||
|
|
||||||
|
- name: Point temp files at an uploadable directory
|
||||||
|
run: |
|
||||||
|
# os.tmpdir() follows these, so the kept session logs land under runner.temp.
|
||||||
|
dir="$RUNNER_TEMP/e2e"
|
||||||
|
mkdir -p "$dir"
|
||||||
|
{ echo "TMPDIR=$dir"; echo "TEMP=$dir"; echo "TMP=$dir"; } >> "$GITHUB_ENV"
|
||||||
|
|
||||||
|
- name: Install mpv and ffmpeg (Linux)
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
run: |
|
||||||
|
# Only Ubuntu sources are needed; unrelated runner repositories can be unavailable.
|
||||||
|
apt_sources=(-o Dir::Etc::sourcelist=sources.list.d/ubuntu.sources -o Dir::Etc::sourceparts=-)
|
||||||
|
sudo apt-get "${apt_sources[@]}" update
|
||||||
|
sudo apt-get "${apt_sources[@]}" install -y mpv ffmpeg xvfb
|
||||||
|
|
||||||
|
- name: Install mpv and ffmpeg (macOS)
|
||||||
|
if: runner.os == 'macOS'
|
||||||
|
run: brew install mpv ffmpeg
|
||||||
|
|
||||||
|
- name: Install mpv and ffmpeg (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
run: |
|
||||||
|
choco install mpv ffmpeg -y --no-progress
|
||||||
|
# The mpv package adds no shim, so put its directory on PATH for later steps.
|
||||||
|
mpv_exe="$(find /c/ProgramData/chocolatey/lib /c/ProgramData/chocolatey/bin "/c/Program Files" /c/tools -maxdepth 6 -iname mpv.exe 2>/dev/null | head -n 1)"
|
||||||
|
test -n "$mpv_exe"
|
||||||
|
cygpath -w "$(dirname "$mpv_exe")" >> "$GITHUB_PATH"
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
bun install --frozen-lockfile
|
||||||
|
cd stats && bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: bun run build
|
||||||
|
|
||||||
|
- name: End-to-end suite
|
||||||
|
run: bun run test:e2e
|
||||||
|
|
||||||
|
- name: Upload session logs (on failure)
|
||||||
|
if: failure()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: e2e-logs-${{ matrix.os }}
|
||||||
|
path: ${{ runner.temp }}/e2e/subminer-e2e-*/*.log
|
||||||
|
if-no-files-found: ignore
|
||||||
@@ -8,6 +8,7 @@ Start here, then leave this file.
|
|||||||
- Architecture map: [`docs/architecture/README.md`](./docs/architecture/README.md)
|
- Architecture map: [`docs/architecture/README.md`](./docs/architecture/README.md)
|
||||||
- Workflow map: [`docs/workflow/README.md`](./docs/workflow/README.md)
|
- Workflow map: [`docs/workflow/README.md`](./docs/workflow/README.md)
|
||||||
- Verification lanes: [`docs/workflow/verification.md`](./docs/workflow/verification.md)
|
- Verification lanes: [`docs/workflow/verification.md`](./docs/workflow/verification.md)
|
||||||
|
- Testing guidelines: [`docs/workflow/testing.md`](./docs/workflow/testing.md)
|
||||||
- Knowledge-base rules: [`docs/knowledge-base/README.md`](./docs/knowledge-base/README.md)
|
- Knowledge-base rules: [`docs/knowledge-base/README.md`](./docs/knowledge-base/README.md)
|
||||||
- Release guide: [`docs/RELEASING.md`](./docs/RELEASING.md)
|
- Release guide: [`docs/RELEASING.md`](./docs/RELEASING.md)
|
||||||
|
|
||||||
@@ -44,10 +45,11 @@ Start here, then leave this file.
|
|||||||
- Launcher/plugin: `bun run test:launcher` or `bun run test:env`
|
- Launcher/plugin: `bun run test:launcher` or `bun run test:env`
|
||||||
- Runtime-compat / dist-sensitive: `bun run test:runtime:compat`
|
- Runtime-compat / dist-sensitive: `bun run test:runtime:compat`
|
||||||
- Stats dashboard UI (`stats/`): `bun run test:stats`
|
- Stats dashboard UI (`stats/`): `bun run test:stats`
|
||||||
|
- Overlay / renderer / mpv / mining behavior in the running app: `bun run build`, then `bun run test:e2e` (headless, sandboxed; `bun run e2e start` for exploratory checks)
|
||||||
- Build/release scripts (`scripts/**`): `bun run test:scripts`
|
- Build/release scripts (`scripts/**`): `bun run test:scripts`
|
||||||
- Internal docs, `AGENTS.md`, or repo skills: `bun run test:docs:kb`
|
- Internal docs, `AGENTS.md`, or repo skills: `bun run test:docs:kb`
|
||||||
- User-facing `docs-site/`: `bun run docs:test`, then `bun run docs:build`
|
- User-facing `docs-site/`: `bun run docs:test`, then `bun run docs:build`
|
||||||
- macOS mpv window helper: `bun test scripts/get-mpv-window-macos.test.ts`
|
- macOS mpv window helper (`scripts/get-mpv-window-macos.swift`): compile it on macOS with `bun run build`
|
||||||
- Test lanes are directory-discovered via `scripts/test-lanes.ts`; never hand-list test files in `package.json`
|
- Test lanes are directory-discovered via `scripts/test-lanes.ts`; never hand-list test files in `package.json`
|
||||||
|
|
||||||
## Docs Upkeep
|
## Docs Upkeep
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ The AppImage is all you need. First-run setup can install the optional `subminer
|
|||||||
|
|
||||||
Download the latest DMG from [GitHub Releases](https://github.com/ksyasuda/SubMiner/releases/latest) and drag `SubMiner.app` into `/Applications`.
|
Download the latest DMG from [GitHub Releases](https://github.com/ksyasuda/SubMiner/releases/latest) and drag `SubMiner.app` into `/Applications`.
|
||||||
|
|
||||||
Then enable SubMiner under **System Settings > Privacy & Security > Accessibility**, or the overlay cannot follow the mpv window. If macOS blocks the first launch, right-click the app and choose **Open**.
|
Then enable SubMiner under **System Settings > Privacy & Security > Accessibility** (named **Device Control and Data Access** on macOS 27), or the overlay cannot follow the mpv window. If macOS blocks the first launch, right-click the app and choose **Open**.
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "subminer",
|
"name": "subminer",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource-variable/geist": "^5.2.8",
|
|
||||||
"@fontsource-variable/geist-mono": "^5.2.7",
|
|
||||||
"@xhayper/discord-rpc": "^1.3.4",
|
"@xhayper/discord-rpc": "^1.3.4",
|
||||||
"axios": "^1.20.0",
|
"axios": "^1.20.0",
|
||||||
"commander": "^14.0.3",
|
"commander": "^14.0.3",
|
||||||
@@ -24,7 +22,6 @@
|
|||||||
"electron": "43.7.7",
|
"electron": "43.7.7",
|
||||||
"electron-builder": "26.16.1",
|
"electron-builder": "26.16.1",
|
||||||
"esbuild": "^0.25.12",
|
"esbuild": "^0.25.12",
|
||||||
"eslint": "^10.8.0",
|
|
||||||
"prettier": "^3.8.1",
|
"prettier": "^3.8.1",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"undici": "7.29.1",
|
"undici": "7.29.1",
|
||||||
@@ -40,6 +37,7 @@
|
|||||||
"brace-expansion": "5.0.11",
|
"brace-expansion": "5.0.11",
|
||||||
"electron-builder-squirrel-windows": "26.16.1",
|
"electron-builder-squirrel-windows": "26.16.1",
|
||||||
"fast-uri": "3.1.7",
|
"fast-uri": "3.1.7",
|
||||||
|
"follow-redirects": "1.16.1",
|
||||||
"form-data": "4.0.6",
|
"form-data": "4.0.6",
|
||||||
"ip-address": "10.2.0",
|
"ip-address": "10.2.0",
|
||||||
"js-yaml": "4.3.2",
|
"js-yaml": "4.3.2",
|
||||||
@@ -127,34 +125,6 @@
|
|||||||
|
|
||||||
"@esbuild/win32-x64": ["@esbuild/win32-x64@0.25.12", "", { "os": "win32", "cpu": "x64" }, "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA=="],
|
"@esbuild/win32-x64": ["@esbuild/win32-x64@0.25.12", "", { "os": "win32", "cpu": "x64" }, "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA=="],
|
||||||
|
|
||||||
"@eslint-community/eslint-utils": ["@eslint-community/eslint-utils@4.9.1", "", { "dependencies": { "eslint-visitor-keys": "^3.4.3" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "sha512-phrYmNiYppR7znFEdqgfWHXR6NCkZEK7hwWDHZUjit/2/U0r6XvkDl0SYnoM51Hq7FhCGdLDT6zxCCOY1hexsQ=="],
|
|
||||||
|
|
||||||
"@eslint-community/regexpp": ["@eslint-community/regexpp@4.12.2", "", {}, "sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew=="],
|
|
||||||
|
|
||||||
"@eslint/config-array": ["@eslint/config-array@0.23.5", "", { "dependencies": { "@eslint/object-schema": "^3.0.5", "debug": "^4.3.1", "minimatch": "^10.2.4" } }, "sha512-Y3kKLvC1dvTOT+oGlqNQ1XLqK6D1HU2YXPc52NmAlJZbMMWDzGYXMiPRJ8TYD39muD/OTjlZmNJ4ib7dvSrMBA=="],
|
|
||||||
|
|
||||||
"@eslint/config-helpers": ["@eslint/config-helpers@0.7.0", "", { "dependencies": { "@eslint/core": "^1.2.1" } }, "sha512-DObd/KKUsU+FaFv4PLxSRenpXfQWmPXXP3pPZ6/K1PCrMu2vQpMDMuQe/BqYeoLcz8ro0bVDF1RxOJgfVEdhUw=="],
|
|
||||||
|
|
||||||
"@eslint/core": ["@eslint/core@1.2.1", "", { "dependencies": { "@types/json-schema": "^7.0.15" } }, "sha512-MwcE1P+AZ4C6DWlpin/OmOA54mmIZ/+xZuJiQd4SyB29oAJjN30UW9wkKNptW2ctp4cEsvhlLY/CsQ1uoHDloQ=="],
|
|
||||||
|
|
||||||
"@eslint/object-schema": ["@eslint/object-schema@3.0.5", "", {}, "sha512-vqTaUEgxzm+YDSdElad6PiRoX4t8VGDjCtt05zn4nU810UIx/uNEV7/lZJ6KwFThKZOzOxzXy48da+No7HZaMw=="],
|
|
||||||
|
|
||||||
"@eslint/plugin-kit": ["@eslint/plugin-kit@0.7.2", "", { "dependencies": { "@eslint/core": "^1.2.1", "levn": "^0.4.1" } }, "sha512-+CNAzxglkrpNf/kKywqQfk74QjtceuOE7Qm+AF8miRvPF/wmmK5+OJOgVh3AVTT3RP2mH3+FOaxlE5v72owk0A=="],
|
|
||||||
|
|
||||||
"@fontsource-variable/geist": ["@fontsource-variable/geist@5.2.8", "", {}, "sha512-cJ6m9e+8MQ5dCYJsLylfZrgBh6KkG4bOLckB35Tr9J/EqdkEM6QllH5PxqP1dhTvFup+HtMRPuz9xOjxXJggxw=="],
|
|
||||||
|
|
||||||
"@fontsource-variable/geist-mono": ["@fontsource-variable/geist-mono@5.2.7", "", {}, "sha512-ZKlZ5sjtalb2TwXKs400mAGDlt/+2ENLNySPx0wTz3bP3mWARCsUW+rpxzZc7e05d2qGch70pItt3K4qttbIYA=="],
|
|
||||||
|
|
||||||
"@humanfs/core": ["@humanfs/core@0.19.2", "", { "dependencies": { "@humanfs/types": "^0.15.0" } }, "sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA=="],
|
|
||||||
|
|
||||||
"@humanfs/node": ["@humanfs/node@0.16.8", "", { "dependencies": { "@humanfs/core": "^0.19.2", "@humanfs/types": "^0.15.0", "@humanwhocodes/retry": "^0.4.0" } }, "sha512-gE1eQNZ3R++kTzFUpdGlpmy8kDZD/MLyHqDwqjkVQI0JMdI1D51sy1H958PNXYkM2rAac7e5/CnIKZrHtPh3BQ=="],
|
|
||||||
|
|
||||||
"@humanfs/types": ["@humanfs/types@0.15.0", "", {}, "sha512-ZZ1w0aoQkwuUuC7Yf+7sdeaNfqQiiLcSRbfI08oAxqLtpXQr9AIVX7Ay7HLDuiLYAaFPu8oBYNq/QIi9URHJ3Q=="],
|
|
||||||
|
|
||||||
"@humanwhocodes/module-importer": ["@humanwhocodes/module-importer@1.0.1", "", {}, "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA=="],
|
|
||||||
|
|
||||||
"@humanwhocodes/retry": ["@humanwhocodes/retry@0.4.3", "", {}, "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ=="],
|
|
||||||
|
|
||||||
"@isaacs/fs-minipass": ["@isaacs/fs-minipass@4.0.1", "", { "dependencies": { "minipass": "^7.0.4" } }, "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w=="],
|
"@isaacs/fs-minipass": ["@isaacs/fs-minipass@4.0.1", "", { "dependencies": { "minipass": "^7.0.4" } }, "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w=="],
|
||||||
|
|
||||||
"@libsql/darwin-arm64": ["@libsql/darwin-arm64@0.5.28", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Lc/b8JXO2W2+H+5UXfw7PCHZCim1jlrB0CmLPsjfVmihMluBpdYafFImhjAHxHlWGfuZ32WzjVPUap5fGmkthw=="],
|
"@libsql/darwin-arm64": ["@libsql/darwin-arm64@0.5.28", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Lc/b8JXO2W2+H+5UXfw7PCHZCim1jlrB0CmLPsjfVmihMluBpdYafFImhjAHxHlWGfuZ32WzjVPUap5fGmkthw=="],
|
||||||
@@ -203,16 +173,10 @@
|
|||||||
|
|
||||||
"@types/debug": ["@types/debug@4.1.13", "", { "dependencies": { "@types/ms": "*" } }, "sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw=="],
|
"@types/debug": ["@types/debug@4.1.13", "", { "dependencies": { "@types/ms": "*" } }, "sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw=="],
|
||||||
|
|
||||||
"@types/esrecurse": ["@types/esrecurse@4.3.1", "", {}, "sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw=="],
|
|
||||||
|
|
||||||
"@types/estree": ["@types/estree@1.0.9", "", {}, "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg=="],
|
|
||||||
|
|
||||||
"@types/fs-extra": ["@types/fs-extra@9.0.13", "", { "dependencies": { "@types/node": "*" } }, "sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA=="],
|
"@types/fs-extra": ["@types/fs-extra@9.0.13", "", { "dependencies": { "@types/node": "*" } }, "sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA=="],
|
||||||
|
|
||||||
"@types/http-cache-semantics": ["@types/http-cache-semantics@4.2.0", "", {}, "sha512-L3LgimLHXtGkWikKnsPg0/VFx9OGZaC+eN1u4r+OB1XRqH3meBIAVC2zr1WdMH+RHmnRkqliQAOHNJ/E0j/e0Q=="],
|
"@types/http-cache-semantics": ["@types/http-cache-semantics@4.2.0", "", {}, "sha512-L3LgimLHXtGkWikKnsPg0/VFx9OGZaC+eN1u4r+OB1XRqH3meBIAVC2zr1WdMH+RHmnRkqliQAOHNJ/E0j/e0Q=="],
|
||||||
|
|
||||||
"@types/json-schema": ["@types/json-schema@7.0.15", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
|
|
||||||
|
|
||||||
"@types/keyv": ["@types/keyv@3.1.4", "", { "dependencies": { "@types/node": "*" } }, "sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg=="],
|
"@types/keyv": ["@types/keyv@3.1.4", "", { "dependencies": { "@types/node": "*" } }, "sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg=="],
|
||||||
|
|
||||||
"@types/ms": ["@types/ms@2.1.0", "", {}, "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="],
|
"@types/ms": ["@types/ms@2.1.0", "", {}, "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="],
|
||||||
@@ -231,13 +195,9 @@
|
|||||||
|
|
||||||
"abbrev": ["abbrev@4.0.0", "", {}, "sha512-a1wflyaL0tHtJSmLSOVybYhy22vRih4eduhhrkcjgrWGnRfrZtovJ2FRjxuTtkkj47O/baf0R86QU5OuYpz8fA=="],
|
"abbrev": ["abbrev@4.0.0", "", {}, "sha512-a1wflyaL0tHtJSmLSOVybYhy22vRih4eduhhrkcjgrWGnRfrZtovJ2FRjxuTtkkj47O/baf0R86QU5OuYpz8fA=="],
|
||||||
|
|
||||||
"acorn": ["acorn@8.16.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw=="],
|
|
||||||
|
|
||||||
"acorn-jsx": ["acorn-jsx@5.3.2", "", { "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ=="],
|
|
||||||
|
|
||||||
"agent-base": ["agent-base@6.0.2", "", { "dependencies": { "debug": "4" } }, "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ=="],
|
"agent-base": ["agent-base@6.0.2", "", { "dependencies": { "debug": "4" } }, "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ=="],
|
||||||
|
|
||||||
"ajv": ["ajv@6.14.0", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw=="],
|
"ajv": ["ajv@8.20.0", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA=="],
|
||||||
|
|
||||||
"ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="],
|
"ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="],
|
||||||
|
|
||||||
@@ -317,8 +277,6 @@
|
|||||||
|
|
||||||
"decompress-response": ["decompress-response@6.0.0", "", { "dependencies": { "mimic-response": "^3.1.0" } }, "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ=="],
|
"decompress-response": ["decompress-response@6.0.0", "", { "dependencies": { "mimic-response": "^3.1.0" } }, "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ=="],
|
||||||
|
|
||||||
"deep-is": ["deep-is@0.1.4", "", {}, "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ=="],
|
|
||||||
|
|
||||||
"defer-to-connect": ["defer-to-connect@2.0.1", "", {}, "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg=="],
|
"defer-to-connect": ["defer-to-connect@2.0.1", "", {}, "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg=="],
|
||||||
|
|
||||||
"define-data-property": ["define-data-property@1.1.4", "", { "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", "gopd": "^1.0.1" } }, "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A=="],
|
"define-data-property": ["define-data-property@1.1.4", "", { "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", "gopd": "^1.0.1" } }, "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A=="],
|
||||||
@@ -383,45 +341,17 @@
|
|||||||
|
|
||||||
"escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="],
|
"escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="],
|
||||||
|
|
||||||
"eslint": ["eslint@10.8.0", "", { "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", "@eslint/config-array": "^0.23.5", "@eslint/config-helpers": "^0.7.0", "@eslint/core": "^1.2.1", "@eslint/plugin-kit": "^0.7.2", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "ajv": "^6.14.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^9.1.2", "eslint-visitor-keys": "^5.0.1", "espree": "^11.2.0", "esquery": "^1.7.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "minimatch": "^10.2.5", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "peerDependencies": { "jiti": "*" }, "optionalPeers": ["jiti"], "bin": { "eslint": "bin/eslint.js" } }, "sha512-nuKKvN+oIBO0koN7Tm7dlkmnkc21mtt0QJLwAKzjLq14y6lRTdVG36MZHJ8eQHwdJMwZbQNMlPOYedMq/oVJvQ=="],
|
|
||||||
|
|
||||||
"eslint-scope": ["eslint-scope@9.1.2", "", { "dependencies": { "@types/esrecurse": "^4.3.1", "@types/estree": "^1.0.8", "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "sha512-xS90H51cKw0jltxmvmHy2Iai1LIqrfbw57b79w/J7MfvDfkIkFZ+kj6zC3BjtUwh150HsSSdxXZcsuv72miDFQ=="],
|
|
||||||
|
|
||||||
"eslint-visitor-keys": ["eslint-visitor-keys@5.0.1", "", {}, "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA=="],
|
|
||||||
|
|
||||||
"espree": ["espree@11.2.0", "", { "dependencies": { "acorn": "^8.16.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^5.0.1" } }, "sha512-7p3DrVEIopW1B1avAGLuCSh1jubc01H2JHc8B4qqGblmg5gI9yumBgACjWo4JlIc04ufug4xJ3SQI8HkS/Rgzw=="],
|
|
||||||
|
|
||||||
"esquery": ["esquery@1.7.0", "", { "dependencies": { "estraverse": "^5.1.0" } }, "sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g=="],
|
|
||||||
|
|
||||||
"esrecurse": ["esrecurse@4.3.0", "", { "dependencies": { "estraverse": "^5.2.0" } }, "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag=="],
|
|
||||||
|
|
||||||
"estraverse": ["estraverse@5.3.0", "", {}, "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA=="],
|
|
||||||
|
|
||||||
"esutils": ["esutils@2.0.3", "", {}, "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="],
|
|
||||||
|
|
||||||
"exponential-backoff": ["exponential-backoff@3.1.3", "", {}, "sha512-ZgEeZXj30q+I0EN+CbSSpIyPaJ5HVQD18Z1m+u1FXbAeT94mr1zw50q4q6jiiC447Nl/YTcIYSAftiGqetwXCA=="],
|
"exponential-backoff": ["exponential-backoff@3.1.3", "", {}, "sha512-ZgEeZXj30q+I0EN+CbSSpIyPaJ5HVQD18Z1m+u1FXbAeT94mr1zw50q4q6jiiC447Nl/YTcIYSAftiGqetwXCA=="],
|
||||||
|
|
||||||
"fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="],
|
"fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="],
|
||||||
|
|
||||||
"fast-json-stable-stringify": ["fast-json-stable-stringify@2.1.0", "", {}, "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="],
|
|
||||||
|
|
||||||
"fast-levenshtein": ["fast-levenshtein@2.0.6", "", {}, "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw=="],
|
|
||||||
|
|
||||||
"fast-uri": ["fast-uri@3.1.7", "", {}, "sha512-dOvZVzjdZdz7phd9v6jCbwxrBW3fK6n8Rc0CtdmM4bumzMnxywBYhuph6J819RRw/ku+rLbelwfMunktuzVVHg=="],
|
"fast-uri": ["fast-uri@3.1.7", "", {}, "sha512-dOvZVzjdZdz7phd9v6jCbwxrBW3fK6n8Rc0CtdmM4bumzMnxywBYhuph6J819RRw/ku+rLbelwfMunktuzVVHg=="],
|
||||||
|
|
||||||
"fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="],
|
"fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="],
|
||||||
|
|
||||||
"file-entry-cache": ["file-entry-cache@8.0.0", "", { "dependencies": { "flat-cache": "^4.0.0" } }, "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ=="],
|
|
||||||
|
|
||||||
"filelist": ["filelist@1.0.6", "", { "dependencies": { "minimatch": "^5.0.1" } }, "sha512-5giy2PkLYY1cP39p17Ech+2xlpTRL9HLspOfEgm0L6CwBXBTgsK5ou0JtzYuepxkaQ/tvhCFIJ5uXo0OrM2DxA=="],
|
"filelist": ["filelist@1.0.6", "", { "dependencies": { "minimatch": "^5.0.1" } }, "sha512-5giy2PkLYY1cP39p17Ech+2xlpTRL9HLspOfEgm0L6CwBXBTgsK5ou0JtzYuepxkaQ/tvhCFIJ5uXo0OrM2DxA=="],
|
||||||
|
|
||||||
"find-up": ["find-up@5.0.0", "", { "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" } }, "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng=="],
|
"follow-redirects": ["follow-redirects@1.16.1", "", {}, "sha512-FNvFGzoMLWmE6Yj9spb/zjd7yiNCHiAW9/Tg9CXrQ8wuu32HtlJOwWO11OJafl5FfY3DxTdQ0vj42zU1kvv5jg=="],
|
||||||
|
|
||||||
"flat-cache": ["flat-cache@4.0.1", "", { "dependencies": { "flatted": "^3.2.9", "keyv": "^4.5.4" } }, "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw=="],
|
|
||||||
|
|
||||||
"flatted": ["flatted@3.4.2", "", {}, "sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA=="],
|
|
||||||
|
|
||||||
"follow-redirects": ["follow-redirects@1.16.0", "", {}, "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw=="],
|
|
||||||
|
|
||||||
"form-data": ["form-data@4.0.6", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.4", "mime-types": "^2.1.35" } }, "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ=="],
|
"form-data": ["form-data@4.0.6", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.4", "mime-types": "^2.1.35" } }, "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ=="],
|
||||||
|
|
||||||
@@ -441,8 +371,6 @@
|
|||||||
|
|
||||||
"glob": ["glob@7.2.3", "", { "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } }, "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q=="],
|
"glob": ["glob@7.2.3", "", { "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" } }, "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q=="],
|
||||||
|
|
||||||
"glob-parent": ["glob-parent@6.0.2", "", { "dependencies": { "is-glob": "^4.0.3" } }, "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A=="],
|
|
||||||
|
|
||||||
"global-agent": ["global-agent@3.0.0", "", { "dependencies": { "boolean": "^3.0.1", "es6-error": "^4.1.1", "matcher": "^3.0.0", "roarr": "^2.15.3", "semver": "^7.3.2", "serialize-error": "^7.0.1" } }, "sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q=="],
|
"global-agent": ["global-agent@3.0.0", "", { "dependencies": { "boolean": "^3.0.1", "es6-error": "^4.1.1", "matcher": "^3.0.0", "roarr": "^2.15.3", "semver": "^7.3.2", "serialize-error": "^7.0.1" } }, "sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q=="],
|
||||||
|
|
||||||
"globalthis": ["globalthis@1.0.4", "", { "dependencies": { "define-properties": "^1.2.1", "gopd": "^1.0.1" } }, "sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ=="],
|
"globalthis": ["globalthis@1.0.4", "", { "dependencies": { "define-properties": "^1.2.1", "gopd": "^1.0.1" } }, "sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ=="],
|
||||||
@@ -475,20 +403,12 @@
|
|||||||
|
|
||||||
"https-proxy-agent": ["https-proxy-agent@5.0.1", "", { "dependencies": { "agent-base": "6", "debug": "4" } }, "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA=="],
|
"https-proxy-agent": ["https-proxy-agent@5.0.1", "", { "dependencies": { "agent-base": "6", "debug": "4" } }, "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA=="],
|
||||||
|
|
||||||
"ignore": ["ignore@5.3.2", "", {}, "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g=="],
|
|
||||||
|
|
||||||
"imurmurhash": ["imurmurhash@0.1.4", "", {}, "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA=="],
|
|
||||||
|
|
||||||
"inflight": ["inflight@1.0.6", "", { "dependencies": { "once": "^1.3.0", "wrappy": "1" } }, "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA=="],
|
"inflight": ["inflight@1.0.6", "", { "dependencies": { "once": "^1.3.0", "wrappy": "1" } }, "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA=="],
|
||||||
|
|
||||||
"inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="],
|
"inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="],
|
||||||
|
|
||||||
"is-extglob": ["is-extglob@2.1.1", "", {}, "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ=="],
|
|
||||||
|
|
||||||
"is-fullwidth-code-point": ["is-fullwidth-code-point@3.0.0", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="],
|
"is-fullwidth-code-point": ["is-fullwidth-code-point@3.0.0", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="],
|
||||||
|
|
||||||
"is-glob": ["is-glob@4.0.3", "", { "dependencies": { "is-extglob": "^2.1.1" } }, "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg=="],
|
|
||||||
|
|
||||||
"isarray": ["isarray@1.0.0", "", {}, "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="],
|
"isarray": ["isarray@1.0.0", "", {}, "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="],
|
||||||
|
|
||||||
"isbinaryfile": ["isbinaryfile@5.0.7", "", {}, "sha512-gnWD14Jh3FzS3CPhF0AxNOJ8CxqeblPTADzI38r0wt8ZyQl5edpy75myt08EG2oKvpyiqSqsx+Wkz9vtkbTqYQ=="],
|
"isbinaryfile": ["isbinaryfile@5.0.7", "", {}, "sha512-gnWD14Jh3FzS3CPhF0AxNOJ8CxqeblPTADzI38r0wt8ZyQl5edpy75myt08EG2oKvpyiqSqsx+Wkz9vtkbTqYQ=="],
|
||||||
@@ -503,9 +423,7 @@
|
|||||||
|
|
||||||
"json-buffer": ["json-buffer@3.0.1", "", {}, "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="],
|
"json-buffer": ["json-buffer@3.0.1", "", {}, "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="],
|
||||||
|
|
||||||
"json-schema-traverse": ["json-schema-traverse@0.4.1", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],
|
"json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="],
|
||||||
|
|
||||||
"json-stable-stringify-without-jsonify": ["json-stable-stringify-without-jsonify@1.0.1", "", {}, "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw=="],
|
|
||||||
|
|
||||||
"json-stringify-safe": ["json-stringify-safe@5.0.1", "", {}, "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA=="],
|
"json-stringify-safe": ["json-stringify-safe@5.0.1", "", {}, "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA=="],
|
||||||
|
|
||||||
@@ -521,12 +439,8 @@
|
|||||||
|
|
||||||
"lazy-val": ["lazy-val@1.0.5", "", {}, "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q=="],
|
"lazy-val": ["lazy-val@1.0.5", "", {}, "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q=="],
|
||||||
|
|
||||||
"levn": ["levn@0.4.1", "", { "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" } }, "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ=="],
|
|
||||||
|
|
||||||
"libsql": ["libsql@0.5.28", "", { "dependencies": { "@neon-rs/load": "^0.0.4", "detect-libc": "2.0.2" }, "optionalDependencies": { "@libsql/darwin-arm64": "0.5.28", "@libsql/darwin-x64": "0.5.28", "@libsql/linux-arm-gnueabihf": "0.5.28", "@libsql/linux-arm-musleabihf": "0.5.28", "@libsql/linux-arm64-gnu": "0.5.28", "@libsql/linux-arm64-musl": "0.5.28", "@libsql/linux-x64-gnu": "0.5.28", "@libsql/linux-x64-musl": "0.5.28", "@libsql/win32-x64-msvc": "0.5.28" }, "os": [ "linux", "win32", "darwin", ], "cpu": [ "arm", "x64", "arm64", ] }, "sha512-wKqx9FgtPcKHdPfR/Kfm0gejsnbuf8zV+ESPmltFvsq5uXwdeN9fsWn611DmqrdXj1e94NkARcMA2f1syiAqOg=="],
|
"libsql": ["libsql@0.5.28", "", { "dependencies": { "@neon-rs/load": "^0.0.4", "detect-libc": "2.0.2" }, "optionalDependencies": { "@libsql/darwin-arm64": "0.5.28", "@libsql/darwin-x64": "0.5.28", "@libsql/linux-arm-gnueabihf": "0.5.28", "@libsql/linux-arm-musleabihf": "0.5.28", "@libsql/linux-arm64-gnu": "0.5.28", "@libsql/linux-arm64-musl": "0.5.28", "@libsql/linux-x64-gnu": "0.5.28", "@libsql/linux-x64-musl": "0.5.28", "@libsql/win32-x64-msvc": "0.5.28" }, "os": [ "linux", "win32", "darwin", ], "cpu": [ "arm", "x64", "arm64", ] }, "sha512-wKqx9FgtPcKHdPfR/Kfm0gejsnbuf8zV+ESPmltFvsq5uXwdeN9fsWn611DmqrdXj1e94NkARcMA2f1syiAqOg=="],
|
||||||
|
|
||||||
"locate-path": ["locate-path@6.0.0", "", { "dependencies": { "p-locate": "^5.0.0" } }, "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw=="],
|
|
||||||
|
|
||||||
"lodash": ["lodash@4.18.0", "", {}, "sha512-l1mfj2atMqndAHI3ls7XqPxEjV2J9ZkcNyHpoZA3r2T1LLwDB69jgkMWh71YKwhBbK0G2f4WSn05ahmQXVxupA=="],
|
"lodash": ["lodash@4.18.0", "", {}, "sha512-l1mfj2atMqndAHI3ls7XqPxEjV2J9ZkcNyHpoZA3r2T1LLwDB69jgkMWh71YKwhBbK0G2f4WSn05ahmQXVxupA=="],
|
||||||
|
|
||||||
"lodash.escaperegexp": ["lodash.escaperegexp@4.1.2", "", {}, "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw=="],
|
"lodash.escaperegexp": ["lodash.escaperegexp@4.1.2", "", {}, "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw=="],
|
||||||
@@ -563,8 +477,6 @@
|
|||||||
|
|
||||||
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
||||||
|
|
||||||
"natural-compare": ["natural-compare@1.4.0", "", {}, "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw=="],
|
|
||||||
|
|
||||||
"node-abi": ["node-abi@4.28.0", "", { "dependencies": { "semver": "^7.6.3" } }, "sha512-Qfp5XZL1cJDOabOT8H5gnqMTmM4NjvYzHp4I/Kt/Sl76OVkOBBHRFlPspGV0hYvMoqQsypFjT/Yp7Km0beXW9g=="],
|
"node-abi": ["node-abi@4.28.0", "", { "dependencies": { "semver": "^7.6.3" } }, "sha512-Qfp5XZL1cJDOabOT8H5gnqMTmM4NjvYzHp4I/Kt/Sl76OVkOBBHRFlPspGV0hYvMoqQsypFjT/Yp7Km0beXW9g=="],
|
||||||
|
|
||||||
"node-api-version": ["node-api-version@0.2.1", "", { "dependencies": { "semver": "^7.3.5" } }, "sha512-2xP/IGGMmmSQpI1+O/k72jF/ykvZ89JeuKX3TLJAYPDVLUalrshrLHkeVcCCZqG/eEa635cr8IBYzgnDvM2O8Q=="],
|
"node-api-version": ["node-api-version@0.2.1", "", { "dependencies": { "semver": "^7.3.5" } }, "sha512-2xP/IGGMmmSQpI1+O/k72jF/ykvZ89JeuKX3TLJAYPDVLUalrshrLHkeVcCCZqG/eEa635cr8IBYzgnDvM2O8Q=="],
|
||||||
@@ -581,16 +493,10 @@
|
|||||||
|
|
||||||
"once": ["once@1.4.0", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="],
|
"once": ["once@1.4.0", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="],
|
||||||
|
|
||||||
"optionator": ["optionator@0.9.4", "", { "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", "word-wrap": "^1.2.5" } }, "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g=="],
|
|
||||||
|
|
||||||
"p-cancelable": ["p-cancelable@2.1.1", "", {}, "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg=="],
|
"p-cancelable": ["p-cancelable@2.1.1", "", {}, "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg=="],
|
||||||
|
|
||||||
"p-limit": ["p-limit@3.1.0", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="],
|
"p-limit": ["p-limit@3.1.0", "", { "dependencies": { "yocto-queue": "^0.1.0" } }, "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ=="],
|
||||||
|
|
||||||
"p-locate": ["p-locate@5.0.0", "", { "dependencies": { "p-limit": "^3.0.2" } }, "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw=="],
|
|
||||||
|
|
||||||
"path-exists": ["path-exists@4.0.0", "", {}, "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w=="],
|
|
||||||
|
|
||||||
"path-is-absolute": ["path-is-absolute@1.0.1", "", {}, "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg=="],
|
"path-is-absolute": ["path-is-absolute@1.0.1", "", {}, "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg=="],
|
||||||
|
|
||||||
"path-key": ["path-key@3.1.1", "", {}, "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="],
|
"path-key": ["path-key@3.1.1", "", {}, "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q=="],
|
||||||
@@ -607,8 +513,6 @@
|
|||||||
|
|
||||||
"postject": ["postject@1.0.0-alpha.6", "", { "dependencies": { "commander": "^9.4.0" }, "bin": { "postject": "dist/cli.js" } }, "sha512-b9Eb8h2eVqNE8edvKdwqkrY6O7kAwmI8kcnBv1NScolYJbo59XUF0noFq+lxbC1yN20bmC0WBEbDC5H/7ASb0A=="],
|
"postject": ["postject@1.0.0-alpha.6", "", { "dependencies": { "commander": "^9.4.0" }, "bin": { "postject": "dist/cli.js" } }, "sha512-b9Eb8h2eVqNE8edvKdwqkrY6O7kAwmI8kcnBv1NScolYJbo59XUF0noFq+lxbC1yN20bmC0WBEbDC5H/7ASb0A=="],
|
||||||
|
|
||||||
"prelude-ls": ["prelude-ls@1.2.1", "", {}, "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g=="],
|
|
||||||
|
|
||||||
"prettier": ["prettier@3.8.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg=="],
|
"prettier": ["prettier@3.8.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg=="],
|
||||||
|
|
||||||
"proc-log": ["proc-log@6.1.0", "", {}, "sha512-iG+GYldRf2BQ0UDUAd6JQ/RwzaQy6mXmsk/IzlYyal4A4SNFw54MeH4/tLkF4I5WoWG9SQwuqWzS99jaFQHBuQ=="],
|
"proc-log": ["proc-log@6.1.0", "", {}, "sha512-iG+GYldRf2BQ0UDUAd6JQ/RwzaQy6mXmsk/IzlYyal4A4SNFw54MeH4/tLkF4I5WoWG9SQwuqWzS99jaFQHBuQ=="],
|
||||||
@@ -625,8 +529,6 @@
|
|||||||
|
|
||||||
"pump": ["pump@3.0.4", "", { "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" } }, "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA=="],
|
"pump": ["pump@3.0.4", "", { "dependencies": { "end-of-stream": "^1.1.0", "once": "^1.3.1" } }, "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA=="],
|
||||||
|
|
||||||
"punycode": ["punycode@2.3.1", "", {}, "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg=="],
|
|
||||||
|
|
||||||
"pvtsutils": ["pvtsutils@1.3.6", "", { "dependencies": { "tslib": "^2.8.1" } }, "sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg=="],
|
"pvtsutils": ["pvtsutils@1.3.6", "", { "dependencies": { "tslib": "^2.8.1" } }, "sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg=="],
|
||||||
|
|
||||||
"pvutils": ["pvutils@1.1.5", "", {}, "sha512-KTqnxsgGiQ6ZAzZCVlJH5eOjSnvlyEgx1m8bkRJfOhmGRqfo5KLvmAlACQkrjEtOQ4B7wF9TdSLIs9O90MX9xA=="],
|
"pvutils": ["pvutils@1.1.5", "", {}, "sha512-KTqnxsgGiQ6ZAzZCVlJH5eOjSnvlyEgx1m8bkRJfOhmGRqfo5KLvmAlACQkrjEtOQ4B7wF9TdSLIs9O90MX9xA=="],
|
||||||
@@ -711,8 +613,6 @@
|
|||||||
|
|
||||||
"tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
|
"tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
|
||||||
|
|
||||||
"type-check": ["type-check@0.4.0", "", { "dependencies": { "prelude-ls": "^1.2.1" } }, "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew=="],
|
|
||||||
|
|
||||||
"type-fest": ["type-fest@0.13.1", "", {}, "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg=="],
|
"type-fest": ["type-fest@0.13.1", "", {}, "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg=="],
|
||||||
|
|
||||||
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
||||||
@@ -725,8 +625,6 @@
|
|||||||
|
|
||||||
"unzipper": ["unzipper@0.12.5", "", { "dependencies": { "bluebird": "~3.7.2", "duplexer2": "~0.1.4", "fs-extra": "11.3.1", "graceful-fs": "^4.2.2", "node-int64": "^0.4.0" } }, "sha512-tXYOi9R57Uj/2Z25SOs5RRSzq886MBQj2gY8dPL+xl/kv6s6SvByoKfAtvfVeEuhntWDgjd2o9p2lb4TVPAz0A=="],
|
"unzipper": ["unzipper@0.12.5", "", { "dependencies": { "bluebird": "~3.7.2", "duplexer2": "~0.1.4", "fs-extra": "11.3.1", "graceful-fs": "^4.2.2", "node-int64": "^0.4.0" } }, "sha512-tXYOi9R57Uj/2Z25SOs5RRSzq886MBQj2gY8dPL+xl/kv6s6SvByoKfAtvfVeEuhntWDgjd2o9p2lb4TVPAz0A=="],
|
||||||
|
|
||||||
"uri-js": ["uri-js@4.4.1", "", { "dependencies": { "punycode": "^2.1.0" } }, "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg=="],
|
|
||||||
|
|
||||||
"utf8-byte-length": ["utf8-byte-length@1.0.5", "", {}, "sha512-Xn0w3MtiQ6zoz2vFyUVruaCL53O/DwUvkEeOvj+uulMm0BkUGYWmBYVyElqZaSLhY6ZD0ulfU3aBra2aVT4xfA=="],
|
"utf8-byte-length": ["utf8-byte-length@1.0.5", "", {}, "sha512-Xn0w3MtiQ6zoz2vFyUVruaCL53O/DwUvkEeOvj+uulMm0BkUGYWmBYVyElqZaSLhY6ZD0ulfU3aBra2aVT4xfA=="],
|
||||||
|
|
||||||
"util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="],
|
"util-deprecate": ["util-deprecate@1.0.2", "", {}, "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="],
|
||||||
@@ -735,8 +633,6 @@
|
|||||||
|
|
||||||
"which": ["which@5.0.0", "", { "dependencies": { "isexe": "^3.1.1" }, "bin": { "node-which": "bin/which.js" } }, "sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ=="],
|
"which": ["which@5.0.0", "", { "dependencies": { "isexe": "^3.1.1" }, "bin": { "node-which": "bin/which.js" } }, "sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ=="],
|
||||||
|
|
||||||
"word-wrap": ["word-wrap@1.2.5", "", {}, "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA=="],
|
|
||||||
|
|
||||||
"wrap-ansi": ["wrap-ansi@7.0.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="],
|
"wrap-ansi": ["wrap-ansi@7.0.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="],
|
||||||
|
|
||||||
"wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
|
"wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
|
||||||
@@ -771,8 +667,6 @@
|
|||||||
|
|
||||||
"@electron/windows-sign/fs-extra": ["fs-extra@11.3.4", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-CTXd6rk/M3/ULNQj8FBqBWHYBVYybQ3VPBw0xGKFe3tuH7ytT6ACnvzpIQ3UZtB8yvUKC2cXn1a+x+5EVQLovA=="],
|
"@electron/windows-sign/fs-extra": ["fs-extra@11.3.4", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-CTXd6rk/M3/ULNQj8FBqBWHYBVYybQ3VPBw0xGKFe3tuH7ytT6ACnvzpIQ3UZtB8yvUKC2cXn1a+x+5EVQLovA=="],
|
||||||
|
|
||||||
"@eslint-community/eslint-utils/eslint-visitor-keys": ["eslint-visitor-keys@3.4.3", "", {}, "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag=="],
|
|
||||||
|
|
||||||
"@malept/flatpak-bundler/fs-extra": ["fs-extra@9.1.0", "", { "dependencies": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ=="],
|
"@malept/flatpak-bundler/fs-extra": ["fs-extra@9.1.0", "", { "dependencies": { "at-least-node": "^1.0.0", "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ=="],
|
||||||
|
|
||||||
"@types/cacheable-request/@types/node": ["@types/node@25.5.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw=="],
|
"@types/cacheable-request/@types/node": ["@types/node@25.5.0", "", { "dependencies": { "undici-types": "~7.18.0" } }, "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw=="],
|
||||||
@@ -787,8 +681,6 @@
|
|||||||
|
|
||||||
"app-builder-lib/@electron/get": ["@electron/get@3.1.0", "", { "dependencies": { "debug": "^4.1.1", "env-paths": "^2.2.0", "fs-extra": "^8.1.0", "got": "^11.8.5", "progress": "^2.0.3", "semver": "^6.2.0", "sumchecker": "^3.0.1" }, "optionalDependencies": { "global-agent": "^3.0.0" } }, "sha512-F+nKc0xW+kVbBRhFzaMgPy3KwmuNTYX1fx6+FxxoSnNgwYX6LD7AKBTWkU0MQ6IBoe7dz069CNkR673sPAgkCQ=="],
|
"app-builder-lib/@electron/get": ["@electron/get@3.1.0", "", { "dependencies": { "debug": "^4.1.1", "env-paths": "^2.2.0", "fs-extra": "^8.1.0", "got": "^11.8.5", "progress": "^2.0.3", "semver": "^6.2.0", "sumchecker": "^3.0.1" }, "optionalDependencies": { "global-agent": "^3.0.0" } }, "sha512-F+nKc0xW+kVbBRhFzaMgPy3KwmuNTYX1fx6+FxxoSnNgwYX6LD7AKBTWkU0MQ6IBoe7dz069CNkR673sPAgkCQ=="],
|
||||||
|
|
||||||
"app-builder-lib/ajv": ["ajv@8.20.0", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA=="],
|
|
||||||
|
|
||||||
"app-builder-lib/ci-info": ["ci-info@4.3.1", "", {}, "sha512-Wdy2Igu8OcBpI2pZePZ5oWjPC38tmDVx5WKUXKwlLYkA0ozo85sLsLvkBbBn/sZaSCMFOGZJ14fvW9t5/d7kdA=="],
|
"app-builder-lib/ci-info": ["ci-info@4.3.1", "", {}, "sha512-Wdy2Igu8OcBpI2pZePZ5oWjPC38tmDVx5WKUXKwlLYkA0ozo85sLsLvkBbBn/sZaSCMFOGZJ14fvW9t5/d7kdA=="],
|
||||||
|
|
||||||
"builder-util/https-proxy-agent": ["https-proxy-agent@7.0.6", "", { "dependencies": { "agent-base": "^7.1.2", "debug": "4" } }, "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw=="],
|
"builder-util/https-proxy-agent": ["https-proxy-agent@7.0.6", "", { "dependencies": { "agent-base": "^7.1.2", "debug": "4" } }, "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw=="],
|
||||||
@@ -835,8 +727,6 @@
|
|||||||
|
|
||||||
"app-builder-lib/@electron/get/semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
|
"app-builder-lib/@electron/get/semver": ["semver@6.3.1", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA=="],
|
||||||
|
|
||||||
"app-builder-lib/ajv/json-schema-traverse": ["json-schema-traverse@1.0.0", "", {}, "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug=="],
|
|
||||||
|
|
||||||
"builder-util/https-proxy-agent/agent-base": ["agent-base@7.1.4", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="],
|
"builder-util/https-proxy-agent/agent-base": ["agent-base@7.1.4", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="],
|
||||||
|
|
||||||
"cross-spawn/which/isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="],
|
"cross-spawn/which/isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="],
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: internal
|
||||||
|
area: testing
|
||||||
|
|
||||||
|
- Added a headless end-to-end harness (`bun run test:e2e`, `bun run e2e`) that boots the built app with a real mpv, a synthetic clip, a fixture Yomitan dictionary, and a fake AnkiConnect on an offscreen display.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
type: fixed
|
||||||
|
area: jellyfin
|
||||||
|
|
||||||
|
- Fixed `subminer jellyfin -p` reporting "No Jellyfin libraries found." when SubMiner was already running (for example right after `subminer jellyfin` login). The app now hands library, item, and preview-auth results to the launcher directly instead of through log files, so picker image previews work again and real errors (expired session, unreachable server) are shown instead of an empty list.
|
||||||
|
- The rofi "Jellyfin Search (optional)" step after picking a library is now a compact input box with a "Type to search, or press Enter to browse all" hint instead of a blank list.
|
||||||
|
- Playing from the terminal (`subminer jellyfin -p`) now reports watch progress to Jellyfin even when cast discovery is off, so Jellyfin remembers where you stopped and marks finished episodes as played. Previously progress was only sent while the cast connection was active.
|
||||||
|
- When `subminer jellyfin -p` has to start SubMiner itself, the app now shows its tray icon and quits when you close mpv, the same as playing a local file. Before, it had no tray icon and kept running hidden after playback. A SubMiner that was already running is still reused and left running.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: docs
|
||||||
|
area: jellyfin
|
||||||
|
|
||||||
|
- Corrected the Jellyfin docs: SubMiner only joins the cast menu at startup when `startupWarmups.jellyfinRemoteSession` is on (off by default) along with `jellyfin.remoteControlAutoConnect`. Otherwise tick **Jellyfin Discovery** in the tray.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: added
|
||||||
|
area: subtitles
|
||||||
|
|
||||||
|
- Japanese subtitle generation now works while playing a Jellyfin episode. SubMiner reads the original file from the server, saves the subtitles to a cache folder, and loads them into mpv. Direct-play and transcoded playback are both supported.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: fixed
|
||||||
|
area: overlay
|
||||||
|
|
||||||
|
- Keyboard-only mode no longer swallows `h`, `l`, and the left/right arrows while a modal is open or a text field has focus, so typing into fields like the Jimaku or TsukiHime title works and no longer seeks mpv. Pressing `Ctrl/Cmd+Shift+Y` (or the controller toggle) inside a modal no longer turns on a hidden keyboard-only mode in the modal window.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: docs
|
||||||
|
area: docs
|
||||||
|
|
||||||
|
- Documented how casting finds mpv on every platform, added a troubleshooting entry for casts that never start mpv, and noted that macOS 27 renames the Accessibility privacy list to "Device Control and Data Access".
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
type: fixed
|
||||||
|
area: jellyfin
|
||||||
|
|
||||||
|
- Fixed casting from Jellyfin on macOS when SubMiner is opened from Finder, the Dock, or Spotlight. SubMiner now honors `mpv.executablePath` and `SUBMINER_MPV_PATH` on macOS and Linux, and on macOS also finds mpv in `/opt/homebrew/bin`, `/usr/local/bin`, and `/Applications/mpv.app` instead of failing with `connect ENOENT /tmp/subminer-socket`.
|
||||||
|
- The subtitle timing preview uses the same mpv lookup.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: docs
|
||||||
|
area: launcher
|
||||||
|
|
||||||
|
- Removed `SUBMINER_JIMAKU_API_KEY`, `SUBMINER_JIMAKU_API_KEY_COMMAND`, and `SUBMINER_JIMAKU_API_BASE_URL` from the development docs' environment variable table. The launcher never used them; set the Jimaku key with `jimaku.apiKey` / `jimaku.apiKeyCommand` in the config instead.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
type: internal
|
||||||
|
area: cleanup
|
||||||
|
|
||||||
|
- Removed dead code: the unused launcher Jimaku client (the `SUBMINER_JIMAKU_*` env vars it read were documented but had no effect), the mpv plugin's hover-highlight module (no sender since Overlay 2.0; custom mpv scripts that still send `subminer-hover-token` or `yomipv-hover-token` are now ignored), the never-read `anilist.characterDictionary.refreshTtlHours` / `evictionPolicy` config keys, unused root dependencies (eslint, geist fonts), and a committed draft plan doc.
|
||||||
|
- Typecheck now runs with `noUnusedLocals`; removed the unused locals, imports, and the Windows overlay focus-handoff values they fed, which were computed but never used.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: internal
|
||||||
|
area: overlay
|
||||||
|
|
||||||
|
- Removed 16 overlay preload/IPC methods that nothing called, plus their main-process handlers. SubMiner no longer observes mpv's `sub-text/ass` or sends every ASS line to overlay windows that never listened.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: fixed
|
||||||
|
area: setup
|
||||||
|
|
||||||
|
- First-run setup now labels a missing command-line launcher "Not set up" instead of "Not installed", so the AppImage catalog test no longer reads the setup window as an error screen.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: fixed
|
||||||
|
area: overlay
|
||||||
|
|
||||||
|
- The open subtitle sidebar no longer re-fetches the whole subtitle list and re-queries mpv about 12 times a second. It polls only the current time and line, and reloads the list when the subtitle track, file, or parsed cues change (plus a slow ~2 s fallback), cutting idle sidebar IPC and renderer work during playback.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
type: fixed
|
||||||
|
area: stats
|
||||||
|
|
||||||
|
- Subtitle lines recorded before halfwidth katakana widening now show fullwidth katakana in the stats dashboard (word/kanji occurrences, sentence search), and cards mined from stats history get the fullwidth sentence and word.
|
||||||
|
- Sentence search matches katakana in either width, so searching アンタ also finds older lines stored as アンタ.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
type: fixed
|
||||||
|
area: overlay
|
||||||
|
|
||||||
|
- Hyprland and Sway window tracking no longer freezes the app when `hyprctl` or `swaymsg` is slow or hangs: polls now run in the background with a timeout and no longer pile up.
|
||||||
|
- The Hyprland/Sway trackers read each mpv process's command line once instead of spawning `ps` on every poll.
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
type: fixed
|
||||||
|
area: overlay
|
||||||
|
|
||||||
|
- Halfwidth katakana in subtitles (common in broadcast-derived Japanese subs, e.g. アンタ, ダキニ) now displays as normal fullwidth katakana, so lines no longer mix squashed and normal-width text. Mined sentences and stats get the fullwidth form too.
|
||||||
@@ -734,10 +734,10 @@
|
|||||||
// autoStartSubMiner starts SubMiner in the background; auto_start_overlay only controls visible overlay display.
|
// autoStartSubMiner starts SubMiner in the background; auto_start_overlay only controls visible overlay display.
|
||||||
// Set mpv.launchMode to choose normal, maximized, or fullscreen SubMiner-managed mpv playback.
|
// Set mpv.launchMode to choose normal, maximized, or fullscreen SubMiner-managed mpv playback.
|
||||||
// Set mpv.profile to pass an mpv profile to managed mpv launches; leave it blank to pass none.
|
// Set mpv.profile to pass an mpv profile to managed mpv launches; leave it blank to pass none.
|
||||||
// Leave mpv.executablePath blank to auto-discover mpv.exe from SUBMINER_MPV_PATH or PATH.
|
// Leave mpv.executablePath blank to auto-discover mpv from SUBMINER_MPV_PATH, PATH, or (macOS) Homebrew and /Applications/mpv.app.
|
||||||
// ==========================================
|
// ==========================================
|
||||||
"mpv": {
|
"mpv": {
|
||||||
"executablePath": "", // Optional absolute path to mpv.exe for Windows launch flows. Leave empty to auto-discover from SUBMINER_MPV_PATH or PATH.
|
"executablePath": "", // Optional absolute path to the mpv binary SubMiner starts itself (Windows launches, Jellyfin casting, timing preview). Leave empty to auto-discover from SUBMINER_MPV_PATH, PATH, and on macOS the Homebrew and /Applications/mpv.app locations.
|
||||||
"launchMode": "normal", // Default window state for SubMiner-managed mpv launches. Values: normal | maximized | fullscreen
|
"launchMode": "normal", // Default window state for SubMiner-managed mpv launches. Values: normal | maximized | fullscreen
|
||||||
"profile": "", // Optional mpv profile name passed to SubMiner-managed mpv launches. Leave empty to pass no profile.
|
"profile": "", // Optional mpv profile name passed to SubMiner-managed mpv launches. Leave empty to pass no profile.
|
||||||
"socketPath": "/tmp/subminer-socket", // mpv IPC socket path used by SubMiner-managed playback and the bundled mpv plugin.
|
"socketPath": "/tmp/subminer-socket", // mpv IPC socket path used by SubMiner-managed playback and the bundled mpv plugin.
|
||||||
|
|||||||
@@ -515,12 +515,12 @@ In external-profile mode, SubMiner only reads the profile. It does not open its
|
|||||||
Log in to a Jellyfin server, browse libraries, and play or cast to SubMiner. Login tokens are stored encrypted, not in this file. See [Jellyfin integration](/jellyfin-integration).
|
Log in to a Jellyfin server, browse libraries, and play or cast to SubMiner. Login tokens are stored encrypted, not in this file. See [Jellyfin integration](/jellyfin-integration).
|
||||||
|
|
||||||
| Key | Default | What it does |
|
| Key | Default | What it does |
|
||||||
| ----------------------------------- | -------------------------------- | ----------------------------------------------- |
|
| ----------------------------------- | -------------------------------- | --------------------------------------------------------------------------------------- |
|
||||||
| `jellyfin.enabled` | `false` | Enable Jellyfin |
|
| `jellyfin.enabled` | `false` | Enable Jellyfin |
|
||||||
| `jellyfin.serverUrl` | `""` | Server URL, for example `http://localhost:8096` |
|
| `jellyfin.serverUrl` | `""` | Server URL, for example `http://localhost:8096` |
|
||||||
| `jellyfin.username` | `""` | Default username for `subminer jellyfin -l` |
|
| `jellyfin.username` | `""` | Default username for `subminer jellyfin -l` |
|
||||||
| `jellyfin.remoteControlEnabled` | `true` | Let Jellyfin apps cast to SubMiner |
|
| `jellyfin.remoteControlEnabled` | `true` | Let Jellyfin apps cast to SubMiner |
|
||||||
| `jellyfin.remoteControlAutoConnect` | `true` | Connect the cast session on startup |
|
| `jellyfin.remoteControlAutoConnect` | `true` | Connect the cast session on startup (also needs `startupWarmups.jellyfinRemoteSession`) |
|
||||||
| `jellyfin.autoAnnounce` | `false` | Announce SubMiner as a cast target on connect |
|
| `jellyfin.autoAnnounce` | `false` | Announce SubMiner as a cast target on connect |
|
||||||
| `jellyfin.pullPictures` | `false` | Fetch posters for launcher pickers |
|
| `jellyfin.pullPictures` | `false` | Fetch posters for launcher pickers |
|
||||||
| `jellyfin.iconCacheDir` | `"/tmp/subminer-jellyfin-icons"` | Poster cache folder |
|
| `jellyfin.iconCacheDir` | `"/tmp/subminer-jellyfin-icons"` | Poster cache folder |
|
||||||
@@ -580,8 +580,8 @@ A local web dashboard at `http://127.0.0.1:<serverPort>`, also available as an o
|
|||||||
Settings for mpv instances that SubMiner starts, and for the bundled mpv plugin. See [mpv plugin](/mpv-plugin).
|
Settings for mpv instances that SubMiner starts, and for the bundled mpv plugin. See [mpv plugin](/mpv-plugin).
|
||||||
|
|
||||||
| Key | Default | What it does |
|
| Key | Default | What it does |
|
||||||
| ---------------------------- | ----------------- | --------------------------------------------------------------------------- |
|
| ---------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------- |
|
||||||
| `mpv.executablePath` | `""` | Path to `mpv.exe` on Windows. Empty checks `SUBMINER_MPV_PATH`, then `PATH` |
|
| `mpv.executablePath` | `""` | Full path to mpv. Empty auto-discovers it ([lookup order](/jellyfin-integration#casting-from-jellyfin)) |
|
||||||
| `mpv.launchMode` | `"normal"` | Window state: `normal`, `maximized`, or `fullscreen` |
|
| `mpv.launchMode` | `"normal"` | Window state: `normal`, `maximized`, or `fullscreen` |
|
||||||
| `mpv.profile` | `""` | mpv profile to pass. Combined with a launcher `--profile` if both are set |
|
| `mpv.profile` | `""` | mpv profile to pass. Combined with a launcher `--profile` if both are set |
|
||||||
| `mpv.socketPath` | platform-specific | mpv IPC socket. See the warning under [Config file](#configuration-file) |
|
| `mpv.socketPath` | platform-specific | mpv IPC socket. See the warning under [Config file](#configuration-file) |
|
||||||
|
|||||||
@@ -175,9 +175,6 @@ Run `make help` for the full list.
|
|||||||
| `SUBMINER_MPV_PLUGIN_PATH` | mpv plugin directory the launcher injects |
|
| `SUBMINER_MPV_PLUGIN_PATH` | mpv plugin directory the launcher injects |
|
||||||
| `SUBMINER_LOG_LEVEL` | App log level (`debug`, `info`, `warn`, `error`) |
|
| `SUBMINER_LOG_LEVEL` | App log level (`debug`, `info`, `warn`, `error`) |
|
||||||
| `SUBMINER_MPV_LOG` | Shared mpv/app log file path |
|
| `SUBMINER_MPV_LOG` | Shared mpv/app log file path |
|
||||||
| `SUBMINER_JIMAKU_API_KEY` | Jimaku API key for launcher subtitle downloads |
|
|
||||||
| `SUBMINER_JIMAKU_API_KEY_COMMAND` | Command that prints the Jimaku API key |
|
|
||||||
| `SUBMINER_JIMAKU_API_BASE_URL` | Jimaku API base URL |
|
|
||||||
| `SUBMINER_JELLYFIN_ACCESS_TOKEN` | Jellyfin access token, used before the stored encrypted session |
|
| `SUBMINER_JELLYFIN_ACCESS_TOKEN` | Jellyfin access token, used before the stored encrypted session |
|
||||||
| `SUBMINER_JELLYFIN_USER_ID` | Jellyfin user ID |
|
| `SUBMINER_JELLYFIN_USER_ID` | Jellyfin user ID |
|
||||||
| `SUBMINER_SKIP_MACOS_HELPER_BUILD` | Set to `1` to skip the macOS helper build during `bun run build` |
|
| `SUBMINER_SKIP_MACOS_HELPER_BUILD` | Set to `1` to skip the macOS helper build during `bun run build` |
|
||||||
@@ -187,7 +187,7 @@ First-run setup can install the `subminer` command for you.
|
|||||||
xattr -d com.apple.quarantine /Applications/SubMiner.app
|
xattr -d com.apple.quarantine /Applications/SubMiner.app
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Open **System Settings > Privacy & Security > Accessibility** and enable SubMiner (add it if it is missing). The overlay cannot follow the mpv window without this.
|
3. Open **System Settings > Privacy & Security > Accessibility** and enable SubMiner (add it if it is missing). On macOS 27 this list is named **Device Control and Data Access**. The overlay cannot follow the mpv window without this.
|
||||||
|
|
||||||
First-run setup can install the `subminer` command for you.
|
First-run setup can install the `subminer` command for you.
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ SubMiner stores an encrypted session token, not your password, and turns the int
|
|||||||
|
|
||||||
## Casting from Jellyfin
|
## Casting from Jellyfin
|
||||||
|
|
||||||
After you sign in, SubMiner connects to Jellyfin at startup and shows up in the cast ("Play on") menu under your computer's hostname. To connect for the current session only, tick **Jellyfin Discovery** in the tray menu.
|
After you sign in, tick **Jellyfin Discovery** in the tray menu. SubMiner then shows up in the cast ("Play on") menu under your computer's hostname until it quits. To connect every time SubMiner starts, turn on `startupWarmups.jellyfinRemoteSession` and leave `remoteControlAutoConnect` on.
|
||||||
|
|
||||||
1. In the Jellyfin web or mobile app, start playing an episode.
|
1. In the Jellyfin web or mobile app, start playing an episode.
|
||||||
2. Open the cast menu and pick your computer.
|
2. Open the cast menu and pick your computer.
|
||||||
@@ -23,7 +23,9 @@ SubMiner starts mpv if it is not already running. Pause, seek, stop, and track c
|
|||||||
|
|
||||||
SubMiner selects a Japanese subtitle track automatically and resets mpv's subtitle delay to zero. It direct-plays files when it can and asks Jellyfin to transcode the rest.
|
SubMiner selects a Japanese subtitle track automatically and resets mpv's subtitle delay to zero. It direct-plays files when it can and asks Jellyfin to transcode the rest.
|
||||||
|
|
||||||
On Windows, casting finds mpv through `mpv.executablePath`, then `SUBMINER_MPV_PATH`, then `PATH`. An invalid `mpv.executablePath` stops mpv from starting.
|
If an episode has no Japanese subtitles, you can [generate them with Whisper](/subtitle-generation#generating-from-the-overlay) while it plays.
|
||||||
|
|
||||||
|
Casting finds mpv through `mpv.executablePath`, then `SUBMINER_MPV_PATH`, then `PATH`. On macOS it then checks `/opt/homebrew/bin/mpv`, `/usr/local/bin/mpv`, and `/Applications/mpv.app`, because an app opened from Finder, the Dock, or Spotlight does not get your shell's `PATH`. If mpv lives somewhere else, set `mpv.executablePath` to its full path (`command -v mpv` prints it). An invalid `mpv.executablePath` stops mpv from starting.
|
||||||
|
|
||||||
## Playing from the terminal
|
## Playing from the terminal
|
||||||
|
|
||||||
@@ -34,18 +36,18 @@ subminer jellyfin -p # fzf picker; `jf` is an alias for `jellyfin`
|
|||||||
subminer -R jellyfin -p # rofi picker
|
subminer -R jellyfin -p # rofi picker
|
||||||
```
|
```
|
||||||
|
|
||||||
Sign in first. See [Launcher script](/launcher-script) for the other `jellyfin` subcommands.
|
Sign in first. Playback resumes from Jellyfin's saved position, and watch progress syncs back the same way it does for casting, whether or not discovery is on. If SubMiner is already running, the picker uses it and leaves it running. Otherwise the launcher starts SubMiner and quits it when you close mpv, the same as playing a local file. See [Launcher script](/launcher-script) for the other `jellyfin` subcommands.
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
All options are under **Settings > Integrations > Jellyfin**, or `jellyfin` in `config.jsonc`. See [Configuration](/configuration#jellyfin) for the full list and defaults.
|
All options are under **Settings > Integrations > Jellyfin**, or `jellyfin` in `config.jsonc`. See [Configuration](/configuration#jellyfin) for the full list and defaults.
|
||||||
|
|
||||||
| Key | What it does |
|
| Key | What it does |
|
||||||
| -------------------------- | -------------------------------------------------------------------- |
|
| -------------------------- | ---------------------------------------------------------------------- |
|
||||||
| `enabled` | Turns the integration on. Set for you when you sign in. |
|
| `enabled` | Turns the integration on. Set for you when you sign in. |
|
||||||
| `serverUrl` | Your Jellyfin server. Filled in when you sign in. |
|
| `serverUrl` | Your Jellyfin server. Filled in when you sign in. |
|
||||||
| `remoteControlEnabled` | Lets SubMiner act as a cast target. |
|
| `remoteControlEnabled` | Lets SubMiner act as a cast target. |
|
||||||
| `remoteControlAutoConnect` | Connects at startup. Turn off to start discovery from the tray. |
|
| `remoteControlAutoConnect` | Connects at startup when `startupWarmups.jellyfinRemoteSession` is on. |
|
||||||
| `autoAnnounce` | Re-announces the device on connect. Try it if SubMiner appears late. |
|
| `autoAnnounce` | Re-announces the device on connect. Try it if SubMiner appears late. |
|
||||||
| `transcodeVideoCodec` | Video codec requested when Jellyfin transcodes. |
|
| `transcodeVideoCodec` | Video codec requested when Jellyfin transcodes. |
|
||||||
|
|
||||||
|
|||||||
@@ -734,10 +734,10 @@
|
|||||||
// autoStartSubMiner starts SubMiner in the background; auto_start_overlay only controls visible overlay display.
|
// autoStartSubMiner starts SubMiner in the background; auto_start_overlay only controls visible overlay display.
|
||||||
// Set mpv.launchMode to choose normal, maximized, or fullscreen SubMiner-managed mpv playback.
|
// Set mpv.launchMode to choose normal, maximized, or fullscreen SubMiner-managed mpv playback.
|
||||||
// Set mpv.profile to pass an mpv profile to managed mpv launches; leave it blank to pass none.
|
// Set mpv.profile to pass an mpv profile to managed mpv launches; leave it blank to pass none.
|
||||||
// Leave mpv.executablePath blank to auto-discover mpv.exe from SUBMINER_MPV_PATH or PATH.
|
// Leave mpv.executablePath blank to auto-discover mpv from SUBMINER_MPV_PATH, PATH, or (macOS) Homebrew and /Applications/mpv.app.
|
||||||
// ==========================================
|
// ==========================================
|
||||||
"mpv": {
|
"mpv": {
|
||||||
"executablePath": "", // Optional absolute path to mpv.exe for Windows launch flows. Leave empty to auto-discover from SUBMINER_MPV_PATH or PATH.
|
"executablePath": "", // Optional absolute path to the mpv binary SubMiner starts itself (Windows launches, Jellyfin casting, timing preview). Leave empty to auto-discover from SUBMINER_MPV_PATH, PATH, and on macOS the Homebrew and /Applications/mpv.app locations.
|
||||||
"launchMode": "normal", // Default window state for SubMiner-managed mpv launches. Values: normal | maximized | fullscreen
|
"launchMode": "normal", // Default window state for SubMiner-managed mpv launches. Values: normal | maximized | fullscreen
|
||||||
"profile": "", // Optional mpv profile name passed to SubMiner-managed mpv launches. Leave empty to pass no profile.
|
"profile": "", // Optional mpv profile name passed to SubMiner-managed mpv launches. Leave empty to pass no profile.
|
||||||
"socketPath": "/tmp/subminer-socket", // mpv IPC socket path used by SubMiner-managed playback and the bundled mpv plugin.
|
"socketPath": "/tmp/subminer-socket", // mpv IPC socket path used by SubMiner-managed playback and the bundled mpv plugin.
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ The modal's **Local tools** section lists anything missing. After you install a
|
|||||||
|
|
||||||
## Generating from the overlay
|
## Generating from the overlay
|
||||||
|
|
||||||
1. Open a local video in mpv and select its Japanese audio track, or play a YouTube video.
|
1. Open a local video in mpv and select its Japanese audio track, or play a Jellyfin or YouTube video.
|
||||||
2. Press `Ctrl+Shift+G`. If the subtitle sidebar is empty, its **Generate Japanese subtitles** button opens the same modal.
|
2. Press `Ctrl+Shift+G`. If the subtitle sidebar is empty, its **Generate Japanese subtitles** button opens the same modal.
|
||||||
3. Pick a model and download it if needed.
|
3. Pick a model and download it if needed.
|
||||||
4. Optionally check **Focus on spoken dialogue** (see below).
|
4. Optionally check **Focus on spoken dialogue** (see below).
|
||||||
@@ -26,6 +26,8 @@ The modal shows progress. **Cancel** stops the job. Closing the modal lets the j
|
|||||||
|
|
||||||
SubMiner saves `<video>.ja.generated.srt` next to the video and adds a number if that name is taken. If the same file is still playing, it loads the subtitles and resets the subtitle delay.
|
SubMiner saves `<video>.ja.generated.srt` next to the video and adds a number if that name is taken. If the same file is still playing, it loads the subtitles and resets the subtitle delay.
|
||||||
|
|
||||||
|
For a Jellyfin video, SubMiner reads the original file from your server and saves the subtitles to `~/.cache/subminer/generated-subs/`, since a stream has no folder of its own. Each Jellyfin generation replaces the previous file there. Playback keeps going while it works. If Jellyfin is transcoding, SubMiner transcribes the audio track that playback started with.
|
||||||
|
|
||||||
For a YouTube video, SubMiner downloads its audio first and pauses the video until the subtitles load. The subtitles are temporary, and the audio is deleted when generation ends or you switch videos. See [YouTube integration](/youtube-integration#generate-subtitles-with-whisper).
|
For a YouTube video, SubMiner downloads its audio first and pauses the video until the subtitles load. The subtitles are temporary, and the audio is deleted when generation ends or you switch videos. See [YouTube integration](/youtube-integration#generate-subtitles-with-whisper).
|
||||||
|
|
||||||
Change the shortcut with `shortcuts.openSubtitleGeneration`.
|
Change the shortcut with `shortcuts.openSubtitleGeneration`.
|
||||||
@@ -46,7 +48,7 @@ subminer generate-subs episode.mkv --model-path /path/to/ggml-small.bin
|
|||||||
| `--audio-stream <index>` | Pick an audio stream by its absolute FFmpeg index |
|
| `--audio-stream <index>` | Pick an audio stream by its absolute FFmpeg index |
|
||||||
| `--output <path>` | Write to this SRT path. Existing files are never overwritten. |
|
| `--output <path>` | Write to this SRT path. Existing files are never overwritten. |
|
||||||
|
|
||||||
With a file argument, SubMiner uses the audio stream tagged Japanese, or the first stream. `Ctrl+C` cancels.
|
With a file argument, SubMiner uses the audio stream tagged Japanese, or the first stream. `Ctrl+C` cancels. The launcher only works with local files. Use the overlay for Jellyfin and YouTube.
|
||||||
|
|
||||||
## Choosing a model
|
## Choosing a model
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,18 @@ SubMiner reads subtitles from mpv over an IPC socket (a named pipe on Windows).
|
|||||||
|
|
||||||
SubMiner reconnects on its own if mpv restarts.
|
SubMiner reconnects on its own if mpv restarts.
|
||||||
|
|
||||||
|
## Casting from Jellyfin does nothing
|
||||||
|
|
||||||
|
When `connect ENOENT /tmp/subminer-socket` follows a cast in the app log, SubMiner could not start mpv, so the socket never appeared. Look for `Failed handling Jellyfin remote Play event` or `Failed to launch mpv for Jellyfin remote playback` just before it.
|
||||||
|
|
||||||
|
- Check that `mpv --version` works in a terminal.
|
||||||
|
- If it does, SubMiner is not finding mpv where it is installed. Set `mpv.executablePath` to the output of `command -v mpv`. See [Casting from Jellyfin](/jellyfin-integration#casting-from-jellyfin) for where SubMiner looks.
|
||||||
|
|
||||||
## Overlay does not appear
|
## Overlay does not appear
|
||||||
|
|
||||||
- Confirm SubMiner is running (`SubMiner.AppImage --start`, or check for the process).
|
- Confirm SubMiner is running (`SubMiner.AppImage --start`, or check for the process).
|
||||||
- Linux: Hyprland and Sway work natively. Any other compositor needs mpv and SubMiner under X11 or Xwayland, with `xdotool`, `xprop`, and `xwininfo` installed. See [KDE Plasma and other Wayland compositors](#kde-plasma-and-other-wayland-compositors).
|
- Linux: Hyprland and Sway work natively. Any other compositor needs mpv and SubMiner under X11 or Xwayland, with `xdotool`, `xprop`, and `xwininfo` installed. See [KDE Plasma and other Wayland compositors](#kde-plasma-and-other-wayland-compositors).
|
||||||
- macOS: grant Accessibility permission in System Settings > Privacy & Security > Accessibility.
|
- macOS: grant Accessibility permission. See [macOS](#macos).
|
||||||
|
|
||||||
## Overlay is on the wrong monitor or position
|
## Overlay is on the wrong monitor or position
|
||||||
|
|
||||||
@@ -255,5 +262,5 @@ mpv --gpu-context=x11vk,x11egl,x11 video.mkv
|
|||||||
|
|
||||||
## macOS
|
## macOS
|
||||||
|
|
||||||
- Accessibility permission is required for window tracking: System Settings > Privacy & Security > Accessibility.
|
- Accessibility permission is required for window tracking: System Settings > Privacy & Security > Accessibility. On macOS 27 this list is named **Device Control and Data Access**.
|
||||||
- If Gatekeeper blocks the app, right-click it and choose Open, or run `xattr -d com.apple.quarantine /path/to/SubMiner.app`.
|
- If Gatekeeper blocks the app, right-click it and choose Open, or run `xattr -d com.apple.quarantine /path/to/SubMiner.app`.
|
||||||
@@ -1,298 +0,0 @@
|
|||||||
# Renderer Performance Optimizations
|
|
||||||
|
|
||||||
**Date:** 2026-03-15
|
|
||||||
**Status:** Draft
|
|
||||||
|
|
||||||
## Goal
|
|
||||||
|
|
||||||
Minimize the time between a subtitle line appearing and annotations being displayed. Three optimizations target different pipeline stages to achieve this.
|
|
||||||
|
|
||||||
## Current Pipeline (Warm State)
|
|
||||||
|
|
||||||
```text
|
|
||||||
MPV subtitle change (0ms)
|
|
||||||
-> IPC to main (5ms)
|
|
||||||
-> Cache check (2ms)
|
|
||||||
-> [CACHE MISS] Yomitan parser (35-180ms)
|
|
||||||
-> Parallel: MeCab enrichment (20-80ms) + Frequency lookup (15-50ms)
|
|
||||||
-> Annotation stage: 4 sequential passes (25-70ms)
|
|
||||||
-> IPC to renderer (10ms)
|
|
||||||
-> DOM render: createElement per token (15-50ms)
|
|
||||||
─────────────────────────────────
|
|
||||||
Total: ~200-320ms (cache miss)
|
|
||||||
Total: ~72ms (cache hit)
|
|
||||||
```
|
|
||||||
|
|
||||||
## Target Pipeline
|
|
||||||
|
|
||||||
```text
|
|
||||||
MPV subtitle change (0ms)
|
|
||||||
-> IPC to main (5ms)
|
|
||||||
-> Cache check (2ms)
|
|
||||||
-> [CACHE HIT via prefetch] (0ms)
|
|
||||||
-> IPC to renderer (10ms)
|
|
||||||
-> DOM render: cloneNode from template (10-30ms)
|
|
||||||
─────────────────────────────────
|
|
||||||
Total: ~30-50ms (prefetch-warmed, normal playback)
|
|
||||||
|
|
||||||
[CACHE MISS, e.g. immediate seek]
|
|
||||||
-> Yomitan parser (35-180ms)
|
|
||||||
-> Parallel: MeCab enrichment + Frequency lookup
|
|
||||||
-> Annotation stage: 1 batched pass (10-25ms)
|
|
||||||
-> IPC to renderer (10ms)
|
|
||||||
-> DOM render: cloneNode from template (10-30ms)
|
|
||||||
─────────────────────────────────
|
|
||||||
Total: ~150-260ms (cache miss, still improved)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Optimization 1: Subtitle Prefetching
|
|
||||||
|
|
||||||
### Summary
|
|
||||||
|
|
||||||
A new `SubtitlePrefetchService` parses external subtitle files and tokenizes upcoming lines in the background before they appear on screen. This converts most cache misses into cache hits during normal playback.
|
|
||||||
|
|
||||||
### Scope
|
|
||||||
|
|
||||||
External subtitle files only (SRT, VTT, ASS). Embedded subtitle tracks are out of scope since Japanese subtitles are virtually always external files.
|
|
||||||
|
|
||||||
### Architecture
|
|
||||||
|
|
||||||
#### Subtitle File Parsing
|
|
||||||
|
|
||||||
A cue parser extracts both timing and text content from subtitle files for prefetching.
|
|
||||||
|
|
||||||
**Parsed cue structure:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
interface SubtitleCue {
|
|
||||||
startTime: number; // seconds
|
|
||||||
endTime: number; // seconds
|
|
||||||
text: string; // plain text, decoded from the source format
|
|
||||||
source?: 'canonical-ass'; // recovered authored text for generated ASS animation
|
|
||||||
animationStartTime?: number; // full generated-frame envelope; entrance/exit frames
|
|
||||||
animationEndTime?: number; // run past the authored timing, live matching uses this
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Supported formats:**
|
|
||||||
|
|
||||||
- SRT/VTT: Regex-based parsing of timing lines + text content between timing blocks.
|
|
||||||
- ASS: Parse the `[Events]` section, read the field order from the `Format:` row, and extract timed `Dialogue:` lines. Timed `Comment:` lines are normally ignored, but can supply canonical authored text when they match a nearby generated animation from the same style and actor. Text can itself contain commas.
|
|
||||||
|
|
||||||
**ASS decoding.** The parser is where ASS text is decoded, once, via `assToPlainText()` in `src/core/services/ass-text.ts`. That decoder mirrors mpv's `ass_to_plaintext` so a cue read from a file reads identically to the same line arriving live on `sub-text`: `{...}` override blocks are markup, `\pN … \p0` vector drawing runs are dropped rather than shown as text, `\N`/`\n`/`\h` are the only escapes (`\{`, `\}` and `\\` are not), and an unclosed `{` is rendered verbatim. Every layer downstream — renderer, timing tracker, tokenizer, tokenization cache keys — receives plain text and uses `normalizePlainSubtitleText()` for whitespace only, so nothing decodes the same string twice and one authored line always maps to one cache key.
|
|
||||||
|
|
||||||
**Duplicate collapsing.** Typeset scripts emit one `Dialogue:` event per animation frame, plus layered copies of the same line. The parser collapses identical text over an identical span unconditionally, and collapses contiguous same-text runs of at least three events when the run looks like an animation. For ASS that means shared style and actor plus authoring evidence: a temporal tag (`\t`, `\move`, `\k`/`\kf`/`\ko`/`\K`, or anything wrapped in `\t(...)`), an animated `Effect` column (`Karaoke`, `Banner`, `Scroll`), or override values that change across the run. Static tags shared by every event (`\pos`, an identical `\clip`) are not evidence. SRT/VTT carry no such metadata, so there collapsing needs at least five contiguous events all under 0.1s — the frame timing left behind by ASS-to-SRT conversion. The parser keeps this authoring metadata (style, actor, layer, `Effect`, parsed override commands, source order) private; `parseSubtitleCues()` returns only `SubtitleCue`.
|
|
||||||
|
|
||||||
ASS scripts can also redraw one complete lyric for two or more long color/highlight phases. Those flush-timed phases collapse separately from short animation frames when they share text, style, actor, and layer and carry direct animation evidence, such as temporal tags or changing non-spatial overrides. Spatial command changes do not prove a phase, so separately positioned signs remain distinct.
|
|
||||||
|
|
||||||
**Canonical animation recovery.** Some ASS producers keep the readable lyric or sign as a timed `Comment:` and generate hundreds of `Dialogue:` frames containing repeated glyphs or changing clip regions. Others retain the complete line as brief `Dialogue:` events around the generated fragments. A complete event is promoted only when nearby dialogue from the same style and actor forms a proven animation cluster and reconstructs its entire text in source order. The generated frames are then replaced by one cue marked `source: 'canonical-ass'`. This source marker lets the live primary-subtitle path prefer the clean authored text and timing for display, sidebar history, immersion recording, and mining, while unmatched editor notes and alternative translations remain ignored. Secondary selection advances to an entering canonical cue at its generated animation start when the preceding authored cue ends before the new authored span. Unrelated simultaneous cues that continue through the new span remain visible.
|
|
||||||
|
|
||||||
**Font texture cleanup.** A clipped repeated-glyph run or frequent changes to secondary alpha marks a texture seed. Clipped runs do not need a font override because some signs build their masks from ordinary `l` glyphs. The parser removes short clipped pieces that share a no-font seed's style and timing, or pieces that share a font seed's style, timing, and font even when the actor changes. It also removes positioned text layers with at least `E0` global alpha when they overlap a seed in the same style. Opaque authored sign text stays publishable when the texture switches fonts or actors around it.
|
|
||||||
|
|
||||||
#### Prefetch Service Lifecycle
|
|
||||||
|
|
||||||
1. **Activation trigger:** When a subtitle track is activated (or changes), check if it's external via MPV's `track-list` property. If `external === true`, read the file via `external-filename` using the existing `loadSubtitleSourceText` infrastructure.
|
|
||||||
2. **Parse phase:** Parse all cues from the file content. Sort by start time. Store as an ordered array.
|
|
||||||
3. **Priority window:** Determine the current playback position. Identify the next 10 cues as the priority window.
|
|
||||||
4. **Priority tokenization:** Tokenize the priority window cues sequentially, storing results into the `SubtitleProcessingController`'s tokenization cache.
|
|
||||||
5. **Background tokenization:** After the priority window is done, tokenize remaining cues working forward from the current position, then wrapping around to cover earlier cues. The prefetcher stops once it has tokenized all cues or the cache is full (whichever comes first) to avoid wasteful eviction churn. For files with more cues than the cache limit, background tokenization focuses on cues ahead of the current position.
|
|
||||||
6. **Seek handling:** On seek, re-compute the priority window from the new position. A seek is detected by observing MPV's `time-pos` property and checking if the delta from the last observed position exceeds a threshold (e.g., > 3 seconds forward or any backward jump). The current in-flight tokenization finishes naturally, then the new priority window takes over.
|
|
||||||
7. **Teardown:** When the subtitle track changes or playback ends, stop all prefetch work and discard state.
|
|
||||||
|
|
||||||
#### Live Priority
|
|
||||||
|
|
||||||
The prefetcher and live subtitle handler share the Yomitan parser (single-threaded IPC). Live subtitle requests must always take priority. The prefetcher:
|
|
||||||
|
|
||||||
- Checks a `paused` flag before each cue tokenization. The live handler sets `paused = true` on subtitle change and clears it after emission.
|
|
||||||
- Yields between each background cue tokenization (via `setTimeout(0)` or equivalent) so the live handler can set the pause flag between cues.
|
|
||||||
- When paused, the prefetcher waits (polling the flag on a short interval or awaiting a resume signal) before continuing with the next cue.
|
|
||||||
|
|
||||||
#### Cache Integration
|
|
||||||
|
|
||||||
The prefetcher calls the same `tokenizeSubtitle` function used by live processing to produce `SubtitleData` results, then stores them into the existing `SubtitleProcessingController` tokenization cache via a new method:
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// New methods on SubtitleProcessingController
|
|
||||||
preCacheTokenization: (text: string, data: SubtitleData) => void;
|
|
||||||
isCacheFull: () => boolean;
|
|
||||||
```
|
|
||||||
|
|
||||||
`preCacheTokenization` uses the same `setCachedTokenization` logic internally (LRU eviction, Map-based storage). `isCacheFull` returns `true` when the cache has reached its limit, allowing the prefetcher to stop background tokenization and avoid wasteful eviction churn.
|
|
||||||
|
|
||||||
#### Cache Invalidation
|
|
||||||
|
|
||||||
When the user marks a word as known (or any event triggers `invalidateTokenizationCache()`), all cached results are cleared -- including prefetched ones, since they share the same cache. After invalidation, the prefetcher re-computes the priority window from the current playback position and re-tokenizes those cues to restore warm cache state.
|
|
||||||
|
|
||||||
#### Error Handling
|
|
||||||
|
|
||||||
If the subtitle file is malformed or partially parseable, the cue parser uses what it can extract. A file that yields zero cues disables prefetching silently (falls back to live-only processing). Encoding errors from `loadSubtitleSourceText` are caught and logged; prefetching is skipped for that track.
|
|
||||||
|
|
||||||
#### Integration Points
|
|
||||||
|
|
||||||
- **MPV property subscriptions:** Needs `track-list` (to detect external subtitle file path) and `time-pos` (to track playback position for window calculation and seek detection).
|
|
||||||
- **File loading:** Uses existing `loadSubtitleSourceText` dependency.
|
|
||||||
- **Tokenization:** Calls the same `tokenizeSubtitle` function used by live processing.
|
|
||||||
- **Cache:** Writes into `SubtitleProcessingController`'s cache.
|
|
||||||
- **Cache invalidation:** Listens for cache invalidation events to re-prefetch the priority window.
|
|
||||||
|
|
||||||
### Files Affected
|
|
||||||
|
|
||||||
- **New:** `src/core/services/subtitle-prefetch.ts` -- the prefetch service
|
|
||||||
- **New:** `src/core/services/subtitle-cue-parser.ts` -- SRT/VTT/ASS cue parser (text + timing)
|
|
||||||
- **Modified:** `src/core/services/subtitle-processing-controller.ts` -- expose `preCacheTokenization` method
|
|
||||||
- **Modified:** `src/main.ts` -- wire up the prefetch service, listen to track changes
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Optimization 2: Batched Annotation Pass
|
|
||||||
|
|
||||||
### Summary
|
|
||||||
|
|
||||||
Collapse the 4 sequential annotation passes (`applyKnownWordMarking` -> `applyFrequencyMarking` -> `applyJlptMarking` -> `markNPlusOneTargets`) into a single iteration over the token array, followed by N+1 marking.
|
|
||||||
|
|
||||||
**Important context:** Frequency rank _values_ (`token.frequencyRank`) are already assigned at the parser level by `applyFrequencyRanks()` in `tokenizer.ts`, before the annotation stage is called. The annotation stage's `applyFrequencyMarking` only performs POS-based _filtering_ -- clearing `frequencyRank` to `undefined` for tokens that should be excluded (particles, noise tokens, etc.) and normalizing valid ranks. This optimization does not change the parser-level frequency rank assignment; it only batches the annotation-level filtering.
|
|
||||||
|
|
||||||
### Current Flow (4 passes, 4 array copies)
|
|
||||||
|
|
||||||
```text
|
|
||||||
tokens (already have frequencyRank values from parser-level applyFrequencyRanks)
|
|
||||||
-> applyKnownWordMarking() // .map() -> new array
|
|
||||||
-> applyFrequencyMarking() // .map() -> new array (POS-based filtering only)
|
|
||||||
-> applyJlptMarking() // .map() -> new array
|
|
||||||
-> markNPlusOneTargets() // .map() -> new array
|
|
||||||
```
|
|
||||||
|
|
||||||
### Dependency Analysis
|
|
||||||
|
|
||||||
All annotations either depend on MeCab POS data or benefit from running after it:
|
|
||||||
|
|
||||||
- **Known word marking:** Needs base tokens (surface/headword). No POS dependency, but no reason to run separately.
|
|
||||||
- **Frequency filtering:** Uses `pos1Exclusions` and `pos2Exclusions` to clear frequency ranks on excluded tokens (particles, noise). Depends on MeCab POS data.
|
|
||||||
- **JLPT marking:** Uses `shouldIgnoreJlptForMecabPos1` to filter. Depends on MeCab POS data.
|
|
||||||
- **N+1 marking:** Uses POS exclusion sets to filter candidates. Depends on known word status + MeCab POS.
|
|
||||||
|
|
||||||
Since frequency filtering and JLPT marking both depend on POS data from MeCab enrichment, and MeCab enrichment already happens before the annotation stage, all four can run in a single pass after MeCab completes.
|
|
||||||
|
|
||||||
### New Flow (1 pass + N+1)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
function annotateTokens(tokens, deps, options): MergedToken[] {
|
|
||||||
const pos1Exclusions = resolvePos1Exclusions(options);
|
|
||||||
const pos2Exclusions = resolvePos2Exclusions(options);
|
|
||||||
|
|
||||||
// Single pass: known word + frequency filtering + JLPT computed together
|
|
||||||
const annotated = tokens.map((token) => {
|
|
||||||
const isKnown = nPlusOneEnabled ? token.isKnown || computeIsKnown(token, deps) : false;
|
|
||||||
|
|
||||||
// Filter frequency rank using POS exclusions (rank values already set at parser level)
|
|
||||||
const frequencyRank = frequencyEnabled
|
|
||||||
? filterFrequencyRank(token, pos1Exclusions, pos2Exclusions)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const jlptLevel = jlptEnabled ? computeJlptLevel(token, deps.getJlptLevel) : undefined;
|
|
||||||
|
|
||||||
return { ...token, isKnown, frequencyRank, jlptLevel };
|
|
||||||
});
|
|
||||||
|
|
||||||
// N+1 must run after known word status is set for all tokens
|
|
||||||
if (nPlusOneEnabled) {
|
|
||||||
return markNPlusOneTargets(annotated, minSentenceWords, pos1Exclusions, pos2Exclusions);
|
|
||||||
}
|
|
||||||
|
|
||||||
return annotated;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### What Changes
|
|
||||||
|
|
||||||
- The individual `applyKnownWordMarking`, `applyFrequencyMarking`, `applyJlptMarking` functions are refactored into per-token computation helpers (pure functions that compute a single field). The frequency helper is named `filterFrequencyRank` to clarify it performs POS-based exclusion, not rank computation.
|
|
||||||
- The `annotateTokens` orchestrator runs one `.map()` call that invokes all three helpers per token.
|
|
||||||
- `markNPlusOneTargets` remains a separate pass because it needs the full array with `isKnown` set (it examines sentence-level context).
|
|
||||||
- The parser-level `applyFrequencyRanks()` call in `tokenizer.ts` is unchanged -- it remains a separate step outside the annotation stage.
|
|
||||||
- Net: 4 array copies + 4 iterations become 1 array copy + 1 iteration + N+1 pass.
|
|
||||||
|
|
||||||
### Expected Savings
|
|
||||||
|
|
||||||
~15-45ms saved (3 fewer array allocations + 3 fewer full iterations). Annotation drops from ~25-70ms to ~10-25ms.
|
|
||||||
|
|
||||||
### Files Affected
|
|
||||||
|
|
||||||
- **Modified:** `src/core/services/tokenizer/annotation-stage.ts` -- refactor into batched single-pass
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Optimization 3: DOM Template Pooling
|
|
||||||
|
|
||||||
### Summary
|
|
||||||
|
|
||||||
Replace `document.createElement('span')` calls in the renderer with `templateSpan.cloneNode(false)` from a pre-created template element.
|
|
||||||
|
|
||||||
### Current Behavior
|
|
||||||
|
|
||||||
In `renderWithTokens` (`subtitle-render.ts`), each render cycle:
|
|
||||||
|
|
||||||
1. Clears DOM with `innerHTML = ''`
|
|
||||||
2. Creates a `DocumentFragment`
|
|
||||||
3. Calls `document.createElement('span')` for each token (~10-15 per subtitle)
|
|
||||||
4. Sets `className`, `textContent`, `dataset.*` individually
|
|
||||||
5. Appends fragment to root
|
|
||||||
|
|
||||||
### New Behavior
|
|
||||||
|
|
||||||
1. At renderer initialization (`createSubtitleRenderer`), create a single template:
|
|
||||||
```typescript
|
|
||||||
const templateSpan = document.createElement('span');
|
|
||||||
```
|
|
||||||
2. In `renderWithTokens`, replace every `document.createElement('span')` with:
|
|
||||||
```typescript
|
|
||||||
const span = templateSpan.cloneNode(false) as HTMLSpanElement;
|
|
||||||
```
|
|
||||||
3. Replace all `innerHTML = ''` calls with `root.replaceChildren()` to avoid the HTML parser invocation on clear. This applies to `renderSubtitle` (primary subtitle root), `renderSecondarySub` (secondary subtitle root), and `renderCharacterLevel` if applicable.
|
|
||||||
4. Everything else stays the same (setting className, textContent, dataset, appending to fragment).
|
|
||||||
|
|
||||||
### Why cloneNode Over Full Node Recycling
|
|
||||||
|
|
||||||
Full recycling (collecting old nodes, clearing attributes, reusing them) requires carefully resetting every `dataset.*` property that might have been set on a previous render. This is error-prone -- a stale `data-frequency-rank` from a previous subtitle appearing on a new token would cause incorrect styling. `cloneNode(false)` on a bare template is nearly as fast and produces a clean node every time.
|
|
||||||
|
|
||||||
### Expected Savings
|
|
||||||
|
|
||||||
`cloneNode(false)` is ~2-3x faster than `createElement` in most browser engines. For 10-15 tokens per subtitle: ~3-8ms saved per render cycle.
|
|
||||||
|
|
||||||
### Files Affected
|
|
||||||
|
|
||||||
- **Modified:** `src/renderer/subtitle-render.ts` -- template creation + cloneNode usage
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Combined Impact Summary
|
|
||||||
|
|
||||||
| Scenario | Before | After | Improvement |
|
|
||||||
| --------------------------------- | ---------- | ---------- | ----------- |
|
|
||||||
| Normal playback (prefetch-warmed) | ~200-320ms | ~30-50ms | ~80-85% |
|
|
||||||
| Cache hit (repeated subtitle) | ~72ms | ~55-65ms | ~10-20% |
|
|
||||||
| Cache miss (immediate seek) | ~200-320ms | ~150-260ms | ~20-25% |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Files Summary
|
|
||||||
|
|
||||||
### New Files
|
|
||||||
|
|
||||||
- `src/core/services/subtitle-prefetch.ts`
|
|
||||||
- `src/core/services/subtitle-cue-parser.ts`
|
|
||||||
|
|
||||||
### Modified Files
|
|
||||||
|
|
||||||
- `src/core/services/subtitle-processing-controller.ts` (expose `preCacheTokenization`)
|
|
||||||
- `src/core/services/tokenizer/annotation-stage.ts` (batched single-pass)
|
|
||||||
- `src/renderer/subtitle-render.ts` (template cloneNode)
|
|
||||||
- `src/main.ts` (wire up prefetch service)
|
|
||||||
|
|
||||||
### Test Files
|
|
||||||
|
|
||||||
- New tests for subtitle cue parser (SRT, VTT, ASS formats)
|
|
||||||
- New tests for subtitle prefetch service (priority window, seek, pause/resume)
|
|
||||||
- Updated tests for annotation stage (same behavior, new implementation)
|
|
||||||
- Updated tests for subtitle render (template cloning)
|
|
||||||
@@ -32,7 +32,7 @@ Update checks and startup launcher migration share a serialized update-state sto
|
|||||||
- `src/main/boot/` owns boot-phase assembly seams so `src/main.ts` can stay focused on lifecycle coordination and startup-path selection.
|
- `src/main/boot/` owns boot-phase assembly seams so `src/main.ts` can stay focused on lifecycle coordination and startup-path selection.
|
||||||
- `src/main/runtime/linux-overlay-mode-runtime.ts` owns Linux fullscreen mode state and window replacement. App cleanup cancels pending replacements; `main.ts` supplies window creation and subtitle refresh hooks.
|
- `src/main/runtime/linux-overlay-mode-runtime.ts` owns Linux fullscreen mode state and window replacement. App cleanup cancels pending replacements; `main.ts` supplies window creation and subtitle refresh hooks.
|
||||||
- `src/core/services/` owns focused runtime services plus pure or side-effect-bounded logic.
|
- `src/core/services/` owns focused runtime services plus pure or side-effect-bounded logic.
|
||||||
- `src/core/services/subtitle-generation*.ts` shares local whisper.cpp transcription, safe model downloads, and progress between the launcher and Electron. Optional dialogue mode retains both Silero-detected speech and other audible sections, omits confidently silent gaps, decodes passages independently, and restores original media timing. `src/main/runtime/subtitle-generation-runtime.ts` owns the overlay job lifecycle and only loads completed subtitles into the same local media; `src/shared/subtitle-generation*.ts` owns configuration, the multilingual model catalog, and IPC contracts. The overlay runtime retains a session model selection, validates picker requests through IPC, and keeps external model paths authoritative.
|
- `src/core/services/subtitle-generation*.ts` shares local whisper.cpp transcription, safe model downloads, and progress between the launcher and Electron. Optional dialogue mode retains both Silero-detected speech and other audible sections, omits confidently silent gaps, decodes passages independently, and restores original media timing. `src/main/runtime/subtitle-generation-runtime.ts` owns the overlay job lifecycle and only loads completed subtitles into the same media. For Jellyfin playback it reads the item's original-file stream (`toJellyfinOriginalStreamUrl`) into one reused output folder, where each run best-effort deletes earlier files and writes a uniquely named SRT; transcoded playback uses Jellyfin's audio index and only external references, since mpv's track indexes describe the transcode. Subprocess errors redact URL tokens; `src/shared/subtitle-generation*.ts` owns configuration, the multilingual model catalog, and IPC contracts. The overlay runtime retains a session model selection, validates picker requests through IPC, and keeps external model paths authoritative.
|
||||||
- Subtitle model recommendations use bounded `nvidia-smi` and Whisper CUDA discovery probes in `subtitle-generation-acceleration.ts`. The overlay runtime caches results by executable path for 30 seconds and exposes acceleration status through the existing status IPC. Recommendations do not alter model selection or transcription arguments.
|
- Subtitle model recommendations use bounded `nvidia-smi` and Whisper CUDA discovery probes in `subtitle-generation-acceleration.ts`. The overlay runtime caches results by executable path for 30 seconds and exposes acceleration status through the existing status IPC. Recommendations do not alter model selection or transcription arguments.
|
||||||
- `subtitle-generation-reference.ts` ranks mpv's loaded text subtitle tracks, excludes signs/songs and forced references, and extracts timing hints with FFmpeg. The overlay and launcher snapshot references only for matching media, including active subtitle delays. Hints guide long-passage cuts with or without VAD; they never limit audio coverage or replace Whisper timestamps.
|
- `subtitle-generation-reference.ts` ranks mpv's loaded text subtitle tracks, excludes signs/songs and forced references, and extracts timing hints with FFmpeg. The overlay and launcher snapshot references only for matching media, including active subtitle delays. Hints guide long-passage cuts with or without VAD; they never limit audio coverage or replace Whisper timestamps.
|
||||||
- `src/main/runtime/subtitle-selection.ts` reads and validates mpv subtitle tracks and applies primary/secondary selections. Its opt-in session shortcut opens the shared overlay modal window, with renderer focus and subtitle suppression handled by the modal registry.
|
- `src/main/runtime/subtitle-selection.ts` reads and validates mpv subtitle tracks and applies primary/secondary selections. Its opt-in session shortcut opens the shared overlay modal window, with renderer focus and subtitle suppression handled by the modal registry.
|
||||||
|
|||||||
@@ -63,7 +63,11 @@ the plugin artifact, persistent config, or session help.
|
|||||||
|
|
||||||
The subtitle sidebar consumes parsed cues through `SubtitleSidebarSnapshot`. Its `sourceKey`
|
The subtitle sidebar consumes parsed cues through `SubtitleSidebarSnapshot`. Its `sourceKey`
|
||||||
identifies the media and subtitle source so renderer selections are invalidated on source changes,
|
identifies the media and subtitle source so renderer selections are invalidated on source changes,
|
||||||
including changes whose cue text and timings are identical. Native selection and clean clipboard
|
including changes whose cue text and timings are identical. While open, the sidebar polls the
|
||||||
|
cheap `SubtitleSidebarPlaybackState` (cached time, current line, `sourceKey`, `cuesRevision`; no
|
||||||
|
mpv round-trips) every 80 ms for active-cue tracking. It fetches the full snapshot, which resolves
|
||||||
|
the source over mpv IPC and carries every cue plus config, only on open, config reload, a
|
||||||
|
`sourceKey`/`cuesRevision` change, and a ~2 s fallback. Native selection and clean clipboard
|
||||||
serialization live in `src/renderer/modals/subtitle-sidebar-selection.ts`. Electron lets standard
|
serialization live in `src/renderer/modals/subtitle-sidebar-selection.ts`. Electron lets standard
|
||||||
Copy input reach the renderer, where sidebar selection takes priority over the live-subtitle binding.
|
Copy input reach the renderer, where sidebar selection takes priority over the live-subtitle binding.
|
||||||
The preload bridge writes selections through Electron's clipboard API so copying does not depend
|
The preload bridge writes selections through Electron's clipboard API so copying does not depend
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ Read when: finding internal docs or checking verification status
|
|||||||
| Planning guide | `docs/workflow/planning.md` | active | 2026-05-23 | lightweight vs execution plans |
|
| Planning guide | `docs/workflow/planning.md` | active | 2026-05-23 | lightweight vs execution plans |
|
||||||
| Agent skills | `docs/workflow/agent-skills.md` | active | 2026-08-23 | repo-local workflow skill ownership |
|
| Agent skills | `docs/workflow/agent-skills.md` | active | 2026-08-23 | repo-local workflow skill ownership |
|
||||||
| Verification guide | `docs/workflow/verification.md` | active | 2026-08-13 | maintained verification lanes |
|
| Verification guide | `docs/workflow/verification.md` | active | 2026-08-13 | maintained verification lanes |
|
||||||
|
| Testing guidelines | `docs/workflow/testing.md` | active | 2026-10-04 | test style and anti-patterns |
|
||||||
| Release guide | `docs/RELEASING.md` | active | 2026-05-23 | release checklist |
|
| Release guide | `docs/RELEASING.md` | active | 2026-05-23 | release checklist |
|
||||||
|
|
||||||
## Update Rules
|
## Update Rules
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ This section is the internal workflow map for contributors and agents.
|
|||||||
|
|
||||||
- [Planning](./planning.md) - when to write a lightweight plan vs a full execution plan
|
- [Planning](./planning.md) - when to write a lightweight plan vs a full execution plan
|
||||||
- [Verification](./verification.md) - maintained test/build lanes and handoff gate
|
- [Verification](./verification.md) - maintained test/build lanes and handoff gate
|
||||||
|
- [Testing](./testing.md) - what a good test looks like and what not to write
|
||||||
- [Agent Skills](./agent-skills.md) - repo-local workflow skill ownership
|
- [Agent Skills](./agent-skills.md) - repo-local workflow skill ownership
|
||||||
- [Release Guide](../RELEASING.md) - tagged release workflow
|
- [Release Guide](../RELEASING.md) - tagged release workflow
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<!-- read_when: writing, reviewing, or deleting tests -->
|
||||||
|
|
||||||
|
# Testing Guidelines
|
||||||
|
|
||||||
|
Status: active
|
||||||
|
Last verified: 2026-10-04
|
||||||
|
Owner: Kyle Yasuda
|
||||||
|
Read when: adding or changing tests
|
||||||
|
|
||||||
|
Which lanes to run lives in [Verification](./verification.md). This page covers what a
|
||||||
|
good test looks like here.
|
||||||
|
|
||||||
|
## Test Behavior, Not Wiring
|
||||||
|
|
||||||
|
- Exercise a module through its public interface and assert outcomes: return values,
|
||||||
|
resulting state, files written, rows in sqlite, messages sent to a fake process.
|
||||||
|
- Prefer real collaborators that are cheap: tmp dirs, in-memory or tmp sqlite, fake
|
||||||
|
executables, pure parsers. Fake only the edges (Electron, mpv socket, network).
|
||||||
|
- Assert call order only when order is the behavior (startup sequencing, ABA races),
|
||||||
|
and then assert relative order, not the whole call log.
|
||||||
|
|
||||||
|
## Do Not Write
|
||||||
|
|
||||||
|
- Pass-through tests: a builder or handler that only forwards deps (`*-main-deps.ts`,
|
||||||
|
`*-runtime-handlers.ts`) needs no test. TypeScript already checks the shape.
|
||||||
|
- Source-text tests: reading `.ts`, `.css`, `.html`, `.lua`, `.swift`, or workflow YAML
|
||||||
|
and asserting with regexes. If the invariant matters, extract the logic and run it
|
||||||
|
(see `src/preload-ipc-listeners.ts`). Policy lints over workflow YAML are the
|
||||||
|
exception and belong in one parsed-YAML check.
|
||||||
|
- "Stays deleted" tests for removed modules, flags, or selectors. `tsc` and review
|
||||||
|
catch reintroduction.
|
||||||
|
- Tests that restate constants, defaults, labels, or window options.
|
||||||
|
- The same rule at several layers. Test a rule once where it lives; keep one
|
||||||
|
end-to-end case (for the tokenizer, the golden corpus) for integration.
|
||||||
|
|
||||||
|
## Keep Tests Small
|
||||||
|
|
||||||
|
- Shared setup goes in a `makeDeps(overrides)` helper or a `*-test-harness.ts` file, not
|
||||||
|
pasted into every test.
|
||||||
|
- Near-identical cases become a table: `for (const c of cases) test(c.name, ...)`.
|
||||||
|
- Inject timers, clocks, and loggers instead of patching globals or private members.
|
||||||
|
- A bug fix gets a regression test for the behavior that broke, named after the
|
||||||
|
behavior, not the ticket.
|
||||||
|
|
||||||
|
## Known Debt
|
||||||
|
|
||||||
|
- `src/main/main-wiring.test.ts` and `src/renderer/renderer-init-order.test.ts` still
|
||||||
|
regex `main.ts` / `renderer.ts` to guard startup ordering. Replace each test with a
|
||||||
|
behavioral one as the logic moves out of `main.ts` closures.
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
# Verification
|
# Verification
|
||||||
|
|
||||||
Status: active
|
Status: active
|
||||||
Last verified: 2026-08-13
|
Last verified: 2026-10-05
|
||||||
Owner: Kyle Yasuda
|
Owner: Kyle Yasuda
|
||||||
Read when: selecting the right verification lane for a change
|
Read when: selecting the right verification lane for a change
|
||||||
|
|
||||||
@@ -14,8 +14,9 @@ Read when: selecting the right verification lane for a change
|
|||||||
files in `package.json`.
|
files in `package.json`.
|
||||||
- `scripts/run-test-lane.mjs` runs each test file in its own `bun test` process
|
- `scripts/run-test-lane.mjs` runs each test file in its own `bun test` process
|
||||||
(per-file isolation with a wall timeout) so a hanging test or leaked global in
|
(per-file isolation with a wall timeout) so a hanging test or leaked global in
|
||||||
one file cannot cascade into the rest of the lane. `--jobs N` parallelizes;
|
one file cannot cascade into the rest of the lane. Files run in parallel, one
|
||||||
`--single-process` restores the shared-process mode for debugging.
|
worker per CPU by default; `--jobs 1` runs serially and `--single-process`
|
||||||
|
restores the shared-process mode for debugging.
|
||||||
- `bun run test:fast` is the full source gate: discovered `src/**`, launcher
|
- `bun run test:fast` is the full source gate: discovered `src/**`, launcher
|
||||||
unit, and `scripts/**`.
|
unit, and `scripts/**`.
|
||||||
- `.github/workflows/quality-gate.yml` is the reusable `workflow_call` gate for
|
- `.github/workflows/quality-gate.yml` is the reusable `workflow_call` gate for
|
||||||
@@ -57,6 +58,8 @@ bun run docs:build
|
|||||||
- Launcher/plugin: `bun run test:launcher` or `bun run test:env`
|
- Launcher/plugin: `bun run test:launcher` or `bun run test:env`
|
||||||
- Runtime-compat / compiled behavior after `bun run build`: `bun run test:runtime:compat`
|
- Runtime-compat / compiled behavior after `bun run build`: `bun run test:runtime:compat`
|
||||||
- Stats dashboard UI: `bun run test:stats`
|
- Stats dashboard UI: `bun run test:stats`
|
||||||
|
- Overlay, renderer, mpv, or mining behavior that unit tests cannot show: `bun run build`,
|
||||||
|
then `bun run test:e2e` (see [Headless End-to-End Harness](#headless-end-to-end-harness))
|
||||||
- Build/release scripts (`scripts/**`): `bun run test:scripts`
|
- Build/release scripts (`scripts/**`): `bun run test:scripts`
|
||||||
- Packaging: build the platform package, then run `bun run test:package <resources-directory>`.
|
- Packaging: build the platform package, then run `bun run test:package <resources-directory>`.
|
||||||
On headless Linux: `xvfb-run -a bun run test:package release/linux-unpacked/resources`.
|
On headless Linux: `xvfb-run -a bun run test:package release/linux-unpacked/resources`.
|
||||||
@@ -70,7 +73,7 @@ bun run docs:build
|
|||||||
|
|
||||||
- `bun run test:coverage:src` runs the same discovered `bun-src-full` membership as
|
- `bun run test:coverage:src` runs the same discovered `bun-src-full` membership as
|
||||||
`test:src` through a sharded coverage runner: one Bun coverage process per test
|
`test:src` through a sharded coverage runner: one Bun coverage process per test
|
||||||
file, then merged LCOV output.
|
file (parallel, one per CPU unless `--jobs N`), then merged LCOV output.
|
||||||
- A failing coverage shard stops the runner with a nonzero status. Coverage is a
|
- A failing coverage shard stops the runner with a nonzero status. Coverage is a
|
||||||
source test gate, not a report-only step.
|
source test gate, not a report-only step.
|
||||||
- Machine-readable output lands at `coverage/test-src/lcov.info`.
|
- Machine-readable output lands at `coverage/test-src/lcov.info`.
|
||||||
@@ -92,6 +95,54 @@ bun run docs:build
|
|||||||
- This is not a full Electron UI startup check. It does not require a display and
|
- This is not a full Electron UI startup check. It does not require a display and
|
||||||
makes no claims about renderer, window, tray, or mpv behavior.
|
makes no claims about renderer, window, tray, or mpv behavior.
|
||||||
|
|
||||||
|
## Headless End-to-End Harness
|
||||||
|
|
||||||
|
`bun run test:e2e` boots the built app against a real mpv and asserts on what the
|
||||||
|
overlay renders and what reaches AnkiConnect. Use it instead of a live desktop test
|
||||||
|
whenever the behavior does not depend on a specific compositor.
|
||||||
|
|
||||||
|
- Needs an existing `bun run build`, plus `mpv` and `ffmpeg` on `PATH` (and `Xvfb` on
|
||||||
|
Linux). It is not part of `test:fast` or the handoff gate. The `e2e` job in
|
||||||
|
`.github/workflows/ci.yml` runs it on Linux, macOS, and Windows for pull requests and
|
||||||
|
`main`, outside the reusable quality gate, and uploads the session logs when it fails.
|
||||||
|
- Every run is sandboxed in a temp dir: its own config and Electron profile, mpv IPC
|
||||||
|
socket, and a fake AnkiConnect on a free port. It never touches the user's running
|
||||||
|
SubMiner, Anki, or stats database. It is not offline: the app still asks AniList for
|
||||||
|
cover art matching the clip's title.
|
||||||
|
- Media is synthetic: an ffmpeg test-pattern clip, a three-cue Japanese `.srt`, and a
|
||||||
|
tiny Yomitan dictionary covering those cues (`e2e/harness/fixtures.ts`). The harness
|
||||||
|
imports the dictionary on a first boot, then restarts the app for the scenario.
|
||||||
|
- Display: Linux runs everything inside a private Xvfb server, so no window reaches the
|
||||||
|
desktop. macOS and Windows have no offscreen display server, so windows open in the
|
||||||
|
current session there; `SUBMINER_E2E_DISPLAY=host` forces the same on Linux. The
|
||||||
|
CI job runs all three. On macOS and Windows the app pre-creates a hidden modal window
|
||||||
|
that loads the same renderer document, so window matching must include the
|
||||||
|
`layer=visible` query (`OVERLAY_PAGE`).
|
||||||
|
- The app is driven over the Chrome DevTools Protocol (DOM queries, input events,
|
||||||
|
per-window screenshots), mpv over its JSON IPC socket, and app commands through the
|
||||||
|
normal CLI handoff (`--mine-sentence`, `--toggle-subtitle-sidebar`, ...).
|
||||||
|
- Scenarios live in `e2e/*.e2e.test.ts` and share one session per file through
|
||||||
|
`startE2eSession()`. Pass `config` to override settings for a scenario file.
|
||||||
|
- On a failed startup the temp dir is kept and its path is in the error. Set
|
||||||
|
`SUBMINER_E2E_KEEP=1` to keep it after any run (`app-stdio.log`, `app.log`, `mpv.log`).
|
||||||
|
|
||||||
|
For exploratory checks, keep one session up and poke at it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run e2e start & # prints the session JSON, stays up until stopped
|
||||||
|
bun run e2e mpv seek 2 absolute+exact
|
||||||
|
bun run e2e eval overlay 'document.getElementById("subtitleRoot").textContent'
|
||||||
|
bun run e2e shot overlay /tmp/overlay.png
|
||||||
|
bun run e2e app --mine-sentence
|
||||||
|
bun run e2e anki # AnkiConnect requests received so far
|
||||||
|
bun run e2e stop
|
||||||
|
```
|
||||||
|
|
||||||
|
Out of scope: compositor-specific behavior (Hyprland placement, stacking, fullscreen,
|
||||||
|
click-through), real GPU video output, and global shortcuts. Xvfb runs without a window
|
||||||
|
manager or compositor, so the transparent overlay is not composited over the video;
|
||||||
|
check overlay visuals with per-window screenshots, and use the live desktop for the rest.
|
||||||
|
|
||||||
## Dependency Audit Policy
|
## Dependency Audit Policy
|
||||||
|
|
||||||
- `bun audit --audit-level high` blocks the reusable quality gate.
|
- `bun audit --audit-level high` blocks the reusable quality gate.
|
||||||
|
|||||||
+160
@@ -0,0 +1,160 @@
|
|||||||
|
// Keeps one isolated e2e session running so a change can be poked at by hand
|
||||||
|
// (or by an agent) without touching the real desktop:
|
||||||
|
//
|
||||||
|
// bun run e2e start boot and stay up until `stop` or Ctrl-C
|
||||||
|
// bun run e2e eval <page> <expression> evaluate JS in a window (or "main" for the main process)
|
||||||
|
// bun run e2e shot <page> <file.png> save a screenshot of a window
|
||||||
|
// bun run e2e mpv <command> [args...] send an mpv IPC command (args parsed as JSON)
|
||||||
|
// bun run e2e app <args...> run a SubMiner CLI command against the instance
|
||||||
|
// bun run e2e anki print the AnkiConnect requests received so far
|
||||||
|
// bun run e2e stop
|
||||||
|
//
|
||||||
|
// <page> is a URL fragment: "overlay" is shorthand for the overlay window.
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { connectCdp, connectCdpPage, listCdpTargets } from './harness/cdp';
|
||||||
|
import { connectMpv } from './harness/mpv';
|
||||||
|
import { OVERLAY_PAGE, runAppCommand, startE2eSession, type AppTarget } from './harness/session';
|
||||||
|
import { waitUntil } from './harness/wait';
|
||||||
|
|
||||||
|
type SessionState = {
|
||||||
|
pid: number;
|
||||||
|
root: string;
|
||||||
|
display: string;
|
||||||
|
cdpPort: number;
|
||||||
|
inspectorUrl: string;
|
||||||
|
mpvSocketPath: string;
|
||||||
|
ankiUrl: string;
|
||||||
|
target: AppTarget;
|
||||||
|
};
|
||||||
|
|
||||||
|
const stateFile = path.join(os.tmpdir(), 'subminer-e2e-session.json');
|
||||||
|
|
||||||
|
function readState(): SessionState {
|
||||||
|
if (!fs.existsSync(stateFile)) {
|
||||||
|
throw new Error('No e2e session is running. Start one with `bun run e2e start`.');
|
||||||
|
}
|
||||||
|
return JSON.parse(fs.readFileSync(stateFile, 'utf8')) as SessionState;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAlive(pid: number): boolean {
|
||||||
|
try {
|
||||||
|
process.kill(pid, 0);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJsonOrString(value: string): unknown {
|
||||||
|
try {
|
||||||
|
return JSON.parse(value);
|
||||||
|
} catch {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function connectNamedPage(state: SessionState, pageName: string) {
|
||||||
|
if (pageName === 'main') return connectCdp(state.inspectorUrl, 'main process');
|
||||||
|
const urlPart = pageName === 'overlay' ? OVERLAY_PAGE : pageName;
|
||||||
|
const targets = await listCdpTargets(state.cdpPort);
|
||||||
|
const target = targets.find((candidate) => candidate.url.includes(urlPart));
|
||||||
|
if (!target) {
|
||||||
|
const open = targets.map((candidate) => ` ${candidate.type} ${candidate.url.slice(0, 100)}`);
|
||||||
|
throw new Error(`No window matches "${pageName}". Open targets:\n${open.join('\n')}`);
|
||||||
|
}
|
||||||
|
return connectCdpPage(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function withPage<T>(
|
||||||
|
state: SessionState,
|
||||||
|
pageName: string,
|
||||||
|
use: (page: Awaited<ReturnType<typeof connectCdpPage>>) => Promise<T>,
|
||||||
|
): Promise<T> {
|
||||||
|
const page = await connectNamedPage(state, pageName);
|
||||||
|
try {
|
||||||
|
return await use(page);
|
||||||
|
} finally {
|
||||||
|
page.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function start(): Promise<void> {
|
||||||
|
if (fs.existsSync(stateFile) && isAlive(readState().pid)) {
|
||||||
|
throw new Error('An e2e session is already running. Stop it with `bun run e2e stop`.');
|
||||||
|
}
|
||||||
|
const session = await startE2eSession();
|
||||||
|
const state: SessionState = {
|
||||||
|
pid: process.pid,
|
||||||
|
root: session.root,
|
||||||
|
display: session.display,
|
||||||
|
cdpPort: session.cdpPort,
|
||||||
|
inspectorUrl: session.inspectorUrl,
|
||||||
|
mpvSocketPath: session.mpvSocketPath,
|
||||||
|
ankiUrl: session.anki.url,
|
||||||
|
target: session.target,
|
||||||
|
};
|
||||||
|
// The state file grants main-process code evaluation via inspectorUrl, so keep it
|
||||||
|
// owner-only. 'wx' creates it exclusively: it fails rather than follow a symlink
|
||||||
|
// planted in the shared temp dir after the stale file is removed.
|
||||||
|
fs.rmSync(stateFile, { force: true });
|
||||||
|
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2), { mode: 0o600, flag: 'wx' });
|
||||||
|
console.log(JSON.stringify(state, null, 2));
|
||||||
|
|
||||||
|
await new Promise<void>((resolve) => {
|
||||||
|
process.once('SIGINT', resolve);
|
||||||
|
process.once('SIGTERM', resolve);
|
||||||
|
});
|
||||||
|
fs.rmSync(stateFile, { force: true });
|
||||||
|
await session.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
const [command, ...args] = process.argv.slice(2);
|
||||||
|
if (command === 'start') return start();
|
||||||
|
|
||||||
|
const state = readState();
|
||||||
|
switch (command) {
|
||||||
|
case 'eval': {
|
||||||
|
const [pageName, expression] = args;
|
||||||
|
if (!pageName || !expression) throw new Error('Usage: eval <page> <expression>');
|
||||||
|
const value = await withPage(state, pageName, (page) => page.evaluate<unknown>(expression));
|
||||||
|
console.log(JSON.stringify(value, null, 2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 'shot': {
|
||||||
|
const [pageName, outputPath] = args;
|
||||||
|
if (!pageName || !outputPath) throw new Error('Usage: shot <page> <file.png>');
|
||||||
|
fs.writeFileSync(outputPath, await withPage(state, pageName, (page) => page.screenshot()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 'mpv': {
|
||||||
|
if (args.length === 0) throw new Error('Usage: mpv <command> [args...]');
|
||||||
|
const mpv = await connectMpv(state.mpvSocketPath);
|
||||||
|
try {
|
||||||
|
console.log(JSON.stringify((await mpv.command(...args.map(parseJsonOrString))) ?? null));
|
||||||
|
} finally {
|
||||||
|
mpv.close();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 'app':
|
||||||
|
await runAppCommand(state.target, args);
|
||||||
|
return;
|
||||||
|
case 'anki':
|
||||||
|
console.log(JSON.stringify(await (await fetch(state.ankiUrl)).json(), null, 2));
|
||||||
|
return;
|
||||||
|
case 'stop':
|
||||||
|
process.kill(state.pid, 'SIGTERM');
|
||||||
|
await waitUntil(() => !isAlive(state.pid), { description: 'e2e session to exit' });
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown command "${command ?? ''}". See the header of e2e/cli.ts.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch((error: unknown) => {
|
||||||
|
console.error(error instanceof Error ? error.message : error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
import { waitUntil, type Truthy, type WaitOptions } from './wait';
|
||||||
|
|
||||||
|
export type CdpTarget = {
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
webSocketDebuggerUrl: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type CdpPage = {
|
||||||
|
/** Sends a raw DevTools protocol command, for anything the helpers below do not cover. */
|
||||||
|
send: (method: string, params?: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
||||||
|
/** Evaluates an expression in the page, awaiting promises, and returns its JSON value. */
|
||||||
|
evaluate: <T>(expression: string) => Promise<T>;
|
||||||
|
/** Polls an expression until it is truthy and returns that value. */
|
||||||
|
waitFor: <T>(expression: string, options: WaitOptions) => Promise<Truthy<T>>;
|
||||||
|
/** Console output and uncaught exceptions seen since connecting, oldest first. */
|
||||||
|
console: string[];
|
||||||
|
/** PNG of the page as rendered by Chromium; needs no OS screen-capture permission. */
|
||||||
|
screenshot: () => Promise<Buffer>;
|
||||||
|
close: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type CdpReply = {
|
||||||
|
id?: number;
|
||||||
|
method?: string;
|
||||||
|
params?: Record<string, unknown>;
|
||||||
|
error?: { message: string };
|
||||||
|
result?: Record<string, unknown>;
|
||||||
|
};
|
||||||
|
|
||||||
|
type RemoteObject = { value?: unknown; description?: string };
|
||||||
|
|
||||||
|
// Renders a console/exception event as one log line.
|
||||||
|
function formatConsoleEvent(method: string, params: Record<string, unknown>): string | null {
|
||||||
|
if (method === 'Runtime.consoleAPICalled') {
|
||||||
|
const args = Array.isArray(params.args) ? (params.args as RemoteObject[]) : [];
|
||||||
|
const text = args.map((arg) => arg.description ?? JSON.stringify(arg.value)).join(' ');
|
||||||
|
return `console.${String(params.type)}: ${text}`;
|
||||||
|
}
|
||||||
|
if (method === 'Runtime.exceptionThrown') {
|
||||||
|
const details = params.exceptionDetails as
|
||||||
|
| { text?: string; exception?: RemoteObject }
|
||||||
|
| undefined;
|
||||||
|
return `exception: ${details?.exception?.description ?? details?.text ?? 'unknown'}`;
|
||||||
|
}
|
||||||
|
if (method === 'Log.entryAdded') {
|
||||||
|
const entry = params.entry as { level?: string; source?: string; text?: string } | undefined;
|
||||||
|
return `${String(entry?.source)}.${String(entry?.level)}: ${String(entry?.text)}`;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
type EvaluateResult = {
|
||||||
|
result: { value?: unknown };
|
||||||
|
exceptionDetails?: { text: string; exception?: { description?: string } };
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function listCdpTargets(port: number): Promise<CdpTarget[]> {
|
||||||
|
const response = await fetch(`http://127.0.0.1:${port}/json/list`);
|
||||||
|
return (await response.json()) as CdpTarget[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function connectCdpPage(target: CdpTarget): Promise<CdpPage> {
|
||||||
|
return connectCdp(target.webSocketDebuggerUrl, target.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Connects to any DevTools endpoint: a renderer page or Electron's main-process inspector. */
|
||||||
|
export async function connectCdp(webSocketDebuggerUrl: string, label: string): Promise<CdpPage> {
|
||||||
|
const socket = new WebSocket(webSocketDebuggerUrl);
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
socket.addEventListener('open', () => resolve(), { once: true });
|
||||||
|
socket.addEventListener('error', () => reject(new Error(`CDP connection to ${label} failed`)), {
|
||||||
|
once: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const pending = new Map<number, (reply: CdpReply) => void>();
|
||||||
|
const consoleLines: string[] = [];
|
||||||
|
let nextId = 1;
|
||||||
|
socket.addEventListener('message', (event) => {
|
||||||
|
const reply: CdpReply = JSON.parse(String(event.data));
|
||||||
|
if (reply.id === undefined) {
|
||||||
|
if (reply.method) {
|
||||||
|
const line = formatConsoleEvent(reply.method, reply.params ?? {});
|
||||||
|
if (line) consoleLines.push(line);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pending.get(reply.id)?.(reply);
|
||||||
|
pending.delete(reply.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
const send = (method: string, params: Record<string, unknown> = {}) =>
|
||||||
|
new Promise<Record<string, unknown>>((resolve, reject) => {
|
||||||
|
const id = nextId++;
|
||||||
|
pending.set(id, (reply) => {
|
||||||
|
if (reply.error) reject(new Error(`CDP ${method} failed: ${reply.error.message}`));
|
||||||
|
else resolve(reply.result ?? {});
|
||||||
|
});
|
||||||
|
socket.send(JSON.stringify({ id, method, params }));
|
||||||
|
});
|
||||||
|
|
||||||
|
const evaluate = async <T>(expression: string): Promise<T> => {
|
||||||
|
const reply = (await send('Runtime.evaluate', {
|
||||||
|
expression,
|
||||||
|
returnByValue: true,
|
||||||
|
awaitPromise: true,
|
||||||
|
})) as EvaluateResult;
|
||||||
|
if (reply.exceptionDetails) {
|
||||||
|
const { text, exception } = reply.exceptionDetails;
|
||||||
|
throw new Error(`Page evaluation threw: ${exception?.description ?? text}`);
|
||||||
|
}
|
||||||
|
return reply.result.value as T;
|
||||||
|
};
|
||||||
|
|
||||||
|
await send('Runtime.enable');
|
||||||
|
// The Node inspector behind Electron's main process has no Log domain.
|
||||||
|
await send('Log.enable').catch(() => undefined);
|
||||||
|
|
||||||
|
return {
|
||||||
|
send,
|
||||||
|
evaluate,
|
||||||
|
console: consoleLines,
|
||||||
|
waitFor: <T>(expression: string, options: WaitOptions) =>
|
||||||
|
waitUntil(() => evaluate<T>(expression), options),
|
||||||
|
screenshot: async () => {
|
||||||
|
const reply = await send('Page.captureScreenshot', { format: 'png' });
|
||||||
|
return Buffer.from(String(reply.data), 'base64');
|
||||||
|
},
|
||||||
|
close: () => socket.close(),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { spawn } from 'node:child_process';
|
||||||
|
import { once } from 'node:events';
|
||||||
|
import { stopProcess, type EnvDelta } from './process';
|
||||||
|
|
||||||
|
export const E2E_SCREEN = { width: 1280, height: 720 } as const;
|
||||||
|
|
||||||
|
export type E2eDisplay = {
|
||||||
|
kind: 'xvfb' | 'host';
|
||||||
|
env: EnvDelta;
|
||||||
|
stop: () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Linux gets a private Xvfb server so no window ever reaches the real desktop.
|
||||||
|
// macOS and Windows have no offscreen display server, so windows open in the
|
||||||
|
// current GUI session there. SUBMINER_E2E_DISPLAY=host forces that on Linux too.
|
||||||
|
export async function startDisplay(): Promise<E2eDisplay> {
|
||||||
|
const requested = process.env.SUBMINER_E2E_DISPLAY?.trim().toLowerCase();
|
||||||
|
if (requested && requested !== 'host' && requested !== 'xvfb') {
|
||||||
|
throw new Error(`SUBMINER_E2E_DISPLAY must be "host" or "xvfb", got "${requested}"`);
|
||||||
|
}
|
||||||
|
const kind = requested ?? (process.platform === 'linux' ? 'xvfb' : 'host');
|
||||||
|
if (kind === 'host') {
|
||||||
|
return { kind, env: { set: {}, unset: [] }, stop: async () => {} };
|
||||||
|
}
|
||||||
|
return startXvfb();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startXvfb(): Promise<E2eDisplay> {
|
||||||
|
// -displayfd makes Xvfb pick a free display number and write it to fd 3 once
|
||||||
|
// it accepts connections, so there is no port guessing and no startup sleep.
|
||||||
|
const child = spawn(
|
||||||
|
'Xvfb',
|
||||||
|
[
|
||||||
|
'-displayfd',
|
||||||
|
'3',
|
||||||
|
'-screen',
|
||||||
|
'0',
|
||||||
|
`${E2E_SCREEN.width}x${E2E_SCREEN.height}x24`,
|
||||||
|
'-nolisten',
|
||||||
|
'tcp',
|
||||||
|
],
|
||||||
|
{ stdio: ['ignore', 'ignore', 'ignore', 'pipe'] },
|
||||||
|
);
|
||||||
|
const displayFd = child.stdio[3];
|
||||||
|
if (!displayFd) throw new Error('Xvfb did not expose its display fd');
|
||||||
|
|
||||||
|
const displayNumber = await Promise.race([
|
||||||
|
once(displayFd, 'data').then(([chunk]) => String(chunk).trim()),
|
||||||
|
once(child, 'error').then(([error]) => {
|
||||||
|
throw new Error(
|
||||||
|
`Could not start Xvfb (${String(error)}). Install it or set SUBMINER_E2E_DISPLAY=host.`,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
once(child, 'exit').then(([code]) => {
|
||||||
|
throw new Error(`Xvfb exited during startup with code ${String(code)}`);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
kind: 'xvfb',
|
||||||
|
env: {
|
||||||
|
set: { DISPLAY: `:${displayNumber}`, XDG_SESSION_TYPE: 'x11' },
|
||||||
|
// Without these the app and mpv would pick the real Wayland session, or
|
||||||
|
// take the compositor-specific code paths of the desktop running the tests.
|
||||||
|
unset: [
|
||||||
|
'WAYLAND_DISPLAY',
|
||||||
|
'HYPRLAND_INSTANCE_SIGNATURE',
|
||||||
|
'SWAYSOCK',
|
||||||
|
'XDG_CURRENT_DESKTOP',
|
||||||
|
'XDG_SESSION_DESKTOP',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
stop: () => stopProcess(child),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import { once } from 'node:events';
|
||||||
|
import http from 'node:http';
|
||||||
|
import type { AddressInfo } from 'node:net';
|
||||||
|
|
||||||
|
export type AnkiRequest = { action: string; params: Record<string, unknown> };
|
||||||
|
|
||||||
|
export type FakeAnki = {
|
||||||
|
url: string;
|
||||||
|
/** Every AnkiConnect action received so far, with `multi` batches flattened. */
|
||||||
|
requests: AnkiRequest[];
|
||||||
|
stop: () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const FAKE_ANKI_DECK = 'E2E';
|
||||||
|
export const FAKE_ANKI_MODEL = 'Lapis';
|
||||||
|
|
||||||
|
const MODEL_FIELDS = [
|
||||||
|
'Expression',
|
||||||
|
'ExpressionFurigana',
|
||||||
|
'ExpressionReading',
|
||||||
|
'ExpressionAudio',
|
||||||
|
'SelectionText',
|
||||||
|
'MainDefinition',
|
||||||
|
'Sentence',
|
||||||
|
'SentenceFurigana',
|
||||||
|
'SentenceAudio',
|
||||||
|
'Picture',
|
||||||
|
'Glossary',
|
||||||
|
'IsWordAndSentenceCard',
|
||||||
|
'IsClickCard',
|
||||||
|
'IsSentenceCard',
|
||||||
|
'IsAudioCard',
|
||||||
|
'MiscInfo',
|
||||||
|
];
|
||||||
|
|
||||||
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A recording AnkiConnect stand-in: an empty collection with one deck and one
|
||||||
|
// Lapis-shaped note type. Scenarios assert on `requests`, not on stored notes.
|
||||||
|
export async function startFakeAnki(): Promise<FakeAnki> {
|
||||||
|
const requests: AnkiRequest[] = [];
|
||||||
|
let nextNoteId = 1000;
|
||||||
|
|
||||||
|
const handle = (body: unknown): unknown => {
|
||||||
|
if (!isRecord(body) || typeof body.action !== 'string') return null;
|
||||||
|
const params = isRecord(body.params) ? body.params : {};
|
||||||
|
if (body.action === 'multi') {
|
||||||
|
return Array.isArray(params.actions) ? params.actions.map(handle) : [];
|
||||||
|
}
|
||||||
|
requests.push({ action: body.action, params });
|
||||||
|
switch (body.action) {
|
||||||
|
case 'version':
|
||||||
|
return 6;
|
||||||
|
case 'deckNames':
|
||||||
|
return [FAKE_ANKI_DECK];
|
||||||
|
case 'modelNames':
|
||||||
|
return [FAKE_ANKI_MODEL];
|
||||||
|
case 'modelFieldNames':
|
||||||
|
return MODEL_FIELDS;
|
||||||
|
case 'addNote':
|
||||||
|
return nextNoteId++;
|
||||||
|
case 'findNotes':
|
||||||
|
case 'notesInfo':
|
||||||
|
return [];
|
||||||
|
case 'storeMediaFile':
|
||||||
|
return params.filename ?? null;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const server = http.createServer((request, response) => {
|
||||||
|
response.setHeader('content-type', 'application/json');
|
||||||
|
// GET exposes the request log so the session CLI can read it from outside.
|
||||||
|
if (request.method === 'GET') {
|
||||||
|
response.end(JSON.stringify(requests));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const chunks: Buffer[] = [];
|
||||||
|
request.on('data', (chunk: Buffer) => chunks.push(chunk));
|
||||||
|
request.on('end', () => {
|
||||||
|
let body: unknown = null;
|
||||||
|
try {
|
||||||
|
body = JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
||||||
|
} catch {
|
||||||
|
// Malformed bodies get the same null result AnkiConnect gives unknown actions.
|
||||||
|
}
|
||||||
|
response.end(JSON.stringify({ result: handle(body), error: null }));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
server.listen(0, '127.0.0.1');
|
||||||
|
await once(server, 'listening');
|
||||||
|
const { port } = server.address() as AddressInfo;
|
||||||
|
|
||||||
|
return {
|
||||||
|
url: `http://127.0.0.1:${port}`,
|
||||||
|
requests,
|
||||||
|
stop: async () => {
|
||||||
|
server.closeAllConnections();
|
||||||
|
server.close();
|
||||||
|
await once(server, 'close');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { execFile } from 'node:child_process';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import { promisify } from 'node:util';
|
||||||
|
import { writeStoredZipAsync } from '../../src/shared/stored-zip';
|
||||||
|
|
||||||
|
const execFileAsync = promisify(execFile);
|
||||||
|
|
||||||
|
export const FIXTURE_DICTIONARY_TITLE = 'SubMiner E2E Fixture';
|
||||||
|
export const FIXTURE_CLIP_SECONDS = 15;
|
||||||
|
|
||||||
|
/** Cues of the synthetic clip. Seek to `at` to land inside a cue. */
|
||||||
|
export const FIXTURE_CUES = [
|
||||||
|
{ start: 1, end: 4, at: 2, text: '今日はいい天気ですね。' },
|
||||||
|
{ start: 5, end: 8, at: 6, text: '猫が好きです。' },
|
||||||
|
{ start: 9, end: 12, at: 10, text: '明日は学校に行きます。' },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
// [term, reading, part of speech, gloss] for every content word in FIXTURE_CUES.
|
||||||
|
const FIXTURE_TERMS = [
|
||||||
|
['今日', 'きょう', 'n', 'today'],
|
||||||
|
['いい', 'いい', 'adj-i', 'good'],
|
||||||
|
['天気', 'てんき', 'n', 'weather'],
|
||||||
|
['猫', 'ねこ', 'n', 'cat'],
|
||||||
|
['好き', 'すき', 'adj-na', 'liked'],
|
||||||
|
['明日', 'あした', 'n', 'tomorrow'],
|
||||||
|
['学校', 'がっこう', 'n', 'school'],
|
||||||
|
['行く', 'いく', 'v5', 'to go'],
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
function srtTimestamp(seconds: number): string {
|
||||||
|
return `00:00:${String(seconds).padStart(2, '0')},000`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function writeFixtureSubtitles(outputPath: string): void {
|
||||||
|
const blocks = FIXTURE_CUES.map(
|
||||||
|
(cue, index) =>
|
||||||
|
`${index + 1}\n${srtTimestamp(cue.start)} --> ${srtTimestamp(cue.end)}\n${cue.text}\n`,
|
||||||
|
);
|
||||||
|
fs.writeFileSync(outputPath, blocks.join('\n'), 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renders a deterministic test-pattern clip with a sine tone, so no real media is needed. */
|
||||||
|
export async function generateFixtureClip(outputPath: string): Promise<void> {
|
||||||
|
await execFileAsync('ffmpeg', [
|
||||||
|
'-nostdin',
|
||||||
|
'-v',
|
||||||
|
'error',
|
||||||
|
'-y',
|
||||||
|
'-f',
|
||||||
|
'lavfi',
|
||||||
|
'-i',
|
||||||
|
`testsrc2=size=640x360:rate=24:duration=${FIXTURE_CLIP_SECONDS}`,
|
||||||
|
'-f',
|
||||||
|
'lavfi',
|
||||||
|
'-i',
|
||||||
|
`sine=frequency=440:duration=${FIXTURE_CLIP_SECONDS}`,
|
||||||
|
'-c:v',
|
||||||
|
'libx264',
|
||||||
|
'-preset',
|
||||||
|
'ultrafast',
|
||||||
|
'-pix_fmt',
|
||||||
|
'yuv420p',
|
||||||
|
'-c:a',
|
||||||
|
'aac',
|
||||||
|
outputPath,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Writes a minimal Yomitan term dictionary so the tokenizer has real entries to match. */
|
||||||
|
export async function buildFixtureDictionary(outputPath: string): Promise<void> {
|
||||||
|
const index = {
|
||||||
|
title: FIXTURE_DICTIONARY_TITLE,
|
||||||
|
revision: '1',
|
||||||
|
format: 3,
|
||||||
|
author: 'SubMiner',
|
||||||
|
description: 'Synthetic dictionary for the e2e harness.',
|
||||||
|
};
|
||||||
|
const termBank = FIXTURE_TERMS.map(([term, reading, partOfSpeech, gloss], sequence) => [
|
||||||
|
term,
|
||||||
|
reading,
|
||||||
|
'',
|
||||||
|
partOfSpeech,
|
||||||
|
0,
|
||||||
|
[gloss],
|
||||||
|
sequence + 1,
|
||||||
|
'',
|
||||||
|
]);
|
||||||
|
await writeStoredZipAsync(outputPath, [
|
||||||
|
{ name: 'index.json', data: Buffer.from(JSON.stringify(index), 'utf8') },
|
||||||
|
{ name: 'term_bank_1.json', data: Buffer.from(JSON.stringify(termBank), 'utf8') },
|
||||||
|
]);
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import { spawn, type ChildProcess } from 'node:child_process';
|
||||||
|
import { once } from 'node:events';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import net from 'node:net';
|
||||||
|
import type { E2eDisplay } from './display';
|
||||||
|
import { E2E_SCREEN } from './display';
|
||||||
|
import { applyEnvDelta } from './process';
|
||||||
|
import { waitUntil } from './wait';
|
||||||
|
|
||||||
|
export type MpvClient = {
|
||||||
|
/** Sends one mpv JSON IPC command and resolves with its `data` field. */
|
||||||
|
command: (...args: unknown[]) => Promise<unknown>;
|
||||||
|
close: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
type MpvReply = { request_id?: number; error?: string; data?: unknown };
|
||||||
|
|
||||||
|
export async function startMpv(options: {
|
||||||
|
socketPath: string;
|
||||||
|
mediaPath: string;
|
||||||
|
subtitlePath: string;
|
||||||
|
logPath: string;
|
||||||
|
display: E2eDisplay;
|
||||||
|
}): Promise<ChildProcess> {
|
||||||
|
const log = fs.openSync(options.logPath, 'w');
|
||||||
|
const child = spawn(
|
||||||
|
'mpv',
|
||||||
|
[
|
||||||
|
'--no-config',
|
||||||
|
'--no-terminal',
|
||||||
|
'--pause',
|
||||||
|
'--keep-open=yes',
|
||||||
|
'--ao=null',
|
||||||
|
`--geometry=${E2E_SCREEN.width}x${E2E_SCREEN.height}+0+0`,
|
||||||
|
// Xvfb has no GPU; the software X11 output always works there.
|
||||||
|
...(options.display.kind === 'xvfb' ? ['--vo=x11'] : []),
|
||||||
|
`--input-ipc-server=${options.socketPath}`,
|
||||||
|
`--sub-file=${options.subtitlePath}`,
|
||||||
|
options.mediaPath,
|
||||||
|
],
|
||||||
|
{ env: applyEnvDelta(process.env, options.display.env), stdio: ['ignore', log, log] },
|
||||||
|
);
|
||||||
|
fs.closeSync(log);
|
||||||
|
await Promise.race([
|
||||||
|
once(child, 'spawn'),
|
||||||
|
once(child, 'error').then(([error]) => {
|
||||||
|
throw new Error(`Could not start mpv (${String(error)}). Is it on PATH?`);
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tryConnect(socketPath: string): Promise<net.Socket | null> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
const socket = net.connect(socketPath);
|
||||||
|
socket.once('connect', () => resolve(socket));
|
||||||
|
socket.once('error', () => resolve(null));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function connectMpv(socketPath: string): Promise<MpvClient> {
|
||||||
|
const socket = await waitUntil(() => tryConnect(socketPath), {
|
||||||
|
description: `mpv IPC socket ${socketPath}`,
|
||||||
|
});
|
||||||
|
const pending = new Map<number, (reply: MpvReply) => void>();
|
||||||
|
let nextRequestId = 1;
|
||||||
|
let buffer = '';
|
||||||
|
|
||||||
|
socket.setEncoding('utf8');
|
||||||
|
socket.on('data', (chunk: string) => {
|
||||||
|
buffer += chunk;
|
||||||
|
const lines = buffer.split('\n');
|
||||||
|
buffer = lines.pop() ?? '';
|
||||||
|
for (const line of lines) {
|
||||||
|
if (!line.trim()) continue;
|
||||||
|
const reply: MpvReply = JSON.parse(line);
|
||||||
|
if (reply.request_id === undefined) continue;
|
||||||
|
pending.get(reply.request_id)?.(reply);
|
||||||
|
pending.delete(reply.request_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
command: (...args) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
const requestId = nextRequestId++;
|
||||||
|
pending.set(requestId, (reply) => {
|
||||||
|
if (reply.error === 'success') resolve(reply.data);
|
||||||
|
else reject(new Error(`mpv ${JSON.stringify(args)} failed: ${reply.error}`));
|
||||||
|
});
|
||||||
|
socket.write(`${JSON.stringify({ command: args, request_id: requestId })}\n`);
|
||||||
|
}),
|
||||||
|
close: () => socket.destroy(),
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import type { ChildProcess } from 'node:child_process';
|
||||||
|
import { once } from 'node:events';
|
||||||
|
|
||||||
|
export type EnvDelta = { set: Record<string, string>; unset: string[] };
|
||||||
|
|
||||||
|
export function applyEnvDelta(base: NodeJS.ProcessEnv, ...deltas: EnvDelta[]): NodeJS.ProcessEnv {
|
||||||
|
const env = { ...base };
|
||||||
|
for (const delta of deltas) {
|
||||||
|
for (const name of delta.unset) delete env[name];
|
||||||
|
Object.assign(env, delta.set);
|
||||||
|
}
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Terminates a child and waits for it to exit, escalating to SIGKILL after `graceMs`. */
|
||||||
|
export async function stopProcess(child: ChildProcess, graceMs = 5_000): Promise<void> {
|
||||||
|
// A child that never spawned (missing binary) has no pid and never emits exit.
|
||||||
|
if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) return;
|
||||||
|
const exited = once(child, 'exit');
|
||||||
|
child.kill();
|
||||||
|
const timer = setTimeout(() => child.kill('SIGKILL'), graceMs);
|
||||||
|
await exited;
|
||||||
|
clearTimeout(timer);
|
||||||
|
}
|
||||||
@@ -0,0 +1,332 @@
|
|||||||
|
import { spawn, type ChildProcess } from 'node:child_process';
|
||||||
|
import { once } from 'node:events';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import { connectCdp, connectCdpPage, listCdpTargets, type CdpPage } from './cdp';
|
||||||
|
import { startDisplay, type E2eDisplay } from './display';
|
||||||
|
import { FAKE_ANKI_DECK, FAKE_ANKI_MODEL, startFakeAnki, type FakeAnki } from './fake-anki';
|
||||||
|
import { buildFixtureDictionary, generateFixtureClip, writeFixtureSubtitles } from './fixtures';
|
||||||
|
import { connectMpv, startMpv, type MpvClient } from './mpv';
|
||||||
|
import { applyEnvDelta, stopProcess, type EnvDelta } from './process';
|
||||||
|
import { waitUntil } from './wait';
|
||||||
|
import {
|
||||||
|
shouldForceX11ElectronBackend,
|
||||||
|
X11_ELECTRON_BOOTSTRAP_ENV,
|
||||||
|
} from '../../src/core/utils/electron-backend';
|
||||||
|
|
||||||
|
const repoRoot = path.resolve(__dirname, '..', '..');
|
||||||
|
|
||||||
|
/** URL fragments identifying the app's windows among the CDP targets. The modal
|
||||||
|
* window loads the same document with `layer=modal`, so the layer is required. */
|
||||||
|
export const OVERLAY_PAGE = 'renderer/index.html?layer=visible';
|
||||||
|
const YOMITAN_SETTINGS_PAGE = 'settings.html';
|
||||||
|
|
||||||
|
type JsonObject = { [key: string]: JsonValue };
|
||||||
|
type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
|
||||||
|
|
||||||
|
export type E2eSessionOptions = {
|
||||||
|
/** Deep-merged over the harness config, for scenarios that need other settings. */
|
||||||
|
config?: JsonObject;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AppTarget = {
|
||||||
|
/** Environment changes that point a process at the isolated instance. */
|
||||||
|
env: EnvDelta;
|
||||||
|
/** Electron/Chromium switches every launch needs. */
|
||||||
|
electronArgs: string[];
|
||||||
|
/** Receives stdout and stderr of every launch. */
|
||||||
|
logPath: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type E2eSession = {
|
||||||
|
/** Temp dir holding the isolated config, fixtures, sockets, and logs. */
|
||||||
|
root: string;
|
||||||
|
display: E2eDisplay['kind'];
|
||||||
|
cdpPort: number;
|
||||||
|
/** DevTools endpoint of the Electron main process (Node inspector). */
|
||||||
|
inspectorUrl: string;
|
||||||
|
mpvSocketPath: string;
|
||||||
|
/** How to start a process that talks to this isolated instance. */
|
||||||
|
target: AppTarget;
|
||||||
|
mpv: MpvClient;
|
||||||
|
anki: FakeAnki;
|
||||||
|
/** Connects to the first window or frame whose URL contains `urlPart`, waiting for it to exist. */
|
||||||
|
openPage: (urlPart: string) => Promise<CdpPage>;
|
||||||
|
/** Evaluates in the main process; reach modules via `process.mainModule.require`. */
|
||||||
|
mainProcess: () => Promise<CdpPage>;
|
||||||
|
/** Runs a CLI command (e.g. `--mine-sentence`) against the running instance. */
|
||||||
|
runAppCommand: (...args: string[]) => Promise<void>;
|
||||||
|
dispose: () => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
function isJsonObject(value: JsonValue | undefined): value is JsonObject {
|
||||||
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeConfig(base: JsonObject, overrides: JsonObject): JsonObject {
|
||||||
|
const merged = { ...base };
|
||||||
|
for (const [key, value] of Object.entries(overrides)) {
|
||||||
|
const existing = merged[key];
|
||||||
|
merged[key] =
|
||||||
|
isJsonObject(existing) && isJsonObject(value) ? mergeConfig(existing, value) : value;
|
||||||
|
}
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything that could reach outside the sandbox (network services, the real
|
||||||
|
// Anki, ports the user's own SubMiner holds) is off or pointed at a fake.
|
||||||
|
function buildConfig(mpvSocketPath: string, ankiUrl: string): JsonObject {
|
||||||
|
return {
|
||||||
|
mpv: { socketPath: mpvSocketPath, aniskipEnabled: false },
|
||||||
|
ankiConnect: {
|
||||||
|
url: ankiUrl,
|
||||||
|
deck: FAKE_ANKI_DECK,
|
||||||
|
proxy: { enabled: false },
|
||||||
|
isLapis: { enabled: true, sentenceCardModel: FAKE_ANKI_MODEL },
|
||||||
|
},
|
||||||
|
stats: { autoStartServer: false },
|
||||||
|
updates: { enabled: false },
|
||||||
|
discordPresence: { enabled: false },
|
||||||
|
websocket: { enabled: false },
|
||||||
|
annotationWebsocket: { enabled: false },
|
||||||
|
texthooker: { launchAtStartup: false },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Outside Electron the package's entry point is the path of its binary, and
|
||||||
|
// resolving it downloads the binary when an install skipped that step (CI).
|
||||||
|
function resolveElectronBinary(): string {
|
||||||
|
const binary: unknown = require('electron');
|
||||||
|
if (typeof binary !== 'string') throw new Error('Could not resolve the Electron binary path');
|
||||||
|
return binary;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Electron announces its main-process inspector on stderr; `offset` skips earlier launches.
|
||||||
|
function readInspectorUrl(logPath: string, byteOffset: number): string | null {
|
||||||
|
const tail = fs.readFileSync(logPath).subarray(byteOffset).toString('utf8');
|
||||||
|
return /Debugger listening on (ws:\/\/\S+)/.exec(tail)?.[1] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readDevToolsPort(portFile: string): number | null {
|
||||||
|
try {
|
||||||
|
const port = Number(fs.readFileSync(portFile, 'utf8').split('\n')[0]);
|
||||||
|
return port > 0 ? port : null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function spawnApp(target: AppTarget, electronArgs: string[], args: string[]): ChildProcess {
|
||||||
|
const log = fs.openSync(target.logPath, 'a');
|
||||||
|
const child = spawn(
|
||||||
|
resolveElectronBinary(),
|
||||||
|
[...target.electronArgs, ...electronArgs, repoRoot, ...args],
|
||||||
|
{ cwd: repoRoot, env: applyEnvDelta(process.env, target.env), stdio: ['ignore', log, log] },
|
||||||
|
);
|
||||||
|
fs.closeSync(log);
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Runs a CLI command against the running instance and waits for it to finish. */
|
||||||
|
export async function runAppCommand(target: AppTarget, args: string[]): Promise<void> {
|
||||||
|
const child = spawnApp(target, [], args);
|
||||||
|
const timer = setTimeout(() => child.kill('SIGKILL'), 30_000);
|
||||||
|
const [code] = await once(child, 'exit');
|
||||||
|
clearTimeout(timer);
|
||||||
|
if (code !== 0) {
|
||||||
|
throw new Error(
|
||||||
|
`SubMiner ${args.join(' ')} exited with ${String(code)}; see ${target.logPath}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openPage(cdpPort: number, urlPart: string): Promise<CdpPage> {
|
||||||
|
const target = await waitUntil(
|
||||||
|
async () =>
|
||||||
|
(await listCdpTargets(cdpPort)).find((candidate) => candidate.url.includes(urlPart)),
|
||||||
|
{ description: `app window matching "${urlPart}"`, timeoutMs: 30_000 },
|
||||||
|
);
|
||||||
|
const page = await connectCdpPage(target);
|
||||||
|
// A target is listed before its document exists; callers expect a usable DOM.
|
||||||
|
await page.waitFor(`document.readyState === "complete"`, {
|
||||||
|
description: `"${urlPart}" document to load`,
|
||||||
|
});
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function startE2eSession(options: E2eSessionOptions = {}): Promise<E2eSession> {
|
||||||
|
if (!fs.existsSync(path.join(repoRoot, 'dist', 'main-entry.js'))) {
|
||||||
|
throw new Error('dist/ is missing. Run `bun run build` before the e2e harness.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-e2e-'));
|
||||||
|
const configHome = path.join(root, 'config');
|
||||||
|
const userDataDir = path.join(configHome, 'SubMiner');
|
||||||
|
const mediaPath = path.join(root, 'clip.mkv');
|
||||||
|
const subtitlePath = path.join(root, 'clip.srt');
|
||||||
|
const dictionaryPath = path.join(root, 'fixture-dictionary.zip');
|
||||||
|
const mpvSocketPath =
|
||||||
|
process.platform === 'win32'
|
||||||
|
? `\\\\.\\pipe\\${path.basename(root)}-mpv`
|
||||||
|
: path.join(root, 'mpv.sock');
|
||||||
|
|
||||||
|
// Teardown steps, run in reverse. Also used to unwind a failed startup.
|
||||||
|
const teardown: Array<() => Promise<void> | void> = [];
|
||||||
|
const dispose = async (): Promise<void> => {
|
||||||
|
for (const step of teardown.reverse()) await step();
|
||||||
|
teardown.length = 0;
|
||||||
|
if (process.env.SUBMINER_E2E_KEEP !== '1') {
|
||||||
|
fs.rmSync(root, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.mkdirSync(userDataDir, { recursive: true });
|
||||||
|
writeFixtureSubtitles(subtitlePath);
|
||||||
|
await Promise.all([generateFixtureClip(mediaPath), buildFixtureDictionary(dictionaryPath)]);
|
||||||
|
|
||||||
|
const display = await startDisplay();
|
||||||
|
teardown.push(display.stop);
|
||||||
|
const anki = await startFakeAnki();
|
||||||
|
teardown.push(anki.stop);
|
||||||
|
|
||||||
|
const config = mergeConfig(buildConfig(mpvSocketPath, anki.url), options.config ?? {});
|
||||||
|
fs.writeFileSync(path.join(userDataDir, 'config.jsonc'), JSON.stringify(config, null, 2));
|
||||||
|
|
||||||
|
const env: EnvDelta = {
|
||||||
|
set: {
|
||||||
|
...display.env.set,
|
||||||
|
// The app derives its config dir, Electron profile, and control socket from these.
|
||||||
|
...(process.platform === 'win32'
|
||||||
|
? { APPDATA: configHome }
|
||||||
|
: { XDG_CONFIG_HOME: configHome, XDG_DATA_HOME: path.join(root, 'data') }),
|
||||||
|
SUBMINER_APP_LOG: path.join(root, 'app.log'),
|
||||||
|
// Stay attached instead of re-spawning detached, so the harness owns the process.
|
||||||
|
SUBMINER_BACKGROUND_CHILD: '1',
|
||||||
|
},
|
||||||
|
unset: [...display.env.unset, 'ELECTRON_RUN_AS_NODE'],
|
||||||
|
};
|
||||||
|
// --enable-logging routes renderer console output into the app log too.
|
||||||
|
const electronArgs = ['--password-store=basic', '--enable-logging=stderr'];
|
||||||
|
// Outside Hyprland/Sway the app re-spawns itself detached onto the X11
|
||||||
|
// backend. Start it there directly so the process we spawn is the app.
|
||||||
|
if (shouldForceX11ElectronBackend(applyEnvDelta(process.env, env))) {
|
||||||
|
env.set[X11_ELECTRON_BOOTSTRAP_ENV] = '1';
|
||||||
|
electronArgs.push('--ozone-platform=x11');
|
||||||
|
}
|
||||||
|
// CI containers and runners lack the user namespaces Chromium's sandbox needs.
|
||||||
|
if (process.platform === 'linux' && process.env.CI) electronArgs.push('--no-sandbox');
|
||||||
|
const target: AppTarget = { env, electronArgs, logPath: path.join(root, 'app-stdio.log') };
|
||||||
|
|
||||||
|
const launchApp = async (
|
||||||
|
args: string[],
|
||||||
|
): Promise<{ child: ChildProcess; cdpPort: number; inspectorUrl: string }> => {
|
||||||
|
// With port 0 Chromium and Node each pick a free port; Chromium records
|
||||||
|
// its port in the profile dir, Node prints its endpoint to stderr.
|
||||||
|
const portFile = path.join(userDataDir, 'DevToolsActivePort');
|
||||||
|
fs.rmSync(portFile, { force: true });
|
||||||
|
const logOffset = fs.existsSync(target.logPath) ? fs.statSync(target.logPath).size : 0;
|
||||||
|
const child = spawnApp(
|
||||||
|
target,
|
||||||
|
['--remote-debugging-port=0', '--inspect=0'],
|
||||||
|
[...args, '--log-level', 'debug'],
|
||||||
|
);
|
||||||
|
const stop = () => stopProcess(child);
|
||||||
|
teardown.push(stop);
|
||||||
|
const cdpPort = await waitUntil(
|
||||||
|
() => {
|
||||||
|
if (child.exitCode !== null) {
|
||||||
|
throw new Error(`SubMiner exited with code ${child.exitCode} during startup`);
|
||||||
|
}
|
||||||
|
return readDevToolsPort(portFile);
|
||||||
|
},
|
||||||
|
{ description: 'SubMiner DevTools port', timeoutMs: 30_000 },
|
||||||
|
);
|
||||||
|
const inspectorUrl = await waitUntil(() => readInspectorUrl(target.logPath, logOffset), {
|
||||||
|
description: 'SubMiner main-process inspector endpoint',
|
||||||
|
});
|
||||||
|
return { child, cdpPort, inspectorUrl };
|
||||||
|
};
|
||||||
|
|
||||||
|
// First boot: import the fixture dictionary through Yomitan's settings page.
|
||||||
|
// Without one the tokenizer finds nothing and first-run setup takes over.
|
||||||
|
const seeder = await launchApp(['--yomitan']);
|
||||||
|
const settings = await openPage(seeder.cdpPort, YOMITAN_SETTINGS_PAGE);
|
||||||
|
await settings.waitFor('globalThis.__subminerYomitanSettingsAutomation?.ready === true', {
|
||||||
|
description: 'Yomitan settings automation bridge',
|
||||||
|
});
|
||||||
|
const archive = fs.readFileSync(dictionaryPath).toString('base64');
|
||||||
|
await settings.evaluate(
|
||||||
|
`globalThis.__subminerYomitanSettingsAutomation
|
||||||
|
.importDictionaryArchiveBase64(${JSON.stringify(archive)}, "fixture-dictionary.zip")
|
||||||
|
.then(() => true)`,
|
||||||
|
);
|
||||||
|
settings.close();
|
||||||
|
await stopProcess(seeder.child);
|
||||||
|
|
||||||
|
const mpvProcess = await startMpv({
|
||||||
|
socketPath: mpvSocketPath,
|
||||||
|
mediaPath,
|
||||||
|
subtitlePath,
|
||||||
|
logPath: path.join(root, 'mpv.log'),
|
||||||
|
display,
|
||||||
|
});
|
||||||
|
teardown.push(() => stopProcess(mpvProcess));
|
||||||
|
const mpv = await connectMpv(mpvSocketPath);
|
||||||
|
teardown.push(mpv.close);
|
||||||
|
|
||||||
|
const app = await launchApp(['--start']);
|
||||||
|
// mpv starts paused and the app resumes it once the overlay and tokenizer
|
||||||
|
// are ready, so that resume marks the end of startup.
|
||||||
|
await waitUntil(async () => (await mpv.command('get_property', 'pause')) === false, {
|
||||||
|
description: 'SubMiner to resume playback after overlay startup',
|
||||||
|
timeoutMs: 30_000,
|
||||||
|
});
|
||||||
|
// Hand scenarios a paused player. The app retries its resume for a moment,
|
||||||
|
// so keep pausing until the pause has held for longer than that retry window.
|
||||||
|
let pausedSince: number | null = null;
|
||||||
|
await waitUntil(
|
||||||
|
async () => {
|
||||||
|
if ((await mpv.command('get_property', 'pause')) !== true) {
|
||||||
|
pausedSince = null;
|
||||||
|
await mpv.command('set_property', 'pause', true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
pausedSince ??= Date.now();
|
||||||
|
return Date.now() - pausedSince >= 1_500;
|
||||||
|
},
|
||||||
|
{ description: 'playback to stay paused after startup', timeoutMs: 40_000 },
|
||||||
|
);
|
||||||
|
const pages: CdpPage[] = [];
|
||||||
|
teardown.push(() => pages.forEach((page) => page.close()));
|
||||||
|
|
||||||
|
return {
|
||||||
|
root,
|
||||||
|
display: display.kind,
|
||||||
|
cdpPort: app.cdpPort,
|
||||||
|
inspectorUrl: app.inspectorUrl,
|
||||||
|
mpvSocketPath,
|
||||||
|
target,
|
||||||
|
mpv,
|
||||||
|
anki,
|
||||||
|
openPage: async (urlPart) => {
|
||||||
|
const page = await openPage(app.cdpPort, urlPart);
|
||||||
|
pages.push(page);
|
||||||
|
return page;
|
||||||
|
},
|
||||||
|
mainProcess: async () => {
|
||||||
|
const page = await connectCdp(app.inspectorUrl, 'main process');
|
||||||
|
pages.push(page);
|
||||||
|
return page;
|
||||||
|
},
|
||||||
|
runAppCommand: (...args) => runAppCommand(target, args),
|
||||||
|
dispose,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
// Keep the logs: a failed startup is exactly when they are needed.
|
||||||
|
process.env.SUBMINER_E2E_KEEP = '1';
|
||||||
|
await dispose();
|
||||||
|
throw new Error(`E2E session failed to start (logs kept in ${root})`, { cause: error });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
export type WaitOptions = {
|
||||||
|
description: string;
|
||||||
|
timeoutMs?: number;
|
||||||
|
intervalMs?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Truthy<T> = Exclude<T, false | 0 | '' | null | undefined>;
|
||||||
|
|
||||||
|
/** Polls `probe` until it returns a truthy value, then returns that value. */
|
||||||
|
export async function waitUntil<T>(
|
||||||
|
probe: () => T | Promise<T>,
|
||||||
|
{ description, timeoutMs = 15_000, intervalMs = 100 }: WaitOptions,
|
||||||
|
): Promise<Truthy<T>> {
|
||||||
|
const deadline = Date.now() + timeoutMs;
|
||||||
|
for (;;) {
|
||||||
|
const value = await probe();
|
||||||
|
if (value) return value as Truthy<T>;
|
||||||
|
if (Date.now() >= deadline) {
|
||||||
|
throw new Error(`Timed out after ${timeoutMs}ms waiting for ${description}`);
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,245 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test, { after } from 'node:test';
|
||||||
|
import { connectCdpPage, listCdpTargets, type CdpPage } from './harness/cdp';
|
||||||
|
import { FAKE_ANKI_DECK, FAKE_ANKI_MODEL } from './harness/fake-anki';
|
||||||
|
import { FIXTURE_CUES } from './harness/fixtures';
|
||||||
|
import { OVERLAY_PAGE, startE2eSession, type E2eSession } from './harness/session';
|
||||||
|
import { waitUntil } from './harness/wait';
|
||||||
|
|
||||||
|
type Started = { session: E2eSession; overlay: CdpPage };
|
||||||
|
|
||||||
|
// Bun caps node:test hooks at 5s whatever their timeout option says, so the
|
||||||
|
// session boots inside whichever test runs first and every test budgets for it.
|
||||||
|
const TEST_TIMEOUT_MS = 120_000;
|
||||||
|
let started: Promise<Started> | undefined;
|
||||||
|
|
||||||
|
function useSession(): Promise<Started> {
|
||||||
|
started ??= (async () => {
|
||||||
|
const session = await startE2eSession();
|
||||||
|
try {
|
||||||
|
return { session, overlay: await session.openPage(OVERLAY_PAGE) };
|
||||||
|
} catch (error) {
|
||||||
|
await session.dispose();
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return started;
|
||||||
|
}
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
const running = await started?.catch(() => undefined);
|
||||||
|
await running?.session.dispose();
|
||||||
|
});
|
||||||
|
|
||||||
|
type RenderedToken = { surface: string; headword: string | null };
|
||||||
|
|
||||||
|
// Parks playback inside a cue and waits for the overlay to show that line.
|
||||||
|
async function showCue(cue: (typeof FIXTURE_CUES)[number]): Promise<RenderedToken[]> {
|
||||||
|
const { session, overlay } = await useSession();
|
||||||
|
await session.mpv.command('seek', cue.at, 'absolute+exact');
|
||||||
|
// One expression reads the line and its tokens together, so a re-render
|
||||||
|
// between two round trips cannot hand back a half-updated subtitle.
|
||||||
|
return overlay
|
||||||
|
.waitFor<RenderedToken[] | false>(
|
||||||
|
`(() => {
|
||||||
|
const root = document.getElementById('subtitleRoot');
|
||||||
|
const words = Array.from(root.querySelectorAll('.word'), (word) => ({
|
||||||
|
surface: word.textContent,
|
||||||
|
headword: word.getAttribute('data-headword'),
|
||||||
|
}));
|
||||||
|
return root.textContent === ${JSON.stringify(cue.text)} && words.length > 0 && words;
|
||||||
|
})()`,
|
||||||
|
{ description: `overlay to render "${cue.text}" tokenized` },
|
||||||
|
)
|
||||||
|
.catch(async (error: unknown) => {
|
||||||
|
// Say what the overlay was showing, what main thinks the line is, and
|
||||||
|
// what the renderer logged, so a dropped update can be placed.
|
||||||
|
const state = await overlay.evaluate<string>(
|
||||||
|
`(async () => JSON.stringify({
|
||||||
|
visibility: document.visibilityState,
|
||||||
|
text: document.getElementById('subtitleRoot').textContent,
|
||||||
|
html: document.getElementById('subtitleRoot').innerHTML.slice(0, 200),
|
||||||
|
mainLine: (await window.electronAPI.getCurrentSubtitle())?.text,
|
||||||
|
errorToast: document.getElementById('overlayErrorToast')?.textContent,
|
||||||
|
}))()`,
|
||||||
|
);
|
||||||
|
// Diagnostics must not replace the cue failure if the inspector is gone too.
|
||||||
|
const windows = await session
|
||||||
|
.mainProcess()
|
||||||
|
.then((main) =>
|
||||||
|
main.evaluate<string>(
|
||||||
|
`JSON.stringify(process.mainModule.require('electron').BrowserWindow.getAllWindows().map((w) => ({
|
||||||
|
id: w.id,
|
||||||
|
title: w.getTitle(),
|
||||||
|
url: w.webContents.getURL().split('/').pop(),
|
||||||
|
visible: w.isVisible(),
|
||||||
|
loading: w.webContents.isLoading(),
|
||||||
|
documentLoaded: w.__subminerOverlayDocumentLoaded,
|
||||||
|
contentReady: w.__subminerOverlayContentReady,
|
||||||
|
})))`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.catch((inspectorError: unknown) => `unavailable (${String(inspectorError)})`);
|
||||||
|
const targets = (await listCdpTargets(session.cdpPort))
|
||||||
|
.filter((t) => t.type === 'page')
|
||||||
|
.map((t) => t.url.split('/').pop());
|
||||||
|
const log = overlay.console.slice(-20).join('\n');
|
||||||
|
throw new Error(
|
||||||
|
`Overlay state: ${state}\nMain windows: ${windows}\nPage targets: ${JSON.stringify(targets)}\nRenderer console:\n${log}`,
|
||||||
|
{ cause: error },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasToken(tokens: RenderedToken[], surface: string, headword: string): boolean {
|
||||||
|
return tokens.some((token) => token.surface === surface && token.headword === headword);
|
||||||
|
}
|
||||||
|
|
||||||
|
test(
|
||||||
|
'overlay renders the current mpv subtitle line as dictionary tokens',
|
||||||
|
{ timeout: TEST_TIMEOUT_MS },
|
||||||
|
async () => {
|
||||||
|
const tokens = await showCue(FIXTURE_CUES[0]);
|
||||||
|
|
||||||
|
assert.ok(hasToken(tokens, '今日', '今日'), JSON.stringify(tokens));
|
||||||
|
assert.ok(hasToken(tokens, '天気', '天気'), JSON.stringify(tokens));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'seeking to another cue replaces the line and deinflects verbs to their headword',
|
||||||
|
{ timeout: TEST_TIMEOUT_MS },
|
||||||
|
async () => {
|
||||||
|
const tokens = await showCue(FIXTURE_CUES[2]);
|
||||||
|
|
||||||
|
assert.ok(hasToken(tokens, '行きます', '行く'), JSON.stringify(tokens));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'mining a sentence card sends the line with generated audio and image to Anki',
|
||||||
|
{ timeout: TEST_TIMEOUT_MS },
|
||||||
|
async () => {
|
||||||
|
const { session } = await useSession();
|
||||||
|
const cue = FIXTURE_CUES[1];
|
||||||
|
await showCue(cue);
|
||||||
|
session.anki.requests.length = 0;
|
||||||
|
|
||||||
|
await session.runAppCommand('--mine-sentence');
|
||||||
|
const update = await waitUntil(
|
||||||
|
() => session.anki.requests.find((request) => request.action === 'updateNoteFields'),
|
||||||
|
{ description: 'media fields to be written to the mined note', timeoutMs: 30_000 },
|
||||||
|
);
|
||||||
|
|
||||||
|
const added = session.anki.requests.filter((request) => request.action === 'addNote');
|
||||||
|
assert.equal(added.length, 1);
|
||||||
|
assert.partialDeepStrictEqual(added[0]?.params.note, {
|
||||||
|
deckName: FAKE_ANKI_DECK,
|
||||||
|
modelName: FAKE_ANKI_MODEL,
|
||||||
|
fields: { Sentence: cue.text },
|
||||||
|
});
|
||||||
|
|
||||||
|
const stored = session.anki.requests
|
||||||
|
.filter((request) => request.action === 'storeMediaFile')
|
||||||
|
.map((request) => String(request.params.filename));
|
||||||
|
assert.ok(
|
||||||
|
stored.some((name) => name.endsWith('.mp3')),
|
||||||
|
`no audio in ${stored.join(', ')}`,
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
stored.some((name) => name.endsWith('.jpg')),
|
||||||
|
`no image in ${stored.join(', ')}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const updatedFields = JSON.stringify(update.params);
|
||||||
|
for (const filename of stored) assert.ok(updatedFields.includes(filename), filename);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test(
|
||||||
|
'open subtitle sidebar lists the parsed cues and follows playback',
|
||||||
|
{ timeout: TEST_TIMEOUT_MS },
|
||||||
|
async () => {
|
||||||
|
const { session, overlay } = await useSession();
|
||||||
|
await showCue(FIXTURE_CUES[0]);
|
||||||
|
await session.runAppCommand('--toggle-subtitle-sidebar');
|
||||||
|
await overlay.waitFor(
|
||||||
|
`document.querySelectorAll('#subtitleSidebarList .subtitle-sidebar-item').length === ${FIXTURE_CUES.length}`,
|
||||||
|
{ description: 'sidebar to list every fixture cue' },
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const [index, cue] of FIXTURE_CUES.entries()) {
|
||||||
|
await session.mpv.command('seek', cue.at, 'absolute+exact');
|
||||||
|
await overlay.waitFor(
|
||||||
|
`document.querySelector('#subtitleSidebarList .subtitle-sidebar-item.active')?.dataset.index === '${index}'`,
|
||||||
|
{ description: `sidebar to highlight cue ${index}` },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await session.runAppCommand('--toggle-subtitle-sidebar');
|
||||||
|
await overlay.waitFor(
|
||||||
|
`document.getElementById('subtitleSidebarModal').classList.contains('hidden')`,
|
||||||
|
{ description: 'sidebar to close' },
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Runs last: it leaves the lookup popup open over the overlay.
|
||||||
|
test(
|
||||||
|
'holding Shift over a word opens the Yomitan popup with its dictionary entry',
|
||||||
|
{ timeout: TEST_TIMEOUT_MS },
|
||||||
|
async () => {
|
||||||
|
const { session, overlay } = await useSession();
|
||||||
|
await showCue(FIXTURE_CUES[0]);
|
||||||
|
const word = await overlay.evaluate<{ x: number; y: number }>(
|
||||||
|
`(() => {
|
||||||
|
const words = Array.from(document.querySelectorAll('#subtitleRoot .word'));
|
||||||
|
const box = words.find((word) => word.textContent === '天気').getBoundingClientRect();
|
||||||
|
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
|
||||||
|
})()`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Yomitan's default scan modifier is Shift, and it scans on mouse movement,
|
||||||
|
// so approach the word, hold Shift, then move across it.
|
||||||
|
const shift = { key: 'Shift', code: 'ShiftLeft', windowsVirtualKeyCode: 16 };
|
||||||
|
const move = (x: number, modifiers = 0) =>
|
||||||
|
overlay.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x, y: word.y, modifiers });
|
||||||
|
await move(word.x - 30);
|
||||||
|
await overlay.send('Input.dispatchKeyEvent', { type: 'rawKeyDown', ...shift, modifiers: 8 });
|
||||||
|
await move(word.x - 2, 8);
|
||||||
|
await move(word.x, 8);
|
||||||
|
|
||||||
|
await overlay.waitFor(
|
||||||
|
`document.querySelector('[data-subminer-yomitan-popup-visible="true"]') !== null`,
|
||||||
|
{ description: 'overlay to mark the Yomitan popup visible' },
|
||||||
|
);
|
||||||
|
// Yomitan keeps more than one popup frame around, so read whichever
|
||||||
|
// one holds the entry instead of trusting target order.
|
||||||
|
let seen: string[] = [];
|
||||||
|
const entry = await waitUntil(
|
||||||
|
async () => {
|
||||||
|
const targets = (await listCdpTargets(session.cdpPort)).filter((target) =>
|
||||||
|
target.url.includes('popup.html'),
|
||||||
|
);
|
||||||
|
seen = [];
|
||||||
|
for (const target of targets) {
|
||||||
|
// A frame can go away between listing and connecting; skip it.
|
||||||
|
const frame = await connectCdpPage(target).catch(() => undefined);
|
||||||
|
if (!frame) continue;
|
||||||
|
// textContent, not innerText: the entry counts once it is in the DOM,
|
||||||
|
// even where a GPU-less runner never lays the frame out.
|
||||||
|
const text = await frame.evaluate<string>('document.body?.textContent ?? ""');
|
||||||
|
frame.close();
|
||||||
|
seen.push(text);
|
||||||
|
}
|
||||||
|
return seen.find((text) => text.includes('weather'));
|
||||||
|
},
|
||||||
|
{ description: 'a popup frame to show the fixture dictionary entry' },
|
||||||
|
).catch((error: unknown) => {
|
||||||
|
const summary = seen.map((text) => text.replace(/\s+/g, ' ').trim().slice(0, 200));
|
||||||
|
throw new Error(`Popup frames held: ${JSON.stringify(summary)}`, { cause: error });
|
||||||
|
});
|
||||||
|
await overlay.send('Input.dispatchKeyEvent', { type: 'keyUp', ...shift });
|
||||||
|
assert.match(entry, /天気/);
|
||||||
|
},
|
||||||
|
);
|
||||||
@@ -6,11 +6,9 @@ import type { LauncherCommandContext } from './context.js';
|
|||||||
import { runConfigCommand } from './config-command.js';
|
import { runConfigCommand } from './config-command.js';
|
||||||
import { runDictionaryCommand } from './dictionary-command.js';
|
import { runDictionaryCommand } from './dictionary-command.js';
|
||||||
import { runDoctorCommand } from './doctor-command.js';
|
import { runDoctorCommand } from './doctor-command.js';
|
||||||
import { runLogsCommand } from './logs-command.js';
|
|
||||||
import { runMpvPostAppCommand, runMpvPreAppCommand } from './mpv-command.js';
|
import { runMpvPostAppCommand, runMpvPreAppCommand } from './mpv-command.js';
|
||||||
import { runAppPassthroughCommand } from './app-command.js';
|
import { runAppPassthroughCommand } from './app-command.js';
|
||||||
import { runStatsCommand } from './stats-command.js';
|
import { runStatsCommand } from './stats-command.js';
|
||||||
import { runUpdateCommand } from './update-command.js';
|
|
||||||
|
|
||||||
class ExitSignal extends Error {
|
class ExitSignal extends Error {
|
||||||
code: number;
|
code: number;
|
||||||
@@ -150,74 +148,7 @@ test('doctor command exits non-zero for missing hard dependencies', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('doctor command forwards refresh-known-words to app binary', () => {
|
test('app command starts default background app detached from launcher app detached from launcher', () => {
|
||||||
const context = createContext();
|
|
||||||
context.args.doctor = true;
|
|
||||||
context.args.doctorRefreshKnownWords = true;
|
|
||||||
const forwarded: string[][] = [];
|
|
||||||
|
|
||||||
const handled = runDoctorCommand(context, {
|
|
||||||
commandExists: () => false,
|
|
||||||
configExists: () => true,
|
|
||||||
resolveMainConfigPath: () => '/tmp/SubMiner/config.jsonc',
|
|
||||||
runAppCommandWithInherit: (_appPath, appArgs) => {
|
|
||||||
forwarded.push(appArgs);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
assert.deepEqual(forwarded, [['--refresh-known-words']]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('logs command exports logs and writes archive path', () => {
|
|
||||||
const writes: string[] = [];
|
|
||||||
const context = createContext();
|
|
||||||
context.args.logsExport = true;
|
|
||||||
context.processAdapter = {
|
|
||||||
...context.processAdapter,
|
|
||||||
writeStdout: (text) => writes.push(text),
|
|
||||||
};
|
|
||||||
|
|
||||||
const handled = runLogsCommand(context, {
|
|
||||||
exportLogsArchive: () => ({
|
|
||||||
zipPath: '/tmp/subminer-logs.zip',
|
|
||||||
exportedFiles: ['/tmp/app.log'],
|
|
||||||
mode: 'current-day',
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
assert.deepEqual(writes, ['/tmp/subminer-logs.zip\n']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('logs command ignores unrelated launcher commands', () => {
|
|
||||||
const context = createContext();
|
|
||||||
|
|
||||||
assert.equal(runLogsCommand(context), false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app command starts default macOS background app detached from launcher', () => {
|
|
||||||
const context = createContext();
|
|
||||||
context.args.appPassthrough = true;
|
|
||||||
context.args.appArgs = [];
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
const handled = runAppPassthroughCommand(context, {
|
|
||||||
runAppCommandWithInherit: () => {
|
|
||||||
calls.push('attached');
|
|
||||||
},
|
|
||||||
launchSyncUiDetached: () => calls.push('sync-ui'),
|
|
||||||
launchYoutubeBrowserDetached: () => calls.push('youtube'),
|
|
||||||
launchAppBackgroundDetached: (appPath, logLevel) => {
|
|
||||||
calls.push(`detached:${appPath}:${logLevel}`);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
assert.deepEqual(calls, ['detached:/tmp/subminer.app:warn']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app command starts default Linux background app detached from launcher', () => {
|
|
||||||
const context = createContext();
|
const context = createContext();
|
||||||
context.args.appPassthrough = true;
|
context.args.appPassthrough = true;
|
||||||
context.args.appArgs = [];
|
context.args.appArgs = [];
|
||||||
@@ -389,49 +320,6 @@ test('dictionary command forwards candidate and selection modes to app binary',
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('dictionary command returns after app handoff starts', () => {
|
|
||||||
const context = createContext();
|
|
||||||
context.args.dictionary = true;
|
|
||||||
|
|
||||||
const handled = runDictionaryCommand(context, {
|
|
||||||
runAppCommandWithInherit: () => undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('update command runs direct Linux release update without launching Electron', async () => {
|
|
||||||
const context = createContext();
|
|
||||||
context.args.update = true;
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
const handled = await runUpdateCommand(context, {
|
|
||||||
runAppCommandCaptureOutput: () => {
|
|
||||||
throw new Error('unexpected Electron launch');
|
|
||||||
},
|
|
||||||
runDirectReleaseUpdate: async (request) => {
|
|
||||||
calls.push(`direct:${request.appPath}:${request.launcherPath}:${request.channel}`);
|
|
||||||
return {
|
|
||||||
appImage: { status: 'not-found' },
|
|
||||||
launcher: { status: 'updated' },
|
|
||||||
supportAssets: [{ status: 'skipped' }],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
readMainConfig: () => null,
|
|
||||||
log: (level, _configured, message) => {
|
|
||||||
calls.push(`${level}:${message}`);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
assert.deepEqual(calls, [
|
|
||||||
'direct:/tmp/subminer.app:/tmp/subminer:stable',
|
|
||||||
'info:AppImage update: not-found',
|
|
||||||
'info:Launcher update: updated',
|
|
||||||
'info:Support assets update: skipped',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stats command launches attached app command with response path', async () => {
|
test('stats command launches attached app command with response path', async () => {
|
||||||
const harness = createStatsTestHarness({ stats: true, logLevel: 'debug' });
|
const harness = createStatsTestHarness({ stats: true, logLevel: 'debug' });
|
||||||
const handled = await runStatsCommand(harness.context, harness.commandDeps);
|
const handled = await runStatsCommand(harness.context, harness.commandDeps);
|
||||||
@@ -449,16 +337,41 @@ test('stats command launches attached app command with response path', async ()
|
|||||||
assert.equal(harness.removedPaths.length, 1);
|
assert.equal(harness.removedPaths.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stats background command launches attached daemon control command with response path', async () => {
|
const STATS_RESPONSE_ARGS = ['--stats-response-path', '/tmp/subminer-stats-test/response.json'];
|
||||||
const harness = createStatsTestHarness({ stats: true, statsBackground: true });
|
|
||||||
|
const statsForwardingCases = [
|
||||||
|
{
|
||||||
|
name: 'stats background command launches the daemon start command',
|
||||||
|
overrides: { statsBackground: true },
|
||||||
|
expected: ['--stats-daemon-start', ...STATS_RESPONSE_ARGS],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'stats stop command forwards the daemon stop flag',
|
||||||
|
overrides: { statsStop: true },
|
||||||
|
expected: ['--stats-daemon-stop', ...STATS_RESPONSE_ARGS],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'stats cleanup command forwards cleanup vocab flags',
|
||||||
|
overrides: { statsCleanup: true, statsCleanupVocab: true },
|
||||||
|
expected: ['--stats', ...STATS_RESPONSE_ARGS, '--stats-cleanup', '--stats-cleanup-vocab'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'stats cleanup command forwards the lifetime rebuild flag',
|
||||||
|
overrides: { statsCleanup: true, statsCleanupLifetime: true },
|
||||||
|
expected: ['--stats', ...STATS_RESPONSE_ARGS, '--stats-cleanup', '--stats-cleanup-lifetime'],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const c of statsForwardingCases) {
|
||||||
|
test(`${c.name} to the app`, async () => {
|
||||||
|
const harness = createStatsTestHarness({ stats: true, ...c.overrides });
|
||||||
const handled = await runStatsCommand(harness.context, harness.commandDeps);
|
const handled = await runStatsCommand(harness.context, harness.commandDeps);
|
||||||
|
|
||||||
assert.equal(handled, true);
|
assert.equal(handled, true);
|
||||||
assert.deepEqual(harness.forwarded, [
|
assert.deepEqual(harness.forwarded, [c.expected]);
|
||||||
['--stats-daemon-start', '--stats-response-path', '/tmp/subminer-stats-test/response.json'],
|
|
||||||
]);
|
|
||||||
assert.equal(harness.removedPaths.length, 1);
|
assert.equal(harness.removedPaths.length, 1);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test('stats command waits for attached app exit after startup response', async () => {
|
test('stats command waits for attached app exit after startup response', async () => {
|
||||||
const harness = createStatsTestHarness({ stats: true });
|
const harness = createStatsTestHarness({ stats: true });
|
||||||
@@ -503,45 +416,6 @@ test('stats command throws when attached app exits non-zero after startup respon
|
|||||||
assert.equal(harness.removedPaths.length, 1);
|
assert.equal(harness.removedPaths.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stats cleanup command forwards cleanup vocab flags to the app', async () => {
|
|
||||||
const harness = createStatsTestHarness({
|
|
||||||
stats: true,
|
|
||||||
statsCleanup: true,
|
|
||||||
statsCleanupVocab: true,
|
|
||||||
});
|
|
||||||
const handled = await runStatsCommand(harness.context, {
|
|
||||||
...harness.commandDeps,
|
|
||||||
waitForStatsResponse: async () => ({ ok: true }),
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
assert.deepEqual(harness.forwarded, [
|
|
||||||
[
|
|
||||||
'--stats',
|
|
||||||
'--stats-response-path',
|
|
||||||
'/tmp/subminer-stats-test/response.json',
|
|
||||||
'--stats-cleanup',
|
|
||||||
'--stats-cleanup-vocab',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
assert.equal(harness.removedPaths.length, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stats stop command forwards stop flag to the app', async () => {
|
|
||||||
const harness = createStatsTestHarness({ stats: true, statsStop: true });
|
|
||||||
|
|
||||||
const handled = await runStatsCommand(harness.context, {
|
|
||||||
...harness.commandDeps,
|
|
||||||
waitForStatsResponse: async () => ({ ok: true }),
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
assert.deepEqual(harness.forwarded, [
|
|
||||||
['--stats-daemon-stop', '--stats-response-path', '/tmp/subminer-stats-test/response.json'],
|
|
||||||
]);
|
|
||||||
assert.equal(harness.removedPaths.length, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stats stop command exits on process exit without waiting for startup response', async () => {
|
test('stats stop command exits on process exit without waiting for startup response', async () => {
|
||||||
const harness = createStatsTestHarness({ stats: true, statsStop: true });
|
const harness = createStatsTestHarness({ stats: true, statsStop: true });
|
||||||
let waitedForResponse = false;
|
let waitedForResponse = false;
|
||||||
@@ -563,30 +437,6 @@ test('stats stop command exits on process exit without waiting for startup respo
|
|||||||
assert.equal(harness.removedPaths.length, 1);
|
assert.equal(harness.removedPaths.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stats cleanup command forwards lifetime rebuild flag to the app', async () => {
|
|
||||||
const harness = createStatsTestHarness({
|
|
||||||
stats: true,
|
|
||||||
statsCleanup: true,
|
|
||||||
statsCleanupLifetime: true,
|
|
||||||
});
|
|
||||||
const handled = await runStatsCommand(harness.context, {
|
|
||||||
...harness.commandDeps,
|
|
||||||
waitForStatsResponse: async () => ({ ok: true }),
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(handled, true);
|
|
||||||
assert.deepEqual(harness.forwarded, [
|
|
||||||
[
|
|
||||||
'--stats',
|
|
||||||
'--stats-response-path',
|
|
||||||
'/tmp/subminer-stats-test/response.json',
|
|
||||||
'--stats-cleanup',
|
|
||||||
'--stats-cleanup-lifetime',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
assert.equal(harness.removedPaths.length, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stats command throws when stats response reports an error', async () => {
|
test('stats command throws when stats response reports an error', async () => {
|
||||||
const harness = createStatsTestHarness({ stats: true });
|
const harness = createStatsTestHarness({ stats: true });
|
||||||
|
|
||||||
@@ -692,36 +542,3 @@ test('stats command aborts pending response wait when attached app fails to spaw
|
|||||||
assert.equal(aborted, true);
|
assert.equal(aborted, true);
|
||||||
assert.equal(harness.removedPaths.length, 1);
|
assert.equal(harness.removedPaths.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stats cleanup command aborts pending response wait when app exits before startup response', async () => {
|
|
||||||
const harness = createStatsTestHarness({
|
|
||||||
stats: true,
|
|
||||||
statsCleanup: true,
|
|
||||||
statsCleanupVocab: true,
|
|
||||||
});
|
|
||||||
let aborted = false;
|
|
||||||
|
|
||||||
await assert.rejects(async () => {
|
|
||||||
await runStatsCommand(harness.context, {
|
|
||||||
...harness.commandDeps,
|
|
||||||
runAppCommandAttached: async (...args) => {
|
|
||||||
await harness.runAppCommandAttachedStub(...args);
|
|
||||||
return 2;
|
|
||||||
},
|
|
||||||
waitForStatsResponse: async (_responsePath, signal) =>
|
|
||||||
await new Promise((resolve) => {
|
|
||||||
signal?.addEventListener(
|
|
||||||
'abort',
|
|
||||||
() => {
|
|
||||||
aborted = true;
|
|
||||||
resolve({ ok: false, error: 'aborted' });
|
|
||||||
},
|
|
||||||
{ once: true },
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
}, /Stats app exited before startup response \(status 2\)\./);
|
|
||||||
|
|
||||||
assert.equal(aborted, true);
|
|
||||||
assert.equal(harness.removedPaths.length, 1);
|
|
||||||
});
|
|
||||||
@@ -65,7 +65,7 @@ export async function runMpvPostAppCommand(
|
|||||||
context: LauncherCommandContext,
|
context: LauncherCommandContext,
|
||||||
deps: MpvCommandDeps = defaultDeps,
|
deps: MpvCommandDeps = defaultDeps,
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
const { args, appPath, scriptPath, mpvSocketPath, pluginRuntimeConfig } = context;
|
const { args, appPath, mpvSocketPath, pluginRuntimeConfig } = context;
|
||||||
if (!args.mpvIdle) {
|
if (!args.mpvIdle) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,72 +4,22 @@ import { EventEmitter } from 'node:events';
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
import type { Args } from '../types.js';
|
||||||
import type { LauncherCommandContext } from './context.js';
|
import type { LauncherCommandContext } from './context.js';
|
||||||
import { registerCleanup, runPlaybackCommandWithDeps } from './playback-command.js';
|
import { registerCleanup, runPlaybackCommandWithDeps } from './playback-command.js';
|
||||||
import { state } from '../mpv.js';
|
import { state, type startMpv } from '../mpv.js';
|
||||||
|
import { makeLauncherArgs } from '../test-support/args.js';
|
||||||
|
import { withEnv } from '../test-support/env.js';
|
||||||
|
|
||||||
function createContext(): LauncherCommandContext {
|
type PlaybackDeps = Parameters<typeof runPlaybackCommandWithDeps>[1];
|
||||||
|
type StartMpvOptions = NonNullable<Parameters<typeof startMpv>[6]>;
|
||||||
|
|
||||||
|
const YOUTUBE_URL = 'https://www.youtube.com/watch?v=65Ovd7t8sNw';
|
||||||
|
|
||||||
|
function makePluginConfig(
|
||||||
|
overrides: Partial<LauncherCommandContext['pluginRuntimeConfig']> = {},
|
||||||
|
): LauncherCommandContext['pluginRuntimeConfig'] {
|
||||||
return {
|
return {
|
||||||
args: {
|
|
||||||
backend: 'auto',
|
|
||||||
directory: '.',
|
|
||||||
recursive: false,
|
|
||||||
profile: '',
|
|
||||||
startOverlay: false,
|
|
||||||
youtubePrimarySubLangs: [],
|
|
||||||
youtubeSecondarySubLangs: [],
|
|
||||||
youtubeAudioLangs: [],
|
|
||||||
useTexthooker: false,
|
|
||||||
autoStartOverlay: false,
|
|
||||||
texthookerOnly: false,
|
|
||||||
texthookerOpenBrowser: false,
|
|
||||||
useRofi: false,
|
|
||||||
history: false,
|
|
||||||
sync: false,
|
|
||||||
syncCliTokens: [],
|
|
||||||
syncUi: false,
|
|
||||||
logLevel: 'info',
|
|
||||||
logRotation: 7,
|
|
||||||
passwordStore: '',
|
|
||||||
target: 'https://www.youtube.com/watch?v=65Ovd7t8sNw',
|
|
||||||
targetKind: 'url',
|
|
||||||
jimakuApiKey: '',
|
|
||||||
jimakuApiKeyCommand: '',
|
|
||||||
jimakuApiBaseUrl: '',
|
|
||||||
jimakuLanguagePreference: 'ja',
|
|
||||||
jimakuMaxEntryResults: 20,
|
|
||||||
jellyfin: false,
|
|
||||||
jellyfinLogin: false,
|
|
||||||
jellyfinLogout: false,
|
|
||||||
jellyfinPlay: false,
|
|
||||||
jellyfinDiscovery: false,
|
|
||||||
dictionary: false,
|
|
||||||
dictionaryCandidates: false,
|
|
||||||
dictionarySelect: false,
|
|
||||||
stats: false,
|
|
||||||
doctor: false,
|
|
||||||
doctorRefreshKnownWords: false,
|
|
||||||
logsExport: false,
|
|
||||||
version: false,
|
|
||||||
settings: false,
|
|
||||||
youtubeBrowser: false,
|
|
||||||
configPath: false,
|
|
||||||
configShow: false,
|
|
||||||
mpvIdle: false,
|
|
||||||
mpvSocket: false,
|
|
||||||
mpvStatus: false,
|
|
||||||
mpvArgs: '',
|
|
||||||
appPassthrough: false,
|
|
||||||
appArgs: [],
|
|
||||||
jellyfinServer: '',
|
|
||||||
jellyfinUsername: '',
|
|
||||||
jellyfinPassword: '',
|
|
||||||
launchMode: 'normal',
|
|
||||||
},
|
|
||||||
scriptPath: '/tmp/subminer',
|
|
||||||
scriptName: 'subminer',
|
|
||||||
mpvSocketPath: '/tmp/subminer.sock',
|
|
||||||
pluginRuntimeConfig: {
|
|
||||||
socketPath: '/tmp/subminer.sock',
|
socketPath: '/tmp/subminer.sock',
|
||||||
binaryPath: '',
|
binaryPath: '',
|
||||||
backend: 'auto',
|
backend: 'auto',
|
||||||
@@ -78,7 +28,29 @@ function createContext(): LauncherCommandContext {
|
|||||||
autoStartPauseUntilReady: true,
|
autoStartPauseUntilReady: true,
|
||||||
osdMessages: false,
|
osdMessages: false,
|
||||||
texthookerEnabled: false,
|
texthookerEnabled: false,
|
||||||
},
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A context for a YouTube URL target with logging at info and CLI texthooker off. */
|
||||||
|
function createContext(
|
||||||
|
options: {
|
||||||
|
args?: Partial<Args>;
|
||||||
|
plugin?: Partial<LauncherCommandContext['pluginRuntimeConfig']>;
|
||||||
|
} = {},
|
||||||
|
): LauncherCommandContext {
|
||||||
|
return {
|
||||||
|
args: makeLauncherArgs({
|
||||||
|
target: YOUTUBE_URL,
|
||||||
|
targetKind: 'url',
|
||||||
|
logLevel: 'info',
|
||||||
|
useTexthooker: false,
|
||||||
|
...options.args,
|
||||||
|
}),
|
||||||
|
scriptPath: '/tmp/subminer',
|
||||||
|
scriptName: 'subminer',
|
||||||
|
mpvSocketPath: '/tmp/subminer.sock',
|
||||||
|
pluginRuntimeConfig: makePluginConfig(options.plugin),
|
||||||
appPath: '/tmp/SubMiner.AppImage',
|
appPath: '/tmp/SubMiner.AppImage',
|
||||||
launcherJellyfinConfig: {},
|
launcherJellyfinConfig: {},
|
||||||
processAdapter: {
|
processAdapter: {
|
||||||
@@ -93,8 +65,70 @@ function createContext(): LauncherCommandContext {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FILE_TARGET = { target: '/tmp/movie.mkv', targetKind: 'file' } as const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Playback harness. Deps are inert by default and record what the tests assert on: the
|
||||||
|
* options mpv was started with, the overlay launches, and an `events` log for the few cases
|
||||||
|
* where relative order is the behavior.
|
||||||
|
*/
|
||||||
|
function makeHarness(
|
||||||
|
options: {
|
||||||
|
context?: LauncherCommandContext;
|
||||||
|
deps?: Partial<PlaybackDeps>;
|
||||||
|
events?: string[];
|
||||||
|
} = {},
|
||||||
|
) {
|
||||||
|
const context = options.context ?? createContext();
|
||||||
|
const events = options.events ?? [];
|
||||||
|
const startMpvOptions: StartMpvOptions[] = [];
|
||||||
|
const overlayCalls: Array<{ extraAppArgs: string[]; configDir?: string }> = [];
|
||||||
|
const deps: PlaybackDeps = {
|
||||||
|
ensurePlaybackSetupReady: async () => {},
|
||||||
|
ensureRuntimePluginReady: async () => {
|
||||||
|
events.push('plugin');
|
||||||
|
},
|
||||||
|
chooseTarget: async () => ({
|
||||||
|
target: context.args.target,
|
||||||
|
kind: context.args.targetKind === 'file' ? 'file' : 'url',
|
||||||
|
}),
|
||||||
|
checkDependencies: () => {},
|
||||||
|
registerCleanup: () => {},
|
||||||
|
startMpv: async (_target, _kind, _args, _socket, _appPath, _subtitles, startOptions) => {
|
||||||
|
events.push('startMpv');
|
||||||
|
if (startOptions) startMpvOptions.push(startOptions);
|
||||||
|
},
|
||||||
|
waitForUnixSocketReady: async () => true,
|
||||||
|
startOverlay: async (_appPath, _args, _socket, extraAppArgs = [], configDir) => {
|
||||||
|
events.push('startOverlay');
|
||||||
|
overlayCalls.push({ extraAppArgs, configDir });
|
||||||
|
},
|
||||||
|
launchAppCommandDetached: () => {},
|
||||||
|
log: () => {},
|
||||||
|
cleanupPlaybackSession: async () => {},
|
||||||
|
getMpvProc: () => null,
|
||||||
|
...options.deps,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
context,
|
||||||
|
events,
|
||||||
|
startMpvOptions,
|
||||||
|
overlayCalls,
|
||||||
|
run: () => runPlaybackCommandWithDeps(context, deps),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertRanInOrder(events: string[], ...expected: string[]): void {
|
||||||
|
const positions = expected.map((event) => events.indexOf(event));
|
||||||
|
assert.ok(
|
||||||
|
positions.every(
|
||||||
|
(position, index) => position >= 0 && (index === 0 || position > positions[index - 1]!),
|
||||||
|
),
|
||||||
|
`expected ${expected.join(' -> ')} in order, got ${events.join(', ')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
test('playback cleanup signal handlers are registered once across repeated sessions', () => {
|
test('playback cleanup signal handlers are registered once across repeated sessions', () => {
|
||||||
assert.equal(typeof registerCleanup, 'function', 'cleanup registration is not exported');
|
|
||||||
const context = createContext();
|
const context = createContext();
|
||||||
const registeredSignals: NodeJS.Signals[] = [];
|
const registeredSignals: NodeJS.Signals[] = [];
|
||||||
context.processAdapter.onSignal = (signal) => {
|
context.processAdapter.onSignal = (signal) => {
|
||||||
@@ -108,121 +142,41 @@ test('playback cleanup signal handlers are registered once across repeated sessi
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('youtube playback launches overlay with app-owned youtube flow args', async () => {
|
test('youtube playback launches overlay with app-owned youtube flow args', async () => {
|
||||||
const calls: string[] = [];
|
const harness = makeHarness({
|
||||||
const context = createContext();
|
context: createContext({
|
||||||
context.pluginRuntimeConfig = {
|
plugin: {
|
||||||
...context.pluginRuntimeConfig,
|
|
||||||
autoStart: false,
|
autoStart: false,
|
||||||
autoStartVisibleOverlay: false,
|
autoStartVisibleOverlay: false,
|
||||||
autoStartPauseUntilReady: false,
|
autoStartPauseUntilReady: false,
|
||||||
};
|
|
||||||
const receivedStartMpvOptions: Record<string, unknown>[] = [];
|
|
||||||
|
|
||||||
await runPlaybackCommandWithDeps(context, {
|
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {},
|
|
||||||
chooseTarget: async (_args, _scriptPath) => ({ target: context.args.target, kind: 'url' }),
|
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async (
|
|
||||||
_target,
|
|
||||||
_targetKind,
|
|
||||||
_args,
|
|
||||||
_socketPath,
|
|
||||||
_appPath,
|
|
||||||
_preloadedSubtitles,
|
|
||||||
options,
|
|
||||||
) => {
|
|
||||||
if (options) {
|
|
||||||
receivedStartMpvOptions.push(options as Record<string, unknown>);
|
|
||||||
}
|
|
||||||
calls.push('startMpv');
|
|
||||||
},
|
},
|
||||||
waitForUnixSocketReady: async () => true,
|
}),
|
||||||
startOverlay: async (_appPath, _args, _socketPath, extraAppArgs = []) => {
|
|
||||||
calls.push(`startOverlay:${extraAppArgs.join(' ')}`);
|
|
||||||
},
|
|
||||||
launchAppCommandDetached: (_appPath: string, appArgs: string[]) => {
|
|
||||||
calls.push(`launch:${appArgs.join(' ')}`);
|
|
||||||
},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {},
|
|
||||||
getMpvProc: () => null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(calls, [
|
await harness.run();
|
||||||
'startMpv',
|
|
||||||
'startOverlay:--youtube-play https://www.youtube.com/watch?v=65Ovd7t8sNw',
|
assertRanInOrder(harness.events, 'startMpv', 'startOverlay');
|
||||||
]);
|
assert.deepEqual(harness.overlayCalls[0]?.extraAppArgs, ['--youtube-play', YOUTUBE_URL]);
|
||||||
assert.equal(receivedStartMpvOptions[0]?.startPaused, true);
|
assert.equal(harness.startMpvOptions[0]?.startPaused, true);
|
||||||
assert.equal(receivedStartMpvOptions[0]?.disableYoutubeSubtitleAutoLoad, true);
|
assert.equal(harness.startMpvOptions[0]?.disableYoutubeSubtitleAutoLoad, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('youtube app-owned playback disables mpv plugin auto-start', async () => {
|
test('youtube app-owned playback disables mpv plugin auto-start', async () => {
|
||||||
const context = createContext();
|
const harness = makeHarness();
|
||||||
context.pluginRuntimeConfig = {
|
|
||||||
...context.pluginRuntimeConfig,
|
|
||||||
autoStart: true,
|
|
||||||
autoStartVisibleOverlay: true,
|
|
||||||
autoStartPauseUntilReady: true,
|
|
||||||
};
|
|
||||||
const receivedStartMpvOptions: Record<string, unknown>[] = [];
|
|
||||||
|
|
||||||
await runPlaybackCommandWithDeps(context, {
|
await harness.run();
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {},
|
|
||||||
chooseTarget: async () => ({ target: context.args.target, kind: 'url' }),
|
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async (
|
|
||||||
_target,
|
|
||||||
_targetKind,
|
|
||||||
_args,
|
|
||||||
_socketPath,
|
|
||||||
_appPath,
|
|
||||||
_preloadedSubtitles,
|
|
||||||
options,
|
|
||||||
) => {
|
|
||||||
if (options) {
|
|
||||||
receivedStartMpvOptions.push(options as Record<string, unknown>);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
waitForUnixSocketReady: async () => true,
|
|
||||||
startOverlay: async () => {},
|
|
||||||
launchAppCommandDetached: () => {},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {},
|
|
||||||
getMpvProc: () => null,
|
|
||||||
});
|
|
||||||
|
|
||||||
const runtimeConfig = receivedStartMpvOptions[0]?.runtimePluginConfig as
|
const runtimeConfig = harness.startMpvOptions[0]?.runtimePluginConfig;
|
||||||
| { autoStart?: boolean; autoStartVisibleOverlay?: boolean; autoStartPauseUntilReady?: boolean }
|
|
||||||
| undefined;
|
|
||||||
assert.equal(runtimeConfig?.autoStart, false);
|
assert.equal(runtimeConfig?.autoStart, false);
|
||||||
assert.equal(runtimeConfig?.autoStartVisibleOverlay, false);
|
assert.equal(runtimeConfig?.autoStartVisibleOverlay, false);
|
||||||
assert.equal(runtimeConfig?.autoStartPauseUntilReady, false);
|
assert.equal(runtimeConfig?.autoStartPauseUntilReady, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('plugin auto-start playback leaves app lifetime to managed-playback owner', async () => {
|
test('plugin auto-start playback leaves app lifetime to managed-playback owner', async () => {
|
||||||
const context = createContext();
|
const context = createContext({
|
||||||
context.args = {
|
args: { ...FILE_TARGET, useTexthooker: true },
|
||||||
...context.args,
|
plugin: { autoStartVisibleOverlay: false, autoStartPauseUntilReady: false },
|
||||||
target: '/tmp/movie.mkv',
|
});
|
||||||
targetKind: 'file',
|
state.appPath = context.appPath ?? '';
|
||||||
useTexthooker: true,
|
|
||||||
};
|
|
||||||
context.pluginRuntimeConfig = {
|
|
||||||
socketPath: '/tmp/subminer.sock',
|
|
||||||
binaryPath: '',
|
|
||||||
backend: 'auto',
|
|
||||||
autoStart: true,
|
|
||||||
autoStartVisibleOverlay: false,
|
|
||||||
autoStartPauseUntilReady: false,
|
|
||||||
osdMessages: false,
|
|
||||||
texthookerEnabled: false,
|
|
||||||
};
|
|
||||||
const appPath = context.appPath ?? '';
|
|
||||||
state.appPath = appPath;
|
|
||||||
state.overlayManagedByLauncher = false;
|
state.overlayManagedByLauncher = false;
|
||||||
const mpvProc = new EventEmitter() as EventEmitter & {
|
const mpvProc = new EventEmitter() as EventEmitter & {
|
||||||
exitCode: number | null;
|
exitCode: number | null;
|
||||||
@@ -233,32 +187,28 @@ test('plugin auto-start playback leaves app lifetime to managed-playback owner',
|
|||||||
mpvProc.killed = false;
|
mpvProc.killed = false;
|
||||||
mpvProc.kill = () => true;
|
mpvProc.kill = () => true;
|
||||||
let cleanupSawManagedOverlay = true;
|
let cleanupSawManagedOverlay = true;
|
||||||
|
const harness = makeHarness({
|
||||||
try {
|
context,
|
||||||
await runPlaybackCommandWithDeps(context, {
|
deps: {
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {},
|
|
||||||
chooseTarget: async () => ({ target: context.args.target, kind: 'file' }),
|
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async () => {
|
startMpv: async () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
mpvProc.exitCode = 0;
|
mpvProc.exitCode = 0;
|
||||||
mpvProc.emit('exit', 0);
|
mpvProc.emit('exit', 0);
|
||||||
}, 5);
|
}, 5);
|
||||||
},
|
},
|
||||||
waitForUnixSocketReady: async () => true,
|
|
||||||
startOverlay: async () => {
|
startOverlay: async () => {
|
||||||
throw new Error('startOverlay should not run when plugin auto-start is used');
|
throw new Error('startOverlay should not run when plugin auto-start is used');
|
||||||
},
|
},
|
||||||
launchAppCommandDetached: () => {},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {
|
cleanupPlaybackSession: async () => {
|
||||||
cleanupSawManagedOverlay = state.overlayManagedByLauncher;
|
cleanupSawManagedOverlay = state.overlayManagedByLauncher;
|
||||||
},
|
},
|
||||||
getMpvProc: () => mpvProc as NonNullable<typeof state.mpvProc>,
|
getMpvProc: () => mpvProc as NonNullable<typeof state.mpvProc>,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await harness.run();
|
||||||
|
|
||||||
assert.equal(cleanupSawManagedOverlay, false);
|
assert.equal(cleanupSawManagedOverlay, false);
|
||||||
} finally {
|
} finally {
|
||||||
state.appPath = '';
|
state.appPath = '';
|
||||||
@@ -267,258 +217,89 @@ test('plugin auto-start playback leaves app lifetime to managed-playback owner',
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('plugin auto-start playback attaches a warm background app through the launcher', async () => {
|
test('plugin auto-start playback attaches a warm background app through the launcher', async () => {
|
||||||
const context = createContext();
|
const harness = makeHarness({
|
||||||
context.args = {
|
context: createContext({
|
||||||
...context.args,
|
args: { ...FILE_TARGET, useTexthooker: true },
|
||||||
target: '/tmp/movie.mkv',
|
plugin: { texthookerEnabled: true },
|
||||||
targetKind: 'file',
|
}),
|
||||||
useTexthooker: true,
|
deps: { isAppControlServerAvailable: async () => true },
|
||||||
};
|
|
||||||
context.pluginRuntimeConfig = {
|
|
||||||
socketPath: '/tmp/subminer.sock',
|
|
||||||
binaryPath: '',
|
|
||||||
backend: 'auto',
|
|
||||||
autoStart: true,
|
|
||||||
autoStartVisibleOverlay: true,
|
|
||||||
autoStartPauseUntilReady: true,
|
|
||||||
osdMessages: false,
|
|
||||||
texthookerEnabled: true,
|
|
||||||
};
|
|
||||||
const calls: string[] = [];
|
|
||||||
const receivedStartMpvOptions: Record<string, unknown>[] = [];
|
|
||||||
|
|
||||||
await runPlaybackCommandWithDeps(context, {
|
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {},
|
|
||||||
chooseTarget: async () => ({ target: context.args.target, kind: 'file' }),
|
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async (
|
|
||||||
_target,
|
|
||||||
_targetKind,
|
|
||||||
_args,
|
|
||||||
_socketPath,
|
|
||||||
_appPath,
|
|
||||||
_preloadedSubtitles,
|
|
||||||
options,
|
|
||||||
) => {
|
|
||||||
calls.push('startMpv');
|
|
||||||
if (options) {
|
|
||||||
receivedStartMpvOptions.push(options as Record<string, unknown>);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
waitForUnixSocketReady: async () => true,
|
|
||||||
startOverlay: async (_appPath, _args, _socketPath, extraAppArgs = []) => {
|
|
||||||
calls.push(`startOverlay:${extraAppArgs.join(' ')}`);
|
|
||||||
},
|
|
||||||
launchAppCommandDetached: () => {},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {},
|
|
||||||
getMpvProc: () => null,
|
|
||||||
isAppControlServerAvailable: async () => true,
|
|
||||||
} as Parameters<typeof runPlaybackCommandWithDeps>[1] & {
|
|
||||||
isAppControlServerAvailable: () => Promise<boolean>;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(calls, ['startMpv', 'startOverlay:--show-visible-overlay --texthooker']);
|
await harness.run();
|
||||||
assert.equal(receivedStartMpvOptions[0]?.startPaused, true);
|
|
||||||
assert.equal(
|
assertRanInOrder(harness.events, 'startMpv', 'startOverlay');
|
||||||
(receivedStartMpvOptions[0]?.runtimePluginConfig as { autoStart?: boolean } | undefined)
|
assert.deepEqual(harness.overlayCalls[0]?.extraAppArgs, [
|
||||||
?.autoStart,
|
'--show-visible-overlay',
|
||||||
false,
|
'--texthooker',
|
||||||
);
|
]);
|
||||||
|
assert.equal(harness.startMpvOptions[0]?.startPaused, true);
|
||||||
|
assert.equal(harness.startMpvOptions[0]?.runtimePluginConfig?.autoStart, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('plugin auto-start attach mode reuses launcher-resolved config dir for app control', async () => {
|
test('plugin auto-start attach mode reuses launcher-resolved config dir for app control', async () => {
|
||||||
const context = createContext();
|
|
||||||
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
||||||
const originalAppData = process.env.APPDATA;
|
|
||||||
const xdgConfigHome = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-test-xdg-'));
|
const xdgConfigHome = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-test-xdg-'));
|
||||||
const expectedConfigDir = path.join(xdgConfigHome, 'SubMiner');
|
const expectedConfigDir = path.join(xdgConfigHome, 'SubMiner');
|
||||||
fs.mkdirSync(expectedConfigDir, { recursive: true });
|
fs.mkdirSync(expectedConfigDir, { recursive: true });
|
||||||
fs.writeFileSync(path.join(expectedConfigDir, 'config.jsonc'), '{}');
|
fs.writeFileSync(path.join(expectedConfigDir, 'config.jsonc'), '{}');
|
||||||
context.args = {
|
|
||||||
...context.args,
|
|
||||||
target: '/tmp/movie.mkv',
|
|
||||||
targetKind: 'file',
|
|
||||||
useTexthooker: true,
|
|
||||||
};
|
|
||||||
context.pluginRuntimeConfig = {
|
|
||||||
socketPath: '/tmp/subminer.sock',
|
|
||||||
binaryPath: '',
|
|
||||||
backend: 'auto',
|
|
||||||
autoStart: true,
|
|
||||||
autoStartVisibleOverlay: true,
|
|
||||||
autoStartPauseUntilReady: true,
|
|
||||||
osdMessages: false,
|
|
||||||
texthookerEnabled: true,
|
|
||||||
};
|
|
||||||
let availabilityConfigDir: string | undefined;
|
let availabilityConfigDir: string | undefined;
|
||||||
let overlayConfigDir: string | undefined;
|
const harness = makeHarness({
|
||||||
let overlayLoadingOsd: boolean | undefined;
|
context: createContext({
|
||||||
|
args: { ...FILE_TARGET, useTexthooker: true },
|
||||||
try {
|
plugin: { texthookerEnabled: true },
|
||||||
process.env.XDG_CONFIG_HOME = xdgConfigHome;
|
}),
|
||||||
process.env.APPDATA = xdgConfigHome;
|
deps: {
|
||||||
|
|
||||||
await runPlaybackCommandWithDeps(context, {
|
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {},
|
|
||||||
chooseTarget: async () => ({ target: context.args.target, kind: 'file' }),
|
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async (
|
|
||||||
_target,
|
|
||||||
_targetKind,
|
|
||||||
_args,
|
|
||||||
_socketPath,
|
|
||||||
_appPath,
|
|
||||||
_preloadedSubtitles,
|
|
||||||
options,
|
|
||||||
) => {
|
|
||||||
overlayLoadingOsd = (
|
|
||||||
options?.runtimePluginConfig as { overlayLoadingOsd?: boolean } | undefined
|
|
||||||
)?.overlayLoadingOsd;
|
|
||||||
},
|
|
||||||
waitForUnixSocketReady: async () => true,
|
|
||||||
startOverlay: async (_appPath, _args, _socketPath, _extraAppArgs = [], configDir) => {
|
|
||||||
overlayConfigDir = configDir;
|
|
||||||
},
|
|
||||||
launchAppCommandDetached: () => {},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {},
|
|
||||||
getMpvProc: () => null,
|
|
||||||
isAppControlServerAvailable: async (_logLevel, configDir) => {
|
isAppControlServerAvailable: async (_logLevel, configDir) => {
|
||||||
availabilityConfigDir = configDir;
|
availabilityConfigDir = configDir;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await withEnv({ XDG_CONFIG_HOME: xdgConfigHome, APPDATA: xdgConfigHome }, () => harness.run());
|
||||||
|
|
||||||
assert.equal(availabilityConfigDir, expectedConfigDir);
|
assert.equal(availabilityConfigDir, expectedConfigDir);
|
||||||
assert.equal(overlayConfigDir, expectedConfigDir);
|
assert.equal(harness.overlayCalls[0]?.configDir, expectedConfigDir);
|
||||||
assert.equal(overlayLoadingOsd, true);
|
assert.equal(harness.startMpvOptions[0]?.runtimePluginConfig?.overlayLoadingOsd, true);
|
||||||
} finally {
|
} finally {
|
||||||
if (originalXdgConfigHome === undefined) {
|
|
||||||
delete process.env.XDG_CONFIG_HOME;
|
|
||||||
} else {
|
|
||||||
process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
|
|
||||||
}
|
|
||||||
if (originalAppData === undefined) {
|
|
||||||
delete process.env.APPDATA;
|
|
||||||
} else {
|
|
||||||
process.env.APPDATA = originalAppData;
|
|
||||||
}
|
|
||||||
fs.rmSync(xdgConfigHome, { recursive: true, force: true });
|
fs.rmSync(xdgConfigHome, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('plugin auto-start attach mode omits texthooker flag when CLI texthooker is disabled', async () => {
|
test('plugin auto-start attach mode omits texthooker flag when CLI texthooker is disabled', async () => {
|
||||||
const context = createContext();
|
const harness = makeHarness({
|
||||||
context.args = {
|
context: createContext({ args: FILE_TARGET, plugin: { texthookerEnabled: true } }),
|
||||||
...context.args,
|
deps: { isAppControlServerAvailable: async () => true },
|
||||||
target: '/tmp/movie.mkv',
|
|
||||||
targetKind: 'file',
|
|
||||||
};
|
|
||||||
context.pluginRuntimeConfig = {
|
|
||||||
socketPath: '/tmp/subminer.sock',
|
|
||||||
binaryPath: '',
|
|
||||||
backend: 'auto',
|
|
||||||
autoStart: true,
|
|
||||||
autoStartVisibleOverlay: true,
|
|
||||||
autoStartPauseUntilReady: true,
|
|
||||||
osdMessages: false,
|
|
||||||
texthookerEnabled: true,
|
|
||||||
};
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
await runPlaybackCommandWithDeps(context, {
|
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {},
|
|
||||||
chooseTarget: async () => ({ target: context.args.target, kind: 'file' }),
|
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async () => {
|
|
||||||
calls.push('startMpv');
|
|
||||||
},
|
|
||||||
waitForUnixSocketReady: async () => true,
|
|
||||||
startOverlay: async (_appPath, _args, _socketPath, extraAppArgs = []) => {
|
|
||||||
calls.push(`startOverlay:${extraAppArgs.join(' ')}`);
|
|
||||||
},
|
|
||||||
launchAppCommandDetached: () => {},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {},
|
|
||||||
getMpvProc: () => null,
|
|
||||||
isAppControlServerAvailable: async () => true,
|
|
||||||
} as Parameters<typeof runPlaybackCommandWithDeps>[1] & {
|
|
||||||
isAppControlServerAvailable: () => Promise<boolean>;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(calls, ['startMpv', 'startOverlay:--show-visible-overlay']);
|
await harness.run();
|
||||||
|
|
||||||
|
assert.deepEqual(harness.overlayCalls[0]?.extraAppArgs, ['--show-visible-overlay']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('playback command ensures Linux runtime plugin before mpv launch', async () => {
|
test('playback command ensures Linux runtime plugin before mpv launch', async () => {
|
||||||
const context = createContext();
|
const harness = makeHarness({ context: createContext({ args: FILE_TARGET }) });
|
||||||
context.args = {
|
|
||||||
...context.args,
|
|
||||||
target: '/tmp/movie.mkv',
|
|
||||||
targetKind: 'file',
|
|
||||||
};
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
await runPlaybackCommandWithDeps(context, {
|
await harness.run();
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {
|
|
||||||
calls.push('plugin');
|
|
||||||
},
|
|
||||||
chooseTarget: async () => ({ target: context.args.target, kind: 'file' }),
|
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async () => {
|
|
||||||
calls.push('startMpv');
|
|
||||||
},
|
|
||||||
waitForUnixSocketReady: async () => true,
|
|
||||||
startOverlay: async () => {},
|
|
||||||
launchAppCommandDetached: () => {},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {},
|
|
||||||
getMpvProc: () => null,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(calls, ['plugin', 'startMpv']);
|
assertRanInOrder(harness.events, 'plugin', 'startMpv');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('rofi playback repairs support assets before opening the picker', async () => {
|
test('rofi playback repairs support assets before opening the picker', async () => {
|
||||||
const context = createContext();
|
const events: string[] = [];
|
||||||
context.args = {
|
const harness = makeHarness({
|
||||||
...context.args,
|
events,
|
||||||
target: '',
|
context: createContext({ args: { target: '', targetKind: '', useRofi: true } }),
|
||||||
targetKind: '',
|
deps: {
|
||||||
useRofi: true,
|
|
||||||
};
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
await runPlaybackCommandWithDeps(context, {
|
|
||||||
ensurePlaybackSetupReady: async () => {},
|
|
||||||
ensureRuntimePluginReady: async () => {
|
|
||||||
calls.push('assets');
|
|
||||||
},
|
|
||||||
chooseTarget: async () => {
|
chooseTarget: async () => {
|
||||||
calls.push('picker');
|
events.push('picker');
|
||||||
return { target: '/tmp/movie.mkv', kind: 'file' };
|
return { target: '/tmp/movie.mkv', kind: 'file' };
|
||||||
},
|
},
|
||||||
checkPickerDependencies: () => {},
|
checkPickerDependencies: () => {},
|
||||||
checkDependencies: () => {},
|
|
||||||
registerCleanup: () => {},
|
|
||||||
startMpv: async () => {
|
|
||||||
calls.push('startMpv');
|
|
||||||
},
|
},
|
||||||
waitForUnixSocketReady: async () => true,
|
|
||||||
startOverlay: async () => {},
|
|
||||||
launchAppCommandDetached: () => {},
|
|
||||||
log: () => {},
|
|
||||||
cleanupPlaybackSession: async () => {},
|
|
||||||
getMpvProc: () => null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(calls, ['assets', 'picker', 'startMpv']);
|
await harness.run();
|
||||||
|
|
||||||
|
assertRanInOrder(events, 'plugin', 'picker', 'startMpv');
|
||||||
});
|
});
|
||||||
@@ -48,49 +48,6 @@ test('runSyncCommand proxies sync argv to the app in --sync-cli mode', async ()
|
|||||||
assert.equal(spawned.length, 1);
|
assert.equal(spawned.length, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('runSyncCommand forwards tokens verbatim and appends the effective log level', async () => {
|
|
||||||
const spawned: string[][] = [];
|
|
||||||
const deps: Partial<SyncCommandDeps> = {
|
|
||||||
runAppCommand: (_appPath, appArgs) => {
|
|
||||||
spawned.push(appArgs);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
await runSyncCommand(
|
|
||||||
makeContext({
|
|
||||||
syncCliTokens: [
|
|
||||||
'media-box',
|
|
||||||
'--pull',
|
|
||||||
'--remote-cmd',
|
|
||||||
'/opt/SubMiner.AppImage',
|
|
||||||
'--db',
|
|
||||||
'/tmp/db.sqlite',
|
|
||||||
'--force',
|
|
||||||
'--json',
|
|
||||||
],
|
|
||||||
logLevel: 'debug',
|
|
||||||
}),
|
|
||||||
deps,
|
|
||||||
);
|
|
||||||
|
|
||||||
assert.deepEqual(spawned, [
|
|
||||||
[
|
|
||||||
'--sync-cli',
|
|
||||||
'sync',
|
|
||||||
'media-box',
|
|
||||||
'--pull',
|
|
||||||
'--remote-cmd',
|
|
||||||
'/opt/SubMiner.AppImage',
|
|
||||||
'--db',
|
|
||||||
'/tmp/db.sqlite',
|
|
||||||
'--force',
|
|
||||||
'--json',
|
|
||||||
'--log-level',
|
|
||||||
'debug',
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('runSyncCommand fails with a clear message when the app binary is missing', async () => {
|
test('runSyncCommand fails with a clear message when the app binary is missing', async () => {
|
||||||
const deps: Partial<SyncCommandDeps> = {
|
const deps: Partial<SyncCommandDeps> = {
|
||||||
runAppCommand: () => {
|
runAppCommand: () => {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
buildPluginRuntimeScriptOptParts,
|
buildPluginRuntimeScriptOptParts,
|
||||||
parsePluginRuntimeConfigFromMainConfig,
|
parsePluginRuntimeConfigFromMainConfig,
|
||||||
} from './config/plugin-runtime-config.js';
|
} from './config/plugin-runtime-config.js';
|
||||||
import { getDefaultSocketPath } from './types.js';
|
|
||||||
|
|
||||||
test('parseLauncherYoutubeSubgenConfig keeps only valid typed values', () => {
|
test('parseLauncherYoutubeSubgenConfig keeps only valid typed values', () => {
|
||||||
const parsed = parseLauncherYoutubeSubgenConfig({
|
const parsed = parseLauncherYoutubeSubgenConfig({
|
||||||
@@ -18,20 +17,11 @@ test('parseLauncherYoutubeSubgenConfig keeps only valid typed values', () => {
|
|||||||
secondarySub: {
|
secondarySub: {
|
||||||
secondarySubLanguages: ['eng', true, 'deu'],
|
secondarySubLanguages: ['eng', true, 'deu'],
|
||||||
},
|
},
|
||||||
jimaku: {
|
|
||||||
apiKey: 'abc',
|
|
||||||
apiKeyCommand: 'pass show key',
|
|
||||||
apiBaseUrl: 'https://jimaku.cc',
|
|
||||||
languagePreference: 'ja',
|
|
||||||
maxEntryResults: 8.7,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal('mode' in parsed, false);
|
assert.equal('mode' in parsed, false);
|
||||||
assert.deepEqual(parsed.primarySubLanguages, ['ja', 'en']);
|
assert.deepEqual(parsed.primarySubLanguages, ['ja', 'en']);
|
||||||
assert.deepEqual(parsed.secondarySubLanguages, ['eng', 'deu']);
|
assert.deepEqual(parsed.secondarySubLanguages, ['eng', 'deu']);
|
||||||
assert.equal(parsed.jimakuLanguagePreference, 'ja');
|
|
||||||
assert.equal(parsed.jimakuMaxEntryResults, 8);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parseLauncherJellyfinConfig omits legacy token and user id fields', () => {
|
test('parseLauncherJellyfinConfig omits legacy token and user id fields', () => {
|
||||||
@@ -207,10 +197,6 @@ test('buildPluginRuntimeScriptOptParts strips script-option delimiters from stri
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getDefaultSocketPath returns Windows named pipe default', () => {
|
|
||||||
assert.equal(getDefaultSocketPath('win32'), '\\\\.\\pipe\\subminer-socket');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('parseLauncherMpvConfig reads configured mpv profile', () => {
|
test('parseLauncherMpvConfig reads configured mpv profile', () => {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
parseLauncherMpvConfig({
|
parseLauncherMpvConfig({
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
import test from 'node:test';
|
|
||||||
import assert from 'node:assert/strict';
|
|
||||||
import { execFileSync } from 'node:child_process';
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
test('launcher root help lists subcommands', () => {
|
|
||||||
const output = execFileSync('bun', ['run', path.join(process.cwd(), 'launcher/main.ts'), '-h'], {
|
|
||||||
encoding: 'utf8',
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.match(output, /Commands:/);
|
|
||||||
assert.match(output, /jellyfin\|jf/);
|
|
||||||
assert.match(output, /doctor/);
|
|
||||||
assert.match(output, /config/);
|
|
||||||
assert.match(output, /mpv/);
|
|
||||||
assert.match(output, /logs/);
|
|
||||||
assert.match(output, /dictionary\|dict/);
|
|
||||||
assert.match(output, /texthooker/);
|
|
||||||
assert.match(output, /app\|bin/);
|
|
||||||
});
|
|
||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
applyRootOptionsToArgs,
|
applyRootOptionsToArgs,
|
||||||
createDefaultArgs,
|
createDefaultArgs,
|
||||||
} from './args-normalizer.js';
|
} from './args-normalizer.js';
|
||||||
|
import type { CliInvocations } from './cli-parser-builder.js';
|
||||||
|
|
||||||
function withTempDir<T>(fn: (dir: string) => T): T {
|
function withTempDir<T>(fn: (dir: string) => T): T {
|
||||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-launcher-args-'));
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-launcher-args-'));
|
||||||
@@ -19,6 +20,48 @@ function withTempDir<T>(fn: (dir: string) => T): T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** An invocations bag with nothing triggered; tests pass only the fields under test. */
|
||||||
|
function emptyInvocations(overrides: Partial<CliInvocations> = {}): CliInvocations {
|
||||||
|
return {
|
||||||
|
jellyfinInvocation: null,
|
||||||
|
configInvocation: null,
|
||||||
|
settingsInvocation: null,
|
||||||
|
youtubeBrowserInvocation: null,
|
||||||
|
mpvInvocation: null,
|
||||||
|
appInvocation: null,
|
||||||
|
dictionaryTriggered: false,
|
||||||
|
dictionaryTarget: null,
|
||||||
|
dictionaryLogLevel: null,
|
||||||
|
dictionaryCandidates: false,
|
||||||
|
dictionarySelect: false,
|
||||||
|
dictionaryAnilistId: null,
|
||||||
|
statsTriggered: false,
|
||||||
|
statsBackground: false,
|
||||||
|
statsStop: false,
|
||||||
|
statsCleanup: false,
|
||||||
|
statsCleanupVocab: false,
|
||||||
|
statsCleanupLifetime: false,
|
||||||
|
statsCleanupDuplicateLines: false,
|
||||||
|
statsCleanupDryRun: false,
|
||||||
|
statsCleanupLookbackDays: null,
|
||||||
|
statsLogLevel: null,
|
||||||
|
syncTriggered: false,
|
||||||
|
syncCliTokens: [],
|
||||||
|
syncLogLevel: null,
|
||||||
|
syncUiTriggered: false,
|
||||||
|
syncUiLogLevel: null,
|
||||||
|
doctorTriggered: false,
|
||||||
|
doctorLogLevel: null,
|
||||||
|
doctorRefreshKnownWords: false,
|
||||||
|
logsTriggered: false,
|
||||||
|
logsExport: false,
|
||||||
|
texthookerTriggered: false,
|
||||||
|
texthookerLogLevel: null,
|
||||||
|
texthookerOpenBrowser: false,
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
test('createDefaultArgs normalizes configured language codes', () => {
|
test('createDefaultArgs normalizes configured language codes', () => {
|
||||||
const parsed = createDefaultArgs({
|
const parsed = createDefaultArgs({
|
||||||
primarySubLanguages: [' JA ', 'jpn', 'ja'],
|
primarySubLanguages: [' JA ', 'jpn', 'ja'],
|
||||||
@@ -92,7 +135,9 @@ test('applyRootOptionsToArgs rejects unsupported targets', () => {
|
|||||||
test('applyInvocationsToArgs maps config and jellyfin invocation state', () => {
|
test('applyInvocationsToArgs maps config and jellyfin invocation state', () => {
|
||||||
const parsed = createDefaultArgs({});
|
const parsed = createDefaultArgs({});
|
||||||
|
|
||||||
applyInvocationsToArgs(parsed, {
|
applyInvocationsToArgs(
|
||||||
|
parsed,
|
||||||
|
emptyInvocations({
|
||||||
jellyfinInvocation: {
|
jellyfinInvocation: {
|
||||||
action: 'play',
|
action: 'play',
|
||||||
play: true,
|
play: true,
|
||||||
@@ -105,40 +150,8 @@ test('applyInvocationsToArgs maps config and jellyfin invocation state', () => {
|
|||||||
action: 'show',
|
action: 'show',
|
||||||
logLevel: 'warn',
|
logLevel: 'warn',
|
||||||
},
|
},
|
||||||
settingsInvocation: null,
|
}),
|
||||||
youtubeBrowserInvocation: null,
|
);
|
||||||
mpvInvocation: null,
|
|
||||||
appInvocation: null,
|
|
||||||
dictionaryTriggered: false,
|
|
||||||
dictionaryTarget: null,
|
|
||||||
dictionaryLogLevel: null,
|
|
||||||
dictionaryCandidates: false,
|
|
||||||
dictionarySelect: false,
|
|
||||||
dictionaryAnilistId: null,
|
|
||||||
statsTriggered: false,
|
|
||||||
statsBackground: false,
|
|
||||||
statsStop: false,
|
|
||||||
statsCleanup: false,
|
|
||||||
statsCleanupVocab: false,
|
|
||||||
statsCleanupLifetime: false,
|
|
||||||
statsCleanupDuplicateLines: false,
|
|
||||||
statsCleanupDryRun: false,
|
|
||||||
statsCleanupLookbackDays: null,
|
|
||||||
statsLogLevel: null,
|
|
||||||
syncTriggered: false,
|
|
||||||
syncCliTokens: [],
|
|
||||||
syncLogLevel: null,
|
|
||||||
syncUiTriggered: false,
|
|
||||||
syncUiLogLevel: null,
|
|
||||||
doctorTriggered: false,
|
|
||||||
doctorLogLevel: null,
|
|
||||||
doctorRefreshKnownWords: false,
|
|
||||||
logsTriggered: false,
|
|
||||||
logsExport: false,
|
|
||||||
texthookerTriggered: false,
|
|
||||||
texthookerLogLevel: null,
|
|
||||||
texthookerOpenBrowser: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(parsed.jellyfin, false);
|
assert.equal(parsed.jellyfin, false);
|
||||||
assert.equal(parsed.jellyfinPlay, true);
|
assert.equal(parsed.jellyfinPlay, true);
|
||||||
@@ -155,45 +168,14 @@ test('applyInvocationsToArgs maps config and jellyfin invocation state', () => {
|
|||||||
test('applyInvocationsToArgs maps settings invocation to settings window', () => {
|
test('applyInvocationsToArgs maps settings invocation to settings window', () => {
|
||||||
const parsed = createDefaultArgs({});
|
const parsed = createDefaultArgs({});
|
||||||
|
|
||||||
applyInvocationsToArgs(parsed, {
|
applyInvocationsToArgs(
|
||||||
jellyfinInvocation: null,
|
parsed,
|
||||||
configInvocation: null,
|
emptyInvocations({
|
||||||
settingsInvocation: {
|
settingsInvocation: {
|
||||||
logLevel: undefined,
|
logLevel: undefined,
|
||||||
},
|
},
|
||||||
youtubeBrowserInvocation: null,
|
}),
|
||||||
mpvInvocation: null,
|
);
|
||||||
appInvocation: null,
|
|
||||||
dictionaryTriggered: false,
|
|
||||||
dictionaryTarget: null,
|
|
||||||
dictionaryLogLevel: null,
|
|
||||||
dictionaryCandidates: false,
|
|
||||||
dictionarySelect: false,
|
|
||||||
dictionaryAnilistId: null,
|
|
||||||
statsTriggered: false,
|
|
||||||
statsBackground: false,
|
|
||||||
statsStop: false,
|
|
||||||
statsCleanup: false,
|
|
||||||
statsCleanupVocab: false,
|
|
||||||
statsCleanupLifetime: false,
|
|
||||||
statsCleanupDuplicateLines: false,
|
|
||||||
statsCleanupDryRun: false,
|
|
||||||
statsCleanupLookbackDays: null,
|
|
||||||
statsLogLevel: null,
|
|
||||||
syncTriggered: false,
|
|
||||||
syncCliTokens: [],
|
|
||||||
syncLogLevel: null,
|
|
||||||
syncUiTriggered: false,
|
|
||||||
syncUiLogLevel: null,
|
|
||||||
doctorTriggered: false,
|
|
||||||
doctorLogLevel: null,
|
|
||||||
doctorRefreshKnownWords: false,
|
|
||||||
logsTriggered: false,
|
|
||||||
logsExport: false,
|
|
||||||
texthookerTriggered: false,
|
|
||||||
texthookerLogLevel: null,
|
|
||||||
texthookerOpenBrowser: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(parsed.settings, true);
|
assert.equal(parsed.settings, true);
|
||||||
assert.equal(parsed.configPath, false);
|
assert.equal(parsed.configPath, false);
|
||||||
@@ -203,45 +185,14 @@ test('applyInvocationsToArgs fails when config invocation has no action', () =>
|
|||||||
const parsed = createDefaultArgs({});
|
const parsed = createDefaultArgs({});
|
||||||
|
|
||||||
const error = withProcessExitIntercept(() => {
|
const error = withProcessExitIntercept(() => {
|
||||||
applyInvocationsToArgs(parsed, {
|
applyInvocationsToArgs(
|
||||||
jellyfinInvocation: null,
|
parsed,
|
||||||
|
emptyInvocations({
|
||||||
configInvocation: {
|
configInvocation: {
|
||||||
action: undefined,
|
action: undefined,
|
||||||
},
|
},
|
||||||
settingsInvocation: null,
|
}),
|
||||||
youtubeBrowserInvocation: null,
|
);
|
||||||
mpvInvocation: null,
|
|
||||||
appInvocation: null,
|
|
||||||
dictionaryTriggered: false,
|
|
||||||
dictionaryTarget: null,
|
|
||||||
dictionaryLogLevel: null,
|
|
||||||
dictionaryCandidates: false,
|
|
||||||
dictionarySelect: false,
|
|
||||||
dictionaryAnilistId: null,
|
|
||||||
statsTriggered: false,
|
|
||||||
statsBackground: false,
|
|
||||||
statsStop: false,
|
|
||||||
statsCleanup: false,
|
|
||||||
statsCleanupVocab: false,
|
|
||||||
statsCleanupLifetime: false,
|
|
||||||
statsCleanupDuplicateLines: false,
|
|
||||||
statsCleanupDryRun: false,
|
|
||||||
statsCleanupLookbackDays: null,
|
|
||||||
statsLogLevel: null,
|
|
||||||
syncTriggered: false,
|
|
||||||
syncCliTokens: [],
|
|
||||||
syncLogLevel: null,
|
|
||||||
syncUiTriggered: false,
|
|
||||||
syncUiLogLevel: null,
|
|
||||||
doctorTriggered: false,
|
|
||||||
doctorLogLevel: null,
|
|
||||||
doctorRefreshKnownWords: false,
|
|
||||||
logsTriggered: false,
|
|
||||||
logsExport: false,
|
|
||||||
texthookerTriggered: false,
|
|
||||||
texthookerLogLevel: null,
|
|
||||||
texthookerOpenBrowser: false,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(error.code, 1);
|
assert.equal(error.code, 1);
|
||||||
@@ -251,43 +202,13 @@ test('applyInvocationsToArgs fails when config invocation has no action', () =>
|
|||||||
test('applyInvocationsToArgs maps texthooker browser-open request', () => {
|
test('applyInvocationsToArgs maps texthooker browser-open request', () => {
|
||||||
const parsed = createDefaultArgs({});
|
const parsed = createDefaultArgs({});
|
||||||
|
|
||||||
applyInvocationsToArgs(parsed, {
|
applyInvocationsToArgs(
|
||||||
jellyfinInvocation: null,
|
parsed,
|
||||||
configInvocation: null,
|
emptyInvocations({
|
||||||
settingsInvocation: null,
|
|
||||||
youtubeBrowserInvocation: null,
|
|
||||||
mpvInvocation: null,
|
|
||||||
appInvocation: null,
|
|
||||||
dictionaryTriggered: false,
|
|
||||||
dictionaryTarget: null,
|
|
||||||
dictionaryLogLevel: null,
|
|
||||||
dictionaryCandidates: false,
|
|
||||||
dictionarySelect: false,
|
|
||||||
dictionaryAnilistId: null,
|
|
||||||
statsTriggered: false,
|
|
||||||
statsBackground: false,
|
|
||||||
statsStop: false,
|
|
||||||
statsCleanup: false,
|
|
||||||
statsCleanupVocab: false,
|
|
||||||
statsCleanupLifetime: false,
|
|
||||||
statsCleanupDuplicateLines: false,
|
|
||||||
statsCleanupDryRun: false,
|
|
||||||
statsCleanupLookbackDays: null,
|
|
||||||
statsLogLevel: null,
|
|
||||||
syncTriggered: false,
|
|
||||||
syncCliTokens: [],
|
|
||||||
syncLogLevel: null,
|
|
||||||
syncUiTriggered: false,
|
|
||||||
syncUiLogLevel: null,
|
|
||||||
doctorTriggered: false,
|
|
||||||
doctorLogLevel: null,
|
|
||||||
doctorRefreshKnownWords: false,
|
|
||||||
logsTriggered: false,
|
|
||||||
logsExport: false,
|
|
||||||
texthookerTriggered: true,
|
texthookerTriggered: true,
|
||||||
texthookerLogLevel: null,
|
|
||||||
texthookerOpenBrowser: true,
|
texthookerOpenBrowser: true,
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
assert.equal(parsed.texthookerOnly, true);
|
assert.equal(parsed.texthookerOnly, true);
|
||||||
assert.equal(parsed.texthookerOpenBrowser, true);
|
assert.equal(parsed.texthookerOpenBrowser, true);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import type {
|
|||||||
LogLevel,
|
LogLevel,
|
||||||
} from '../types.js';
|
} from '../types.js';
|
||||||
import {
|
import {
|
||||||
DEFAULT_JIMAKU_API_BASE_URL,
|
|
||||||
DEFAULT_YOUTUBE_PRIMARY_SUB_LANGS,
|
DEFAULT_YOUTUBE_PRIMARY_SUB_LANGS,
|
||||||
DEFAULT_YOUTUBE_SECONDARY_SUB_LANGS,
|
DEFAULT_YOUTUBE_SECONDARY_SUB_LANGS,
|
||||||
} from '../types.js';
|
} from '../types.js';
|
||||||
@@ -125,11 +124,6 @@ export function createDefaultArgs(
|
|||||||
recursive: false,
|
recursive: false,
|
||||||
profile: mpvConfig.profile ?? '',
|
profile: mpvConfig.profile ?? '',
|
||||||
startOverlay: false,
|
startOverlay: false,
|
||||||
jimakuApiKey: process.env.SUBMINER_JIMAKU_API_KEY || '',
|
|
||||||
jimakuApiKeyCommand: process.env.SUBMINER_JIMAKU_API_KEY_COMMAND || '',
|
|
||||||
jimakuApiBaseUrl: process.env.SUBMINER_JIMAKU_API_BASE_URL || DEFAULT_JIMAKU_API_BASE_URL,
|
|
||||||
jimakuLanguagePreference: launcherConfig.jimakuLanguagePreference || 'ja',
|
|
||||||
jimakuMaxEntryResults: launcherConfig.jimakuMaxEntryResults || 10,
|
|
||||||
jellyfin: false,
|
jellyfin: false,
|
||||||
jellyfinLogin: false,
|
jellyfinLogin: false,
|
||||||
jellyfinLogout: false,
|
jellyfinLogout: false,
|
||||||
@@ -184,15 +178,6 @@ export function createDefaultArgs(
|
|||||||
targetKind: '',
|
targetKind: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (launcherConfig.jimakuApiKey) parsed.jimakuApiKey = launcherConfig.jimakuApiKey;
|
|
||||||
if (launcherConfig.jimakuApiKeyCommand)
|
|
||||||
parsed.jimakuApiKeyCommand = launcherConfig.jimakuApiKeyCommand;
|
|
||||||
if (launcherConfig.jimakuApiBaseUrl) parsed.jimakuApiBaseUrl = launcherConfig.jimakuApiBaseUrl;
|
|
||||||
if (launcherConfig.jimakuLanguagePreference)
|
|
||||||
parsed.jimakuLanguagePreference = launcherConfig.jimakuLanguagePreference;
|
|
||||||
if (launcherConfig.jimakuMaxEntryResults !== undefined)
|
|
||||||
parsed.jimakuMaxEntryResults = launcherConfig.jimakuMaxEntryResults;
|
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,31 +16,9 @@ export function parseLauncherYoutubeSubgenConfig(
|
|||||||
secondarySubRaw && typeof secondarySubRaw === 'object'
|
secondarySubRaw && typeof secondarySubRaw === 'object'
|
||||||
? (secondarySubRaw as Record<string, unknown>)
|
? (secondarySubRaw as Record<string, unknown>)
|
||||||
: null;
|
: null;
|
||||||
const jimakuRaw = root.jimaku;
|
|
||||||
const jimaku =
|
|
||||||
jimakuRaw && typeof jimakuRaw === 'object' ? (jimakuRaw as Record<string, unknown>) : null;
|
|
||||||
|
|
||||||
const jimakuLanguagePreference = jimaku?.languagePreference;
|
|
||||||
const jimakuMaxEntryResults = jimaku?.maxEntryResults;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
primarySubLanguages: asStringArray(youtube?.primarySubLanguages),
|
primarySubLanguages: asStringArray(youtube?.primarySubLanguages),
|
||||||
secondarySubLanguages: asStringArray(secondarySub?.secondarySubLanguages),
|
secondarySubLanguages: asStringArray(secondarySub?.secondarySubLanguages),
|
||||||
jimakuApiKey: typeof jimaku?.apiKey === 'string' ? jimaku.apiKey : undefined,
|
|
||||||
jimakuApiKeyCommand:
|
|
||||||
typeof jimaku?.apiKeyCommand === 'string' ? jimaku.apiKeyCommand : undefined,
|
|
||||||
jimakuApiBaseUrl: typeof jimaku?.apiBaseUrl === 'string' ? jimaku.apiBaseUrl : undefined,
|
|
||||||
jimakuLanguagePreference:
|
|
||||||
jimakuLanguagePreference === 'ja' ||
|
|
||||||
jimakuLanguagePreference === 'en' ||
|
|
||||||
jimakuLanguagePreference === 'none'
|
|
||||||
? jimakuLanguagePreference
|
|
||||||
: undefined,
|
|
||||||
jimakuMaxEntryResults:
|
|
||||||
typeof jimakuMaxEntryResults === 'number' &&
|
|
||||||
Number.isFinite(jimakuMaxEntryResults) &&
|
|
||||||
jimakuMaxEntryResults > 0
|
|
||||||
? Math.floor(jimakuMaxEntryResults)
|
|
||||||
: undefined,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+287
-103
@@ -1,83 +1,40 @@
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
import assert from 'node:assert/strict';
|
import assert from 'node:assert/strict';
|
||||||
import type { Args } from './types.js';
|
import path from 'node:path';
|
||||||
import { runJellyfinPlayMenuWithDeps } from './jellyfin.js';
|
import {
|
||||||
|
buildForwardedJellyfinAppArgs,
|
||||||
|
buildRootSearchGroups,
|
||||||
|
classifyJellyfinChildSelection,
|
||||||
|
deriveJellyfinTokenStorePath,
|
||||||
|
hasStoredJellyfinSession,
|
||||||
|
parseEpisodePathFromDisplay,
|
||||||
|
parseJellyfinErrorFromAppOutput,
|
||||||
|
parseJellyfinAppReply,
|
||||||
|
parseJellyfinItemsReply,
|
||||||
|
parseJellyfinLibrariesReply,
|
||||||
|
parseJellyfinPreviewAuthResponse,
|
||||||
|
runJellyfinPlayMenuWithDeps,
|
||||||
|
shouldRetryWithStartForNoRunningInstance,
|
||||||
|
} from './jellyfin.js';
|
||||||
|
import { makeLauncherArgs } from './test-support/args.js';
|
||||||
|
import { withEnv } from './test-support/env.js';
|
||||||
|
|
||||||
function createArgs(): Args {
|
class HandoffComplete extends Error {}
|
||||||
return {
|
|
||||||
backend: 'auto',
|
|
||||||
directory: '.',
|
|
||||||
recursive: false,
|
|
||||||
profile: '',
|
|
||||||
startOverlay: false,
|
|
||||||
youtubePrimarySubLangs: [],
|
|
||||||
youtubeSecondarySubLangs: [],
|
|
||||||
youtubeAudioLangs: [],
|
|
||||||
useTexthooker: false,
|
|
||||||
autoStartOverlay: false,
|
|
||||||
texthookerOnly: false,
|
|
||||||
texthookerOpenBrowser: false,
|
|
||||||
useRofi: false,
|
|
||||||
history: false,
|
|
||||||
sync: false,
|
|
||||||
syncCliTokens: [],
|
|
||||||
syncUi: false,
|
|
||||||
logLevel: 'info',
|
|
||||||
logRotation: 7,
|
|
||||||
passwordStore: '',
|
|
||||||
target: '',
|
|
||||||
targetKind: '',
|
|
||||||
jimakuApiKey: '',
|
|
||||||
jimakuApiKeyCommand: '',
|
|
||||||
jimakuApiBaseUrl: '',
|
|
||||||
jimakuLanguagePreference: 'ja',
|
|
||||||
jimakuMaxEntryResults: 20,
|
|
||||||
jellyfin: false,
|
|
||||||
jellyfinLogin: false,
|
|
||||||
jellyfinLogout: false,
|
|
||||||
jellyfinPlay: false,
|
|
||||||
jellyfinDiscovery: false,
|
|
||||||
dictionary: false,
|
|
||||||
dictionaryCandidates: false,
|
|
||||||
dictionarySelect: false,
|
|
||||||
stats: false,
|
|
||||||
doctor: false,
|
|
||||||
doctorRefreshKnownWords: false,
|
|
||||||
logsExport: false,
|
|
||||||
version: false,
|
|
||||||
settings: false,
|
|
||||||
youtubeBrowser: false,
|
|
||||||
configPath: false,
|
|
||||||
configShow: false,
|
|
||||||
mpvIdle: false,
|
|
||||||
mpvSocket: false,
|
|
||||||
mpvStatus: false,
|
|
||||||
mpvArgs: '',
|
|
||||||
appPassthrough: false,
|
|
||||||
appArgs: [],
|
|
||||||
jellyfinServer: 'https://jellyfin.example.test',
|
|
||||||
jellyfinUsername: '',
|
|
||||||
jellyfinPassword: '',
|
|
||||||
launchMode: 'normal',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
test('Jellyfin playback ensures Linux runtime plugin before detached idle mpv bootstrap', async () => {
|
type PlayMenuDeps = NonNullable<Parameters<typeof runJellyfinPlayMenuWithDeps>[4]>;
|
||||||
const originalAccessToken = process.env.SUBMINER_JELLYFIN_ACCESS_TOKEN;
|
|
||||||
const originalUserId = process.env.SUBMINER_JELLYFIN_USER_ID;
|
|
||||||
process.env.SUBMINER_JELLYFIN_ACCESS_TOKEN = 'token';
|
|
||||||
process.env.SUBMINER_JELLYFIN_USER_ID = 'user';
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
try {
|
/**
|
||||||
await assert.rejects(
|
* Runs the play menu with fake deps and a direct env session. The app handoff never returns in
|
||||||
() =>
|
* production, so the fake throws `HandoffComplete` after recording its args into `handoff`.
|
||||||
runJellyfinPlayMenuWithDeps(
|
*/
|
||||||
'/tmp/SubMiner.AppImage',
|
async function runPlayMenu(options: {
|
||||||
createArgs(),
|
socketReady?: boolean;
|
||||||
'/tmp/subminer',
|
overrides?: Partial<PlayMenuDeps>;
|
||||||
'/tmp/subminer.sock',
|
args?: Parameters<typeof makeLauncherArgs>[0];
|
||||||
{
|
}) {
|
||||||
|
const launches: string[] = [];
|
||||||
|
const handoff: { appArgs: string[] | null } = { appArgs: null };
|
||||||
|
const deps: PlayMenuDeps = {
|
||||||
loadLauncherJellyfinConfig: () => ({}),
|
loadLauncherJellyfinConfig: () => ({}),
|
||||||
findRofiTheme: () => null,
|
findRofiTheme: () => null,
|
||||||
resolveJellyfinSelection: async () => 'item-123',
|
resolveJellyfinSelection: async () => 'item-123',
|
||||||
@@ -87,42 +44,269 @@ test('Jellyfin playback ensures Linux runtime plugin before detached idle mpv bo
|
|||||||
hasStoredJellyfinSession: () => true,
|
hasStoredJellyfinSession: () => true,
|
||||||
requestJellyfinPreviewAuthFromApp: async () => null,
|
requestJellyfinPreviewAuthFromApp: async () => null,
|
||||||
resolveLauncherMainConfigPath: () => '/tmp/SubMiner/config.jsonc',
|
resolveLauncherMainConfigPath: () => '/tmp/SubMiner/config.jsonc',
|
||||||
pathExists: () => false,
|
pathExists: () => options.socketReady ?? false,
|
||||||
ensureRuntimePluginReady: async () => {
|
ensureRuntimePluginReady: async () => {
|
||||||
calls.push('plugin');
|
launches.push('plugin');
|
||||||
},
|
|
||||||
waitForUnixSocketReady: async () => {
|
|
||||||
calls.push('wait');
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
|
waitForUnixSocketReady: async () => true,
|
||||||
launchMpvIdleDetached: async () => {
|
launchMpvIdleDetached: async () => {
|
||||||
calls.push('launch');
|
launches.push('launch');
|
||||||
},
|
},
|
||||||
resolveLauncherRuntimePluginPath: () => {
|
resolveLauncherRuntimePluginPath: () => '/tmp/plugin/main.lua',
|
||||||
calls.push('resolve');
|
runAppCommandWithInheritLogged: (_appPath, appArgs) => {
|
||||||
return '/tmp/plugin/main.lua';
|
handoff.appArgs = appArgs;
|
||||||
|
throw new HandoffComplete();
|
||||||
},
|
},
|
||||||
runAppCommandWithInheritLogged: () => {
|
isAppManagedByLauncher: () => false,
|
||||||
calls.push('handoff');
|
runAppCommandCaptureOutput: () => {
|
||||||
throw new Error('stop after handoff');
|
throw new Error('unexpected owned-app handoff');
|
||||||
|
},
|
||||||
|
waitForUnixSocketClosed: async () => {
|
||||||
|
throw new Error('unexpected wait for mpv to close');
|
||||||
|
},
|
||||||
|
exitProcess: () => {
|
||||||
|
throw new Error('unexpected exit');
|
||||||
},
|
},
|
||||||
log: () => {},
|
log: () => {},
|
||||||
},
|
...options.overrides,
|
||||||
|
};
|
||||||
|
|
||||||
|
await withEnv(
|
||||||
|
{ SUBMINER_JELLYFIN_ACCESS_TOKEN: 'token', SUBMINER_JELLYFIN_USER_ID: 'user' },
|
||||||
|
() =>
|
||||||
|
assert.rejects(
|
||||||
|
() =>
|
||||||
|
runJellyfinPlayMenuWithDeps(
|
||||||
|
'/tmp/SubMiner.AppImage',
|
||||||
|
makeLauncherArgs({ jellyfinServer: 'https://jellyfin.example.test', ...options.args }),
|
||||||
|
'/tmp/subminer',
|
||||||
|
'/tmp/subminer.sock',
|
||||||
|
deps,
|
||||||
|
),
|
||||||
|
HandoffComplete,
|
||||||
),
|
),
|
||||||
/stop after handoff/,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.deepEqual(calls, ['plugin', 'resolve', 'launch', 'wait', 'handoff']);
|
return { launches, appArgs: handoff.appArgs };
|
||||||
} finally {
|
}
|
||||||
if (originalAccessToken === undefined) {
|
|
||||||
delete process.env.SUBMINER_JELLYFIN_ACCESS_TOKEN;
|
test('Jellyfin playback launches the idle mpv with the runtime plugin, then hands the item to the app', async () => {
|
||||||
} else {
|
const { launches, appArgs } = await runPlayMenu({});
|
||||||
process.env.SUBMINER_JELLYFIN_ACCESS_TOKEN = originalAccessToken;
|
|
||||||
}
|
assert.deepEqual(launches, ['plugin', 'launch']);
|
||||||
if (originalUserId === undefined) {
|
assert.deepEqual(appArgs, ['--start', '--jellyfin-play', '--jellyfin-item-id=item-123']);
|
||||||
delete process.env.SUBMINER_JELLYFIN_USER_ID;
|
});
|
||||||
} else {
|
|
||||||
process.env.SUBMINER_JELLYFIN_USER_ID = originalUserId;
|
test('Jellyfin playback reuses a ready mpv socket instead of launching idle mpv', async () => {
|
||||||
}
|
const { launches, appArgs } = await runPlayMenu({ socketReady: true });
|
||||||
}
|
|
||||||
|
assert.deepEqual(launches, []);
|
||||||
|
assert.deepEqual(appArgs, ['--start', '--jellyfin-play', '--jellyfin-item-id=item-123']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Jellyfin playback in an app the picker started waits for mpv to close before exiting', async () => {
|
||||||
|
const events: string[] = [];
|
||||||
|
const { appArgs } = await runPlayMenu({
|
||||||
|
socketReady: true,
|
||||||
|
overrides: {
|
||||||
|
isAppManagedByLauncher: () => true,
|
||||||
|
runAppCommandCaptureOutput: (_appPath, appArgs) => {
|
||||||
|
events.push(`handoff ${appArgs.join(' ')}`);
|
||||||
|
return { status: 0, stdout: '', stderr: '' };
|
||||||
|
},
|
||||||
|
waitForUnixSocketClosed: async (socketPath) => {
|
||||||
|
events.push(`wait ${socketPath}`);
|
||||||
|
},
|
||||||
|
exitProcess: (code) => {
|
||||||
|
events.push(`exit ${code}`);
|
||||||
|
throw new HandoffComplete();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(appArgs, null);
|
||||||
|
assert.deepEqual(events, [
|
||||||
|
'handoff --start --jellyfin-play --jellyfin-item-id=item-123',
|
||||||
|
'wait /tmp/subminer.sock',
|
||||||
|
'exit 0',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseJellyfinAppReply maps library and item replies to picker entries', () => {
|
||||||
|
const libraries = parseJellyfinAppReply(
|
||||||
|
JSON.stringify({
|
||||||
|
libraries: [
|
||||||
|
{ id: 'lib1', name: 'Anime', collectionType: 'tvshows' },
|
||||||
|
{ id: 'lib1', name: 'Duplicate', collectionType: 'tvshows' },
|
||||||
|
{ name: 'No id' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
assert.ok(libraries?.ok);
|
||||||
|
assert.deepEqual(parseJellyfinLibrariesReply(libraries.payload), [
|
||||||
|
{ id: 'lib1', name: 'Anime', kind: 'tvshows' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
const items = parseJellyfinAppReply(
|
||||||
|
JSON.stringify({ items: [{ id: 'movie-1', title: 'Movie [Alt]', type: 'Movie' }] }),
|
||||||
|
);
|
||||||
|
assert.ok(items?.ok);
|
||||||
|
assert.deepEqual(parseJellyfinItemsReply(items.payload), [
|
||||||
|
{ id: 'movie-1', name: 'Movie [Alt]', type: 'Movie', display: 'Movie [Alt]' },
|
||||||
|
]);
|
||||||
|
assert.equal(parseJellyfinLibrariesReply(items.payload), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseJellyfinAppReply surfaces app errors and rejects partial files', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
parseJellyfinAppReply(
|
||||||
|
JSON.stringify({ error: 'Missing Jellyfin session. Run --jellyfin-login first.' }),
|
||||||
|
),
|
||||||
|
{ ok: false, error: 'Missing Jellyfin session. Run `subminer jellyfin -l` to log in again.' },
|
||||||
|
);
|
||||||
|
assert.equal(parseJellyfinAppReply(''), null);
|
||||||
|
assert.equal(parseJellyfinAppReply('{"libraries": ['), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('buildForwardedJellyfinAppArgs appends server, password store, and log level', () => {
|
||||||
|
const forwarded = buildForwardedJellyfinAppArgs(
|
||||||
|
{
|
||||||
|
jellyfinServer: 'https://jf.example.test/',
|
||||||
|
passwordStore: 'gnome-libsecret',
|
||||||
|
logLevel: 'info',
|
||||||
|
} as never,
|
||||||
|
['--jellyfin-libraries'],
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.deepEqual(forwarded, [
|
||||||
|
'--jellyfin-libraries',
|
||||||
|
'--jellyfin-server',
|
||||||
|
'https://jf.example.test',
|
||||||
|
'--password-store',
|
||||||
|
'gnome-libsecret',
|
||||||
|
'--log-level',
|
||||||
|
'info',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseJellyfinErrorFromAppOutput extracts bracketed error lines', () => {
|
||||||
|
const parsed = parseJellyfinErrorFromAppOutput(`
|
||||||
|
[subminer] - 2026-03-01 13:10:34 - WARN - [main] test warning
|
||||||
|
[2026-03-01T21:11:28.821Z] [ERROR] Missing Jellyfin session. Set SUBMINER_JELLYFIN_ACCESS_TOKEN and SUBMINER_JELLYFIN_USER_ID, then retry.
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
parsed,
|
||||||
|
'Missing Jellyfin session. Set SUBMINER_JELLYFIN_ACCESS_TOKEN and SUBMINER_JELLYFIN_USER_ID, then retry.',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseJellyfinErrorFromAppOutput extracts main runtime error lines', () => {
|
||||||
|
const parsed = parseJellyfinErrorFromAppOutput(`
|
||||||
|
[subminer] - 2026-03-01 13:10:34 - ERROR - [main] runJellyfinCommand failed: {"message":"Missing Jellyfin password."}
|
||||||
|
`);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
parsed,
|
||||||
|
'[main] runJellyfinCommand failed: {"message":"Missing Jellyfin password."}',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseJellyfinPreviewAuthResponse parses valid structured response payload', () => {
|
||||||
|
const parsed = parseJellyfinPreviewAuthResponse({
|
||||||
|
serverUrl: 'http://pve-main:8096/',
|
||||||
|
accessToken: 'token-123',
|
||||||
|
userId: 'user-1',
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(parsed, {
|
||||||
|
serverUrl: 'http://pve-main:8096',
|
||||||
|
accessToken: 'token-123',
|
||||||
|
userId: 'user-1',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseJellyfinPreviewAuthResponse returns null without a token', () => {
|
||||||
|
assert.equal(
|
||||||
|
parseJellyfinPreviewAuthResponse({
|
||||||
|
serverUrl: 'http://pve-main:8096',
|
||||||
|
accessToken: '',
|
||||||
|
userId: 'user-1',
|
||||||
|
}),
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('hasStoredJellyfinSession checks token-store existence', () => {
|
||||||
|
const configPath = path.join('/home/test', '.config', 'SubMiner', 'config.jsonc');
|
||||||
|
const tokenPath = deriveJellyfinTokenStorePath(configPath);
|
||||||
|
const exists = (candidate: string): boolean => candidate === tokenPath;
|
||||||
|
assert.equal(hasStoredJellyfinSession(configPath, exists), true);
|
||||||
|
assert.equal(
|
||||||
|
hasStoredJellyfinSession(path.join('/home/test', '.config', 'Other', 'alt.jsonc'), exists),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('shouldRetryWithStartForNoRunningInstance matches expected app lifecycle error', () => {
|
||||||
|
assert.equal(
|
||||||
|
shouldRetryWithStartForNoRunningInstance('No running instance. Use --start to launch the app.'),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
shouldRetryWithStartForNoRunningInstance(
|
||||||
|
'Missing Jellyfin session. Run --jellyfin-login first.',
|
||||||
|
),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseEpisodePathFromDisplay extracts series and season from episode display titles', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
parseEpisodePathFromDisplay('KONOSUBA S01E03 A Panty Treasure in This Right Hand!'),
|
||||||
|
{
|
||||||
|
seriesName: 'KONOSUBA',
|
||||||
|
seasonNumber: 1,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
assert.deepEqual(parseEpisodePathFromDisplay('Frieren S2E10 Something'), {
|
||||||
|
seriesName: 'Frieren',
|
||||||
|
seasonNumber: 2,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseEpisodePathFromDisplay returns null for non-episode displays', () => {
|
||||||
|
assert.equal(parseEpisodePathFromDisplay('Movie Title (Movie)'), null);
|
||||||
|
assert.equal(parseEpisodePathFromDisplay('Just A Name'), null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('buildRootSearchGroups excludes episodes and keeps containers/movies', () => {
|
||||||
|
const groups = buildRootSearchGroups([
|
||||||
|
{ id: 'series-1', name: 'The Eminence in Shadow', type: 'Series', display: 'x' },
|
||||||
|
{ id: 'movie-1', name: 'Spirited Away', type: 'Movie', display: 'x' },
|
||||||
|
{ id: 'episode-1', name: 'The Eminence in Shadow S01E01', type: 'Episode', display: 'x' },
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.deepEqual(groups, [
|
||||||
|
{
|
||||||
|
id: 'series-1',
|
||||||
|
name: 'The Eminence in Shadow',
|
||||||
|
type: 'Series',
|
||||||
|
display: 'The Eminence in Shadow (Series)',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'movie-1',
|
||||||
|
name: 'Spirited Away',
|
||||||
|
type: 'Movie',
|
||||||
|
display: 'Spirited Away (Movie)',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('classifyJellyfinChildSelection keeps container drilldown state instead of flattening', () => {
|
||||||
|
const next = classifyJellyfinChildSelection({ id: 'season-2', type: 'Season' });
|
||||||
|
assert.deepEqual(next, {
|
||||||
|
kind: 'container',
|
||||||
|
id: 'season-2',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
+192
-219
@@ -10,7 +10,8 @@ import type {
|
|||||||
JellyfinGroupEntry,
|
JellyfinGroupEntry,
|
||||||
} from './types.js';
|
} from './types.js';
|
||||||
import { shouldForwardLogLevel } from './types.js';
|
import { shouldForwardLogLevel } from './types.js';
|
||||||
import { log, fail, getMpvLogPath } from './log.js';
|
import type { JellyfinPreviewAuthPayload } from '../src/shared/jellyfin-cli-response.js';
|
||||||
|
import { log, fail } from './log.js';
|
||||||
import { nowMs } from './time.js';
|
import { nowMs } from './time.js';
|
||||||
import { commandExists, resolvePathMaybe, sleep } from './util.js';
|
import { commandExists, resolvePathMaybe, sleep } from './util.js';
|
||||||
import {
|
import {
|
||||||
@@ -23,11 +24,14 @@ import {
|
|||||||
import { loadLauncherJellyfinConfig } from './config.js';
|
import { loadLauncherJellyfinConfig } from './config.js';
|
||||||
import { resolveLauncherMainConfigPath } from './config/shared-config-reader.js';
|
import { resolveLauncherMainConfigPath } from './config/shared-config-reader.js';
|
||||||
import {
|
import {
|
||||||
|
adoptLauncherStartedApp,
|
||||||
|
isAppManagedByLauncher,
|
||||||
runAppCommandWithInheritLogged,
|
runAppCommandWithInheritLogged,
|
||||||
runAppCommandCaptureOutput,
|
runAppCommandCaptureOutput,
|
||||||
launchAppStartDetached,
|
launchAppBackgroundDetached,
|
||||||
launchMpvIdleDetached,
|
launchMpvIdleDetached,
|
||||||
resolveLauncherRuntimePluginPath,
|
resolveLauncherRuntimePluginPath,
|
||||||
|
waitForUnixSocketClosed,
|
||||||
waitForUnixSocketReady,
|
waitForUnixSocketReady,
|
||||||
} from './mpv.js';
|
} from './mpv.js';
|
||||||
import { ensureLinuxRuntimePluginAvailable } from './runtime-plugin-preflight.js';
|
import { ensureLinuxRuntimePluginAvailable } from './runtime-plugin-preflight.js';
|
||||||
@@ -52,6 +56,10 @@ type JellyfinPlayMenuDeps = {
|
|||||||
launchMpvIdleDetached: typeof launchMpvIdleDetached;
|
launchMpvIdleDetached: typeof launchMpvIdleDetached;
|
||||||
resolveLauncherRuntimePluginPath: typeof resolveLauncherRuntimePluginPath;
|
resolveLauncherRuntimePluginPath: typeof resolveLauncherRuntimePluginPath;
|
||||||
runAppCommandWithInheritLogged: typeof runAppCommandWithInheritLogged;
|
runAppCommandWithInheritLogged: typeof runAppCommandWithInheritLogged;
|
||||||
|
isAppManagedByLauncher: typeof isAppManagedByLauncher;
|
||||||
|
runAppCommandCaptureOutput: typeof runAppCommandCaptureOutput;
|
||||||
|
waitForUnixSocketClosed: typeof waitForUnixSocketClosed;
|
||||||
|
exitProcess: (code: number) => never;
|
||||||
log: typeof log;
|
log: typeof log;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,6 +83,10 @@ const defaultJellyfinPlayMenuDeps: JellyfinPlayMenuDeps = {
|
|||||||
launchMpvIdleDetached,
|
launchMpvIdleDetached,
|
||||||
resolveLauncherRuntimePluginPath,
|
resolveLauncherRuntimePluginPath,
|
||||||
runAppCommandWithInheritLogged,
|
runAppCommandWithInheritLogged,
|
||||||
|
isAppManagedByLauncher,
|
||||||
|
runAppCommandCaptureOutput,
|
||||||
|
waitForUnixSocketClosed,
|
||||||
|
exitProcess: (code) => process.exit(code),
|
||||||
log,
|
log,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,76 +183,77 @@ function stripAnsi(value: string): string {
|
|||||||
return value.replace(ANSI_ESCAPE_PATTERN, '');
|
return value.replace(ANSI_ESCAPE_PATTERN, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseNamedJellyfinRecord(payload: string): {
|
// Reply the app writes to --jellyfin-response-path; see src/shared/jellyfin-cli-response.ts.
|
||||||
name: string;
|
export type JellyfinAppReply =
|
||||||
id: string;
|
| { ok: true; payload: Record<string, unknown> }
|
||||||
type: string;
|
| { ok: false; error: string };
|
||||||
} | null {
|
|
||||||
const typeClose = payload.lastIndexOf(')');
|
|
||||||
if (typeClose !== payload.length - 1) return null;
|
|
||||||
|
|
||||||
const typeOpen = payload.lastIndexOf(' (');
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||||
if (typeOpen <= 0 || typeOpen >= typeClose) return null;
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
|
|
||||||
const idClose = payload.lastIndexOf(']', typeOpen);
|
|
||||||
if (idClose <= 0) return null;
|
|
||||||
|
|
||||||
const idOpen = payload.lastIndexOf(' [', idClose);
|
|
||||||
if (idOpen <= 0 || idOpen >= idClose) return null;
|
|
||||||
|
|
||||||
const name = payload.slice(0, idOpen).trim();
|
|
||||||
const id = payload.slice(idOpen + 2, idClose).trim();
|
|
||||||
const type = payload.slice(typeOpen + 2, typeClose).trim();
|
|
||||||
if (!name || !id || !type) return null;
|
|
||||||
|
|
||||||
return { name, id, type };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseJellyfinLibrariesFromAppOutput(output: string): JellyfinLibraryEntry[] {
|
function readString(record: Record<string, unknown>, key: string): string {
|
||||||
|
const value = record[key];
|
||||||
|
return typeof value === 'string' ? value.trim() : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseJellyfinAppReply(raw: string): JellyfinAppReply | null {
|
||||||
|
let parsed: unknown;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(raw);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!isRecord(parsed)) return null;
|
||||||
|
const error = readString(parsed, 'error');
|
||||||
|
if (error) return { ok: false, error: normalizeJellyfinAppError(error) };
|
||||||
|
return { ok: true, payload: parsed };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseJellyfinLibrariesReply(
|
||||||
|
payload: Record<string, unknown>,
|
||||||
|
): JellyfinLibraryEntry[] | null {
|
||||||
|
if (!Array.isArray(payload.libraries)) return null;
|
||||||
const libraries: JellyfinLibraryEntry[] = [];
|
const libraries: JellyfinLibraryEntry[] = [];
|
||||||
const seenIds = new Set<string>();
|
const seenIds = new Set<string>();
|
||||||
|
for (const entry of payload.libraries) {
|
||||||
for (const rawLine of output.split(/\r?\n/)) {
|
if (!isRecord(entry)) continue;
|
||||||
const line = stripAnsi(rawLine);
|
const id = readString(entry, 'id');
|
||||||
const markerIndex = line.indexOf('Jellyfin library:');
|
if (!id || seenIds.has(id)) continue;
|
||||||
if (markerIndex < 0) continue;
|
seenIds.add(id);
|
||||||
const payload = line.slice(markerIndex + 'Jellyfin library:'.length).trim();
|
|
||||||
const parsed = parseNamedJellyfinRecord(payload);
|
|
||||||
if (!parsed || seenIds.has(parsed.id)) continue;
|
|
||||||
seenIds.add(parsed.id);
|
|
||||||
libraries.push({
|
libraries.push({
|
||||||
id: parsed.id,
|
id,
|
||||||
name: parsed.name,
|
name: readString(entry, 'name') || 'Untitled',
|
||||||
kind: parsed.type,
|
kind: readString(entry, 'collectionType') || 'unknown',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return libraries;
|
return libraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseJellyfinItemsFromAppOutput(output: string): JellyfinItemEntry[] {
|
export function parseJellyfinItemsReply(
|
||||||
|
payload: Record<string, unknown>,
|
||||||
|
): JellyfinItemEntry[] | null {
|
||||||
|
if (!Array.isArray(payload.items)) return null;
|
||||||
const items: JellyfinItemEntry[] = [];
|
const items: JellyfinItemEntry[] = [];
|
||||||
const seenIds = new Set<string>();
|
const seenIds = new Set<string>();
|
||||||
|
for (const entry of payload.items) {
|
||||||
for (const rawLine of output.split(/\r?\n/)) {
|
if (!isRecord(entry)) continue;
|
||||||
const line = stripAnsi(rawLine);
|
const id = readString(entry, 'id');
|
||||||
const markerIndex = line.indexOf('Jellyfin item:');
|
if (!id || seenIds.has(id)) continue;
|
||||||
if (markerIndex < 0) continue;
|
seenIds.add(id);
|
||||||
const payload = line.slice(markerIndex + 'Jellyfin item:'.length).trim();
|
const title = readString(entry, 'title') || 'Untitled';
|
||||||
const parsed = parseNamedJellyfinRecord(payload);
|
items.push({ id, name: title, type: readString(entry, 'type'), display: title });
|
||||||
if (!parsed || seenIds.has(parsed.id)) continue;
|
|
||||||
seenIds.add(parsed.id);
|
|
||||||
items.push({
|
|
||||||
id: parsed.id,
|
|
||||||
name: parsed.name,
|
|
||||||
type: parsed.type,
|
|
||||||
display: parsed.name,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function normalizeJellyfinAppError(message: string): string {
|
||||||
|
if (message.includes('Missing Jellyfin session')) {
|
||||||
|
return 'Missing Jellyfin session. Run `subminer jellyfin -l` to log in again.';
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
export function parseJellyfinErrorFromAppOutput(output: string): string {
|
export function parseJellyfinErrorFromAppOutput(output: string): string {
|
||||||
const lines = output.split(/\r?\n/).map((line) => stripAnsi(line).trim());
|
const lines = output.split(/\r?\n/).map((line) => stripAnsi(line).trim());
|
||||||
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
||||||
@@ -260,41 +273,20 @@ export function parseJellyfinErrorFromAppOutput(output: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (line.includes('Missing Jellyfin session')) {
|
if (line.includes('Missing Jellyfin session')) {
|
||||||
return 'Missing Jellyfin session. Run `subminer jellyfin -l` to log in again.';
|
return normalizeJellyfinAppError(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
type JellyfinPreviewAuthResponse = {
|
export function parseJellyfinPreviewAuthResponse(
|
||||||
serverUrl: string;
|
payload: Record<string, unknown>,
|
||||||
accessToken: string;
|
): JellyfinPreviewAuthPayload | null {
|
||||||
userId: string;
|
const serverUrl = sanitizeServerUrl(readString(payload, 'serverUrl'));
|
||||||
};
|
const accessToken = readString(payload, 'accessToken');
|
||||||
|
const userId = readString(payload, 'userId');
|
||||||
export function parseJellyfinPreviewAuthResponse(raw: string): JellyfinPreviewAuthResponse | null {
|
|
||||||
if (!raw || raw.trim().length === 0) return null;
|
|
||||||
let parsed: unknown;
|
|
||||||
try {
|
|
||||||
parsed = JSON.parse(raw);
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!parsed || typeof parsed !== 'object') return null;
|
|
||||||
|
|
||||||
const candidate = parsed as Record<string, unknown>;
|
|
||||||
const serverUrl = sanitizeServerUrl(
|
|
||||||
typeof candidate.serverUrl === 'string' ? candidate.serverUrl : '',
|
|
||||||
);
|
|
||||||
const accessToken = typeof candidate.accessToken === 'string' ? candidate.accessToken.trim() : '';
|
|
||||||
const userId = typeof candidate.userId === 'string' ? candidate.userId.trim() : '';
|
|
||||||
if (!serverUrl || !accessToken) return null;
|
if (!serverUrl || !accessToken) return null;
|
||||||
|
return { serverUrl, accessToken, userId };
|
||||||
return {
|
|
||||||
serverUrl,
|
|
||||||
accessToken,
|
|
||||||
userId,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function shouldRetryWithStartForNoRunningInstance(errorMessage: string): boolean {
|
export function shouldRetryWithStartForNoRunningInstance(errorMessage: string): boolean {
|
||||||
@@ -312,19 +304,6 @@ export function hasStoredJellyfinSession(
|
|||||||
return exists(deriveJellyfinTokenStorePath(configPath));
|
return exists(deriveJellyfinTokenStorePath(configPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readUtf8FileAppendedSince(logPath: string, offsetBytes: number): string {
|
|
||||||
try {
|
|
||||||
const buffer = fs.readFileSync(logPath);
|
|
||||||
if (buffer.length === 0) return '';
|
|
||||||
const normalizedOffset =
|
|
||||||
Number.isFinite(offsetBytes) && offsetBytes >= 0 ? Math.floor(offsetBytes) : 0;
|
|
||||||
const startOffset = normalizedOffset > buffer.length ? 0 : normalizedOffset;
|
|
||||||
return buffer.subarray(startOffset).toString('utf8');
|
|
||||||
} catch {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseEpisodePathFromDisplay(
|
export function parseEpisodePathFromDisplay(
|
||||||
display: string,
|
display: string,
|
||||||
): { seriesName: string; seasonNumber: number } | null {
|
): { seriesName: string; seasonNumber: number } | null {
|
||||||
@@ -421,145 +400,79 @@ export function buildForwardedJellyfinAppArgs(args: Args, appArgs: string[]): st
|
|||||||
return forwarded;
|
return forwarded;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runAppJellyfinListCommand(
|
const JELLYFIN_APP_REPLY_TIMEOUT_MS = 60_000;
|
||||||
appPath: string,
|
const JELLYFIN_PREVIEW_AUTH_TIMEOUT_MS = 15_000;
|
||||||
args: Args,
|
|
||||||
appArgs: string[],
|
function readJellyfinAppReply(responsePath: string): JellyfinAppReply | null {
|
||||||
label: string,
|
try {
|
||||||
): Promise<string> {
|
return parseJellyfinAppReply(fs.readFileSync(responsePath, 'utf8'));
|
||||||
const attempt = await runAppJellyfinCommand(appPath, args, appArgs, label);
|
} catch {
|
||||||
if (attempt.status !== 0) {
|
return null;
|
||||||
const message = attempt.output.trim();
|
|
||||||
fail(message || `${label} failed.`);
|
|
||||||
}
|
}
|
||||||
if (attempt.error) {
|
|
||||||
fail(attempt.error);
|
|
||||||
}
|
|
||||||
return attempt.output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runAppJellyfinCommand(
|
// Runs a Jellyfin command in the app and waits for the reply it writes to a temp file. The helper
|
||||||
|
// process usually hands the command to an already-running instance and exits at once with no
|
||||||
|
// output, so the reply file is the only result channel that works in both cases.
|
||||||
|
async function requestJellyfinReplyFromApp(
|
||||||
appPath: string,
|
appPath: string,
|
||||||
args: Args,
|
args: Args,
|
||||||
appArgs: string[],
|
appArgs: string[],
|
||||||
label: string,
|
label: string,
|
||||||
): Promise<{ status: number; output: string; error: string; logOffset: number }> {
|
timeoutMs: number,
|
||||||
const forwardedBase = buildForwardedJellyfinAppArgs(args, appArgs);
|
): Promise<JellyfinAppReply> {
|
||||||
|
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-jf-reply-'));
|
||||||
|
const responsePath = path.join(tmpDir, 'response.json');
|
||||||
|
const forwarded = buildForwardedJellyfinAppArgs(args, [
|
||||||
|
...appArgs,
|
||||||
|
`--jellyfin-response-path=${responsePath}`,
|
||||||
|
]);
|
||||||
|
|
||||||
const readLogAppendedSince = (offset: number): string => {
|
const runOnce = (): { status: number; output: string; error: string } => {
|
||||||
const logPath = getMpvLogPath();
|
|
||||||
return readUtf8FileAppendedSince(logPath, offset);
|
|
||||||
};
|
|
||||||
|
|
||||||
const hasCommandSignal = (output: string): boolean => {
|
|
||||||
if (label === 'jellyfin-libraries') {
|
|
||||||
return (
|
|
||||||
output.includes('Jellyfin library:') || output.includes('No Jellyfin libraries found.')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (label === 'jellyfin-items') {
|
|
||||||
return (
|
|
||||||
output.includes('Jellyfin item:') ||
|
|
||||||
output.includes('No Jellyfin items found for the selected library/search.')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (label === 'jellyfin-preview-auth') {
|
|
||||||
return output.includes('Jellyfin preview auth written.');
|
|
||||||
}
|
|
||||||
return output.trim().length > 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
const runOnce = (): { status: number; output: string; error: string; logOffset: number } => {
|
|
||||||
const forwarded = [...forwardedBase];
|
|
||||||
const logPath = getMpvLogPath();
|
|
||||||
let logOffset = 0;
|
|
||||||
try {
|
|
||||||
if (fs.existsSync(logPath)) {
|
|
||||||
logOffset = fs.statSync(logPath).size;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
logOffset = 0;
|
|
||||||
}
|
|
||||||
log('debug', args.logLevel, `${label}: launching app with args: ${forwarded.join(' ')}`);
|
log('debug', args.logLevel, `${label}: launching app with args: ${forwarded.join(' ')}`);
|
||||||
const result = runAppCommandCaptureOutput(appPath, forwarded);
|
const result = runAppCommandCaptureOutput(appPath, forwarded);
|
||||||
log('debug', args.logLevel, `${label}: app command exited with status ${result.status}`);
|
log('debug', args.logLevel, `${label}: app command exited with status ${result.status}`);
|
||||||
let output = `${result.stdout || ''}\n${result.stderr || ''}\n${readLogAppendedSince(logOffset)}`;
|
const output = `${result.stdout || ''}\n${result.stderr || ''}`;
|
||||||
let error = parseJellyfinErrorFromAppOutput(output);
|
return { status: result.status, output, error: parseJellyfinErrorFromAppOutput(output) };
|
||||||
|
|
||||||
return { status: result.status, output, error, logOffset };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let retriedAfterStart = false;
|
try {
|
||||||
let attempt = runOnce();
|
let attempt = runOnce();
|
||||||
if (shouldRetryWithStartForNoRunningInstance(attempt.error)) {
|
if (shouldRetryWithStartForNoRunningInstance(attempt.error)) {
|
||||||
log('debug', args.logLevel, `${label}: starting app detached, then retrying command`);
|
// Start it the way `subminer app` does: the app outlives this picker and the playback, so it
|
||||||
launchAppStartDetached(appPath, args.logLevel);
|
// needs its tray to be visible and quittable.
|
||||||
await sleep(1000);
|
log(
|
||||||
retriedAfterStart = true;
|
'debug',
|
||||||
attempt = runOnce();
|
args.logLevel,
|
||||||
}
|
`${label}: starting app in the background, then retrying command`,
|
||||||
|
|
||||||
if (attempt.status === 0 && !attempt.error && !hasCommandSignal(attempt.output)) {
|
|
||||||
// When app is already running, command handling happens in the primary process and log
|
|
||||||
// lines can land slightly after the helper process exits.
|
|
||||||
const settleWindowMs = (() => {
|
|
||||||
if (label === 'jellyfin-items') {
|
|
||||||
return retriedAfterStart ? 45000 : 30000;
|
|
||||||
}
|
|
||||||
return retriedAfterStart ? 12000 : 4000;
|
|
||||||
})();
|
|
||||||
const settleDeadline = nowMs() + settleWindowMs;
|
|
||||||
const settleOffset = attempt.logOffset;
|
|
||||||
while (nowMs() < settleDeadline) {
|
|
||||||
await sleep(100);
|
|
||||||
const settledOutput = readLogAppendedSince(settleOffset);
|
|
||||||
if (!settledOutput.trim()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
attempt.output = `${attempt.output}\n${settledOutput}`;
|
|
||||||
attempt.error = parseJellyfinErrorFromAppOutput(attempt.output);
|
|
||||||
if (attempt.error || hasCommandSignal(attempt.output)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return attempt;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function requestJellyfinPreviewAuthFromApp(
|
|
||||||
appPath: string,
|
|
||||||
args: Args,
|
|
||||||
): Promise<JellyfinPreviewAuthResponse | null> {
|
|
||||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-jf-preview-auth-'));
|
|
||||||
const responsePath = path.join(tmpDir, 'response.json');
|
|
||||||
try {
|
|
||||||
const attempt = await runAppJellyfinCommand(
|
|
||||||
appPath,
|
|
||||||
args,
|
|
||||||
['--jellyfin-preview-auth', `--jellyfin-response-path=${responsePath}`],
|
|
||||||
'jellyfin-preview-auth',
|
|
||||||
);
|
);
|
||||||
if (attempt.status !== 0 || attempt.error) {
|
launchAppBackgroundDetached(appPath, args.logLevel);
|
||||||
return null;
|
adoptLauncherStartedApp(appPath, args);
|
||||||
|
// A cold start (an AppImage mount, first-run setup) can take a while to claim the instance
|
||||||
|
// lock, so keep retrying until the app takes the command or the request deadline passes.
|
||||||
|
const startDeadline = nowMs() + timeoutMs;
|
||||||
|
do {
|
||||||
|
await sleep(1000);
|
||||||
|
attempt = runOnce();
|
||||||
|
} while (shouldRetryWithStartForNoRunningInstance(attempt.error) && nowMs() < startDeadline);
|
||||||
|
}
|
||||||
|
// A written reply is authoritative; the exit status and log lines only explain a missing one.
|
||||||
|
const earlyReply = readJellyfinAppReply(responsePath);
|
||||||
|
if (earlyReply) return earlyReply;
|
||||||
|
if (attempt.status !== 0) {
|
||||||
|
return { ok: false, error: attempt.error || attempt.output.trim() || `${label} failed.` };
|
||||||
|
}
|
||||||
|
if (attempt.error) {
|
||||||
|
return { ok: false, error: attempt.error };
|
||||||
}
|
}
|
||||||
|
|
||||||
const deadline = nowMs() + 4000;
|
const deadline = nowMs() + timeoutMs;
|
||||||
while (nowMs() < deadline) {
|
while (nowMs() < deadline) {
|
||||||
try {
|
const reply = readJellyfinAppReply(responsePath);
|
||||||
if (fs.existsSync(responsePath)) {
|
if (reply) return reply;
|
||||||
const raw = fs.readFileSync(responsePath, 'utf8');
|
|
||||||
const parsed = parseJellyfinPreviewAuthResponse(raw);
|
|
||||||
if (parsed) {
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// retry until timeout
|
|
||||||
}
|
|
||||||
await sleep(100);
|
await sleep(100);
|
||||||
}
|
}
|
||||||
return null;
|
return { ok: false, error: `Timed out waiting for SubMiner to answer ${label}.` };
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||||
@@ -569,19 +482,57 @@ async function requestJellyfinPreviewAuthFromApp(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function requestJellyfinPreviewAuthFromApp(
|
||||||
|
appPath: string,
|
||||||
|
args: Args,
|
||||||
|
): Promise<JellyfinPreviewAuthPayload | null> {
|
||||||
|
const reply = await requestJellyfinReplyFromApp(
|
||||||
|
appPath,
|
||||||
|
args,
|
||||||
|
['--jellyfin-preview-auth'],
|
||||||
|
'jellyfin-preview-auth',
|
||||||
|
JELLYFIN_PREVIEW_AUTH_TIMEOUT_MS,
|
||||||
|
);
|
||||||
|
if (!reply.ok) {
|
||||||
|
log('debug', args.logLevel, `jellyfin-preview-auth: ${reply.error}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return parseJellyfinPreviewAuthResponse(reply.payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function requestJellyfinListFromApp<T>(
|
||||||
|
appPath: string,
|
||||||
|
args: Args,
|
||||||
|
appArgs: string[],
|
||||||
|
label: string,
|
||||||
|
parse: (payload: Record<string, unknown>) => T[] | null,
|
||||||
|
): Promise<T[]> {
|
||||||
|
const reply = await requestJellyfinReplyFromApp(
|
||||||
|
appPath,
|
||||||
|
args,
|
||||||
|
appArgs,
|
||||||
|
label,
|
||||||
|
JELLYFIN_APP_REPLY_TIMEOUT_MS,
|
||||||
|
);
|
||||||
|
if (!reply.ok) fail(reply.error);
|
||||||
|
const entries = parse(reply.payload);
|
||||||
|
if (!entries) fail(`Unexpected reply from SubMiner for ${label}.`);
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
async function resolveJellyfinSelectionViaApp(
|
async function resolveJellyfinSelectionViaApp(
|
||||||
appPath: string,
|
appPath: string,
|
||||||
args: Args,
|
args: Args,
|
||||||
session: JellyfinSessionConfig,
|
session: JellyfinSessionConfig,
|
||||||
themePath: string | null = null,
|
themePath: string | null = null,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const listLibrariesOutput = await runAppJellyfinListCommand(
|
const libraries = await requestJellyfinListFromApp(
|
||||||
appPath,
|
appPath,
|
||||||
args,
|
args,
|
||||||
['--jellyfin-libraries'],
|
['--jellyfin-libraries'],
|
||||||
'jellyfin-libraries',
|
'jellyfin-libraries',
|
||||||
|
parseJellyfinLibrariesReply,
|
||||||
);
|
);
|
||||||
const libraries = parseJellyfinLibrariesFromAppOutput(listLibrariesOutput);
|
|
||||||
if (libraries.length === 0) {
|
if (libraries.length === 0) {
|
||||||
fail('No Jellyfin libraries found.');
|
fail('No Jellyfin libraries found.');
|
||||||
}
|
}
|
||||||
@@ -655,8 +606,13 @@ async function resolveJellyfinSelectionViaApp(
|
|||||||
if (includeItemTypes) {
|
if (includeItemTypes) {
|
||||||
itemArgs.push(`--jellyfin-include-item-types=${includeItemTypes}`);
|
itemArgs.push(`--jellyfin-include-item-types=${includeItemTypes}`);
|
||||||
}
|
}
|
||||||
const output = await runAppJellyfinListCommand(appPath, args, itemArgs, 'jellyfin-items');
|
return requestJellyfinListFromApp(
|
||||||
return parseJellyfinItemsFromAppOutput(output);
|
appPath,
|
||||||
|
args,
|
||||||
|
itemArgs,
|
||||||
|
'jellyfin-items',
|
||||||
|
parseJellyfinItemsReply,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let rootItems =
|
let rootItems =
|
||||||
@@ -1106,5 +1062,22 @@ export async function runJellyfinPlayMenuWithDeps(
|
|||||||
const forwarded = ['--start', '--jellyfin-play', `--jellyfin-item-id=${itemId}`];
|
const forwarded = ['--start', '--jellyfin-play', `--jellyfin-item-id=${itemId}`];
|
||||||
if (shouldForwardLogLevel(args.logLevel)) forwarded.push('--log-level', args.logLevel);
|
if (shouldForwardLogLevel(args.logLevel)) forwarded.push('--log-level', args.logLevel);
|
||||||
if (args.passwordStore) forwarded.push('--password-store', args.passwordStore);
|
if (args.passwordStore) forwarded.push('--password-store', args.passwordStore);
|
||||||
|
if (!deps.isAppManagedByLauncher()) {
|
||||||
|
// A running app keeps running after playback; a cold `--start --jellyfin-play` makes the app
|
||||||
|
// quit with mpv on its own.
|
||||||
deps.runAppCommandWithInheritLogged(appPath, forwarded, args.logLevel, 'jellyfin-play');
|
deps.runAppCommandWithInheritLogged(appPath, forwarded, args.logLevel, 'jellyfin-play');
|
||||||
|
}
|
||||||
|
// The picker started the app, so this playback owns it, as with local playback: hand over the
|
||||||
|
// item, wait for mpv to close, then exit, which stops the app.
|
||||||
|
const handoff = deps.runAppCommandCaptureOutput(appPath, forwarded);
|
||||||
|
if (handoff.status !== 0) {
|
||||||
|
fail(handoff.error?.message || handoff.stderr.trim() || 'Failed to start Jellyfin playback.');
|
||||||
|
}
|
||||||
|
deps.log(
|
||||||
|
'debug',
|
||||||
|
args.logLevel,
|
||||||
|
'jellyfin-play: waiting for mpv to close before stopping the app',
|
||||||
|
);
|
||||||
|
await deps.waitForUnixSocketClosed(mpvSocketPath);
|
||||||
|
return deps.exitProcess(0);
|
||||||
}
|
}
|
||||||
@@ -1,518 +0,0 @@
|
|||||||
import fs from 'node:fs';
|
|
||||||
import path from 'node:path';
|
|
||||||
import http from 'node:http';
|
|
||||||
import https from 'node:https';
|
|
||||||
import { spawnSync } from 'node:child_process';
|
|
||||||
import type { Args, JimakuLanguagePreference } from './types.js';
|
|
||||||
import { DEFAULT_JIMAKU_API_BASE_URL } from './types.js';
|
|
||||||
import { commandExists } from './util.js';
|
|
||||||
|
|
||||||
export interface JimakuEntry {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
english_name?: string | null;
|
|
||||||
japanese_name?: string | null;
|
|
||||||
flags?: {
|
|
||||||
anime?: boolean;
|
|
||||||
movie?: boolean;
|
|
||||||
adult?: boolean;
|
|
||||||
external?: boolean;
|
|
||||||
unverified?: boolean;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JimakuFileEntry {
|
|
||||||
name: string;
|
|
||||||
url: string;
|
|
||||||
size: number;
|
|
||||||
last_modified: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JimakuApiError {
|
|
||||||
error: string;
|
|
||||||
code?: number;
|
|
||||||
retryAfter?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
type JimakuApiResponse<T> = { ok: true; data: T } | { ok: false; error: JimakuApiError };
|
|
||||||
|
|
||||||
type JimakuDownloadResult = { ok: true; path: string } | { ok: false; error: JimakuApiError };
|
|
||||||
|
|
||||||
interface JimakuConfig {
|
|
||||||
apiKey: string;
|
|
||||||
apiKeyCommand: string;
|
|
||||||
apiBaseUrl: string;
|
|
||||||
languagePreference: JimakuLanguagePreference;
|
|
||||||
maxEntryResults: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JimakuMediaInfo {
|
|
||||||
title: string;
|
|
||||||
season: number | null;
|
|
||||||
episode: number | null;
|
|
||||||
confidence: 'high' | 'medium' | 'low';
|
|
||||||
filename: string;
|
|
||||||
rawTitle: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRetryAfter(headers: http.IncomingHttpHeaders): number | undefined {
|
|
||||||
const value = headers['x-ratelimit-reset-after'];
|
|
||||||
if (!value) return undefined;
|
|
||||||
const raw = Array.isArray(value) ? value[0] : value;
|
|
||||||
if (!raw) return undefined;
|
|
||||||
const parsed = Number.parseFloat(raw);
|
|
||||||
if (!Number.isFinite(parsed)) return undefined;
|
|
||||||
return parsed;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function matchEpisodeFromName(name: string): {
|
|
||||||
season: number | null;
|
|
||||||
episode: number | null;
|
|
||||||
index: number | null;
|
|
||||||
confidence: 'high' | 'medium' | 'low';
|
|
||||||
} {
|
|
||||||
const seasonEpisode = name.match(/S(\d{1,2})E(\d{1,3})/i);
|
|
||||||
if (seasonEpisode && seasonEpisode.index !== undefined) {
|
|
||||||
const seasonText = seasonEpisode[1];
|
|
||||||
const episodeText = seasonEpisode[2];
|
|
||||||
if (!seasonText || !episodeText) {
|
|
||||||
return { season: null, episode: null, index: null, confidence: 'low' };
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
season: Number.parseInt(seasonText, 10),
|
|
||||||
episode: Number.parseInt(episodeText, 10),
|
|
||||||
index: seasonEpisode.index,
|
|
||||||
confidence: 'high',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const alt = name.match(/(\d{1,2})x(\d{1,3})/i);
|
|
||||||
if (alt && alt.index !== undefined) {
|
|
||||||
const seasonText = alt[1];
|
|
||||||
const episodeText = alt[2];
|
|
||||||
if (!seasonText || !episodeText) {
|
|
||||||
return { season: null, episode: null, index: null, confidence: 'low' };
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
season: Number.parseInt(seasonText, 10),
|
|
||||||
episode: Number.parseInt(episodeText, 10),
|
|
||||||
index: alt.index,
|
|
||||||
confidence: 'high',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const epOnly = name.match(/(?:^|[\s._-])E(?:P)?(\d{1,3})(?:\b|[\s._-])/i);
|
|
||||||
if (epOnly && epOnly.index !== undefined) {
|
|
||||||
const episodeText = epOnly[1];
|
|
||||||
if (!episodeText) {
|
|
||||||
return { season: null, episode: null, index: null, confidence: 'low' };
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
season: null,
|
|
||||||
episode: Number.parseInt(episodeText, 10),
|
|
||||||
index: epOnly.index,
|
|
||||||
confidence: 'medium',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const numeric = name.match(/(?:^|[-–—]\s*)(\d{1,3})\s*[-–—]/);
|
|
||||||
if (numeric && numeric.index !== undefined) {
|
|
||||||
const episodeText = numeric[1];
|
|
||||||
if (!episodeText) {
|
|
||||||
return { season: null, episode: null, index: null, confidence: 'low' };
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
season: null,
|
|
||||||
episode: Number.parseInt(episodeText, 10),
|
|
||||||
index: numeric.index,
|
|
||||||
confidence: 'medium',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { season: null, episode: null, index: null, confidence: 'low' };
|
|
||||||
}
|
|
||||||
|
|
||||||
function detectSeasonFromDir(mediaPath: string): number | null {
|
|
||||||
const parent = path.basename(path.dirname(mediaPath));
|
|
||||||
const match = parent.match(/(?:Season|S)\s*(\d{1,2})/i);
|
|
||||||
if (!match) return null;
|
|
||||||
const seasonText = match[1];
|
|
||||||
if (!seasonText) return null;
|
|
||||||
const parsed = Number.parseInt(seasonText, 10);
|
|
||||||
return Number.isFinite(parsed) ? parsed : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseGuessitOutput(mediaPath: string, stdout: string): JimakuMediaInfo | null {
|
|
||||||
const payload = stdout.trim();
|
|
||||||
if (!payload) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(payload) as {
|
|
||||||
title?: string;
|
|
||||||
title_original?: string;
|
|
||||||
series?: string;
|
|
||||||
season?: number | string;
|
|
||||||
episode?: number | string;
|
|
||||||
episode_list?: Array<number | string>;
|
|
||||||
};
|
|
||||||
const season =
|
|
||||||
typeof parsed.season === 'number'
|
|
||||||
? parsed.season
|
|
||||||
: typeof parsed.season === 'string'
|
|
||||||
? Number.parseInt(parsed.season, 10)
|
|
||||||
: null;
|
|
||||||
const directEpisode =
|
|
||||||
typeof parsed.episode === 'number'
|
|
||||||
? parsed.episode
|
|
||||||
: typeof parsed.episode === 'string'
|
|
||||||
? Number.parseInt(parsed.episode, 10)
|
|
||||||
: null;
|
|
||||||
const episodeFromList =
|
|
||||||
parsed.episode_list && parsed.episode_list.length > 0
|
|
||||||
? Number.parseInt(String(parsed.episode_list[0]), 10)
|
|
||||||
: null;
|
|
||||||
const episodeValue =
|
|
||||||
directEpisode !== null && Number.isFinite(directEpisode) ? directEpisode : episodeFromList;
|
|
||||||
const episode = Number.isFinite(episodeValue as number) ? (episodeValue as number) : null;
|
|
||||||
const title = (parsed.title || parsed.title_original || parsed.series || '').trim();
|
|
||||||
const hasStructuredData =
|
|
||||||
title.length > 0 ||
|
|
||||||
Number.isFinite(season as number) ||
|
|
||||||
Number.isFinite(episodeValue as number);
|
|
||||||
|
|
||||||
if (!hasStructuredData) return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
title: title || '',
|
|
||||||
season: Number.isFinite(season as number) ? season : detectSeasonFromDir(mediaPath),
|
|
||||||
episode: episode,
|
|
||||||
confidence: 'high',
|
|
||||||
filename: path.basename(mediaPath),
|
|
||||||
rawTitle: path.basename(mediaPath).replace(/\.[^/.]+$/, ''),
|
|
||||||
};
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseMediaInfoWithGuessit(mediaPath: string): JimakuMediaInfo | null {
|
|
||||||
if (!commandExists('guessit')) return null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const fileName = path.basename(mediaPath);
|
|
||||||
const result = spawnSync('guessit', ['--json', fileName], {
|
|
||||||
cwd: path.dirname(mediaPath),
|
|
||||||
encoding: 'utf8',
|
|
||||||
maxBuffer: 2_000_000,
|
|
||||||
windowsHide: true,
|
|
||||||
});
|
|
||||||
if (result.error || result.status !== 0) return null;
|
|
||||||
return parseGuessitOutput(mediaPath, result.stdout || '');
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanupTitle(value: string): string {
|
|
||||||
return value
|
|
||||||
.replace(/^[\s-–—]+/, '')
|
|
||||||
.replace(/[\s-–—]+$/, '')
|
|
||||||
.replace(/\s+/g, ' ')
|
|
||||||
.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatLangScore(name: string, pref: JimakuLanguagePreference): number {
|
|
||||||
if (pref === 'none') return 0;
|
|
||||||
const upper = name.toUpperCase();
|
|
||||||
const hasJa =
|
|
||||||
/(^|[\W_])JA([\W_]|$)/.test(upper) ||
|
|
||||||
/(^|[\W_])JPN([\W_]|$)/.test(upper) ||
|
|
||||||
upper.includes('.JA.');
|
|
||||||
const hasEn =
|
|
||||||
/(^|[\W_])EN([\W_]|$)/.test(upper) ||
|
|
||||||
/(^|[\W_])ENG([\W_]|$)/.test(upper) ||
|
|
||||||
upper.includes('.EN.');
|
|
||||||
if (pref === 'ja') {
|
|
||||||
if (hasJa) return 2;
|
|
||||||
if (hasEn) return 1;
|
|
||||||
} else if (pref === 'en') {
|
|
||||||
if (hasEn) return 2;
|
|
||||||
if (hasJa) return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function resolveJimakuApiKey(config: JimakuConfig): Promise<string | null> {
|
|
||||||
if (config.apiKey && config.apiKey.trim()) {
|
|
||||||
return config.apiKey.trim();
|
|
||||||
}
|
|
||||||
if (config.apiKeyCommand && config.apiKeyCommand.trim()) {
|
|
||||||
try {
|
|
||||||
const commandResult = spawnSync(config.apiKeyCommand, {
|
|
||||||
shell: true,
|
|
||||||
encoding: 'utf8',
|
|
||||||
timeout: 10000,
|
|
||||||
});
|
|
||||||
if (commandResult.error) return null;
|
|
||||||
const key = (commandResult.stdout || '').trim();
|
|
||||||
return key.length > 0 ? key : null;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function jimakuFetchJson<T>(
|
|
||||||
endpoint: string,
|
|
||||||
query: Record<string, string | number | boolean | null | undefined>,
|
|
||||||
options: { baseUrl: string; apiKey: string },
|
|
||||||
): Promise<JimakuApiResponse<T>> {
|
|
||||||
const url = new URL(endpoint, options.baseUrl);
|
|
||||||
for (const [key, value] of Object.entries(query)) {
|
|
||||||
if (value === null || value === undefined) continue;
|
|
||||||
url.searchParams.set(key, String(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const requestUrl = new URL(url.toString());
|
|
||||||
const transport = requestUrl.protocol === 'https:' ? https : http;
|
|
||||||
const req = transport.request(
|
|
||||||
requestUrl,
|
|
||||||
{
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
Authorization: options.apiKey,
|
|
||||||
'User-Agent': 'SubMiner',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
(res) => {
|
|
||||||
let data = '';
|
|
||||||
res.on('data', (chunk) => {
|
|
||||||
data += chunk.toString();
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
const status = res.statusCode || 0;
|
|
||||||
if (status >= 200 && status < 300) {
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(data) as T;
|
|
||||||
resolve({ ok: true, data: parsed });
|
|
||||||
} catch {
|
|
||||||
resolve({
|
|
||||||
ok: false,
|
|
||||||
error: { error: 'Failed to parse Jimaku response JSON.' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let errorMessage = `Jimaku API error (HTTP ${status})`;
|
|
||||||
try {
|
|
||||||
const parsed = JSON.parse(data) as { error?: string };
|
|
||||||
if (parsed && parsed.error) {
|
|
||||||
errorMessage = parsed.error;
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// ignore parse errors
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve({
|
|
||||||
ok: false,
|
|
||||||
error: {
|
|
||||||
error: errorMessage,
|
|
||||||
code: status || undefined,
|
|
||||||
retryAfter: status === 429 ? getRetryAfter(res.headers) : undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
req.on('error', (error) => {
|
|
||||||
resolve({
|
|
||||||
ok: false,
|
|
||||||
error: { error: `Jimaku request failed: ${(error as Error).message}` },
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
req.end();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseMediaInfo(mediaPath: string | null): JimakuMediaInfo {
|
|
||||||
if (!mediaPath) {
|
|
||||||
return {
|
|
||||||
title: '',
|
|
||||||
season: null,
|
|
||||||
episode: null,
|
|
||||||
confidence: 'low',
|
|
||||||
filename: '',
|
|
||||||
rawTitle: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const guessitInfo = parseMediaInfoWithGuessit(mediaPath);
|
|
||||||
if (guessitInfo) return guessitInfo;
|
|
||||||
|
|
||||||
const filename = path.basename(mediaPath);
|
|
||||||
let name = filename.replace(/\.[^/.]+$/, '');
|
|
||||||
name = name.replace(/\[[^\]]*]/g, ' ');
|
|
||||||
name = name.replace(/\(\d{4}\)/g, ' ');
|
|
||||||
name = name.replace(/[._]/g, ' ');
|
|
||||||
name = name.replace(/[–—]/g, '-');
|
|
||||||
name = name.replace(/\s+/g, ' ').trim();
|
|
||||||
|
|
||||||
const parsed = matchEpisodeFromName(name);
|
|
||||||
let titlePart = name;
|
|
||||||
if (parsed.index !== null) {
|
|
||||||
titlePart = name.slice(0, parsed.index);
|
|
||||||
}
|
|
||||||
|
|
||||||
const seasonFromDir = parsed.season ?? detectSeasonFromDir(mediaPath);
|
|
||||||
const title = cleanupTitle(titlePart || name);
|
|
||||||
|
|
||||||
return {
|
|
||||||
title,
|
|
||||||
season: seasonFromDir,
|
|
||||||
episode: parsed.episode,
|
|
||||||
confidence: parsed.confidence,
|
|
||||||
filename,
|
|
||||||
rawTitle: name,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sortJimakuFiles(
|
|
||||||
files: JimakuFileEntry[],
|
|
||||||
pref: JimakuLanguagePreference,
|
|
||||||
): JimakuFileEntry[] {
|
|
||||||
if (pref === 'none') return files;
|
|
||||||
return [...files].sort((a, b) => {
|
|
||||||
const scoreDiff = formatLangScore(b.name, pref) - formatLangScore(a.name, pref);
|
|
||||||
if (scoreDiff !== 0) return scoreDiff;
|
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function downloadToFile(
|
|
||||||
url: string,
|
|
||||||
destPath: string,
|
|
||||||
headers: Record<string, string>,
|
|
||||||
redirectCount = 0,
|
|
||||||
): Promise<JimakuDownloadResult> {
|
|
||||||
if (redirectCount > 3) {
|
|
||||||
return {
|
|
||||||
ok: false,
|
|
||||||
error: { error: 'Too many redirects while downloading subtitle.' },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
const parsedUrl = new URL(url);
|
|
||||||
const transport = parsedUrl.protocol === 'https:' ? https : http;
|
|
||||||
|
|
||||||
const req = transport.get(parsedUrl, { headers }, (res) => {
|
|
||||||
const status = res.statusCode || 0;
|
|
||||||
if ([301, 302, 303, 307, 308].includes(status) && res.headers.location) {
|
|
||||||
const redirectUrl = new URL(res.headers.location, parsedUrl).toString();
|
|
||||||
res.resume();
|
|
||||||
downloadToFile(redirectUrl, destPath, headers, redirectCount + 1).then(resolve);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (status < 200 || status >= 300) {
|
|
||||||
res.resume();
|
|
||||||
resolve({
|
|
||||||
ok: false,
|
|
||||||
error: {
|
|
||||||
error: `Failed to download subtitle (HTTP ${status}).`,
|
|
||||||
code: status,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileStream = fs.createWriteStream(destPath);
|
|
||||||
res.pipe(fileStream);
|
|
||||||
fileStream.on('finish', () => {
|
|
||||||
fileStream.close(() => {
|
|
||||||
resolve({ ok: true, path: destPath });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
fileStream.on('error', (err: Error) => {
|
|
||||||
resolve({
|
|
||||||
ok: false,
|
|
||||||
error: { error: `Failed to save subtitle: ${err.message}` },
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
req.on('error', (err) => {
|
|
||||||
resolve({
|
|
||||||
ok: false,
|
|
||||||
error: {
|
|
||||||
error: `Download request failed: ${(err as Error).message}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isValidSubtitleCandidateFile(filename: string): boolean {
|
|
||||||
const ext = path.extname(filename).toLowerCase();
|
|
||||||
return ext === '.srt' || ext === '.vtt' || ext === '.ass' || ext === '.ssa' || ext === '.sub';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function mapPreferenceToLanguages(preference: JimakuLanguagePreference): string[] {
|
|
||||||
if (preference === 'en') return ['en', 'eng'];
|
|
||||||
if (preference === 'none') return [];
|
|
||||||
return ['ja', 'jpn'];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizeJimakuSearchInput(mediaPath: string): string {
|
|
||||||
const trimmed = (mediaPath || '').trim();
|
|
||||||
if (!trimmed) return '';
|
|
||||||
if (!/^https?:\/\/.*/.test(trimmed)) return trimmed;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const url = new URL(trimmed);
|
|
||||||
const titleParam =
|
|
||||||
url.searchParams.get('title') || url.searchParams.get('name') || url.searchParams.get('q');
|
|
||||||
if (titleParam && titleParam.trim()) return titleParam.trim();
|
|
||||||
|
|
||||||
const pathParts = url.pathname.split('/').filter(Boolean).reverse();
|
|
||||||
const candidate = pathParts.find((part) => {
|
|
||||||
const decoded = decodeURIComponent(part || '').replace(/\.[^/.]+$/, '');
|
|
||||||
const lowered = decoded.toLowerCase();
|
|
||||||
return lowered.length > 2 && !/^[0-9.]+$/.test(lowered) && !/^[a-f0-9]{16,}$/i.test(lowered);
|
|
||||||
});
|
|
||||||
|
|
||||||
const fallback = candidate || url.hostname.replace(/^www\./, '');
|
|
||||||
return sanitizeJimakuQueryInput(decodeURIComponent(fallback));
|
|
||||||
} catch {
|
|
||||||
return trimmed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sanitizeJimakuQueryInput(value: string): string {
|
|
||||||
return value
|
|
||||||
.replace(/^\s*-\s*/, '')
|
|
||||||
.replace(/[^\w\s\-'".:(),]/g, ' ')
|
|
||||||
.replace(/\s+/g, ' ')
|
|
||||||
.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildJimakuConfig(args: Args): {
|
|
||||||
apiKey: string;
|
|
||||||
apiKeyCommand: string;
|
|
||||||
apiBaseUrl: string;
|
|
||||||
languagePreference: JimakuLanguagePreference;
|
|
||||||
maxEntryResults: number;
|
|
||||||
} {
|
|
||||||
return {
|
|
||||||
apiKey: args.jimakuApiKey,
|
|
||||||
apiKeyCommand: args.jimakuApiKeyCommand,
|
|
||||||
apiBaseUrl: args.jimakuApiBaseUrl || DEFAULT_JIMAKU_API_BASE_URL,
|
|
||||||
languagePreference: args.jimakuLanguagePreference,
|
|
||||||
maxEntryResults: args.jimakuMaxEntryResults || 10,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
+368
-937
File diff suppressed because it is too large.
Load diff
+439
-880
File diff suppressed because it is too large.
Load diff
@@ -1121,6 +1121,21 @@ function clearOverlayManagedByLauncher(): void {
|
|||||||
state.overlayManagedByLauncher = false;
|
state.overlayManagedByLauncher = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For commands that start the app ahead of playback (the Jellyfin picker): the launcher now owns
|
||||||
|
// it, as with local playback, and stops it when the launcher exits for any reason, including a
|
||||||
|
// cancelled picker or Ctrl+C.
|
||||||
|
export function adoptLauncherStartedApp(appPath: string, args: Args): void {
|
||||||
|
if (state.overlayManagedByLauncher) return;
|
||||||
|
markOverlayManagedByLauncher(appPath);
|
||||||
|
process.once('exit', () => stopManagedOverlayApp(args));
|
||||||
|
process.once('SIGINT', () => process.exit(130));
|
||||||
|
process.once('SIGTERM', () => process.exit(143));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAppManagedByLauncher(): boolean {
|
||||||
|
return state.overlayManagedByLauncher;
|
||||||
|
}
|
||||||
|
|
||||||
function isAppAlreadyRunning(appPath: string, logLevel: LogLevel): boolean {
|
function isAppAlreadyRunning(appPath: string, logLevel: LogLevel): boolean {
|
||||||
const result = runSyncAppCommand(appPath, ['--app-ping'], false);
|
const result = runSyncAppCommand(appPath, ['--app-ping'], false);
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
@@ -1723,6 +1738,13 @@ export async function canConnectUnixSocket(socketPath: string): Promise<boolean>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resolves once mpv stops accepting connections on its IPC socket, i.e. the player was closed.
|
||||||
|
export async function waitForUnixSocketClosed(socketPath: string, pollMs = 1000): Promise<void> {
|
||||||
|
while (await canConnectUnixSocket(socketPath)) {
|
||||||
|
await sleep(pollMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function waitForUnixSocketReady(
|
export async function waitForUnixSocketReady(
|
||||||
socketPath: string,
|
socketPath: string,
|
||||||
timeoutMs: number,
|
timeoutMs: number,
|
||||||
|
|||||||
@@ -30,12 +30,6 @@ test('parseArgs captures mpv args string', () => {
|
|||||||
assert.equal(parsed.mpvArgs, '--pause=yes --title="movie night"');
|
assert.equal(parsed.mpvArgs, '--pause=yes --title="movie night"');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parseArgs appends CLI mpv profile to configured mpv profile', () => {
|
|
||||||
const parsed = parseArgs(['--profile', 'hdr'], 'subminer', {}, { profile: 'anime' });
|
|
||||||
|
|
||||||
assert.equal(parsed.profile, 'anime,hdr');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('parseArgs maps root settings window option', () => {
|
test('parseArgs maps root settings window option', () => {
|
||||||
const parsed = parseArgs(['--settings'], 'subminer', {});
|
const parsed = parseArgs(['--settings'], 'subminer', {});
|
||||||
|
|
||||||
@@ -224,14 +218,6 @@ test('parseArgs maps stats cleanup to vocab mode by default', () => {
|
|||||||
assert.equal(parsed.statsCleanupVocab, true);
|
assert.equal(parsed.statsCleanupVocab, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('parseArgs maps explicit stats cleanup vocab flag', () => {
|
|
||||||
const parsed = parseArgs(['stats', 'cleanup', '-v'], 'subminer', {});
|
|
||||||
|
|
||||||
assert.equal(parsed.stats, true);
|
|
||||||
assert.equal(parsed.statsCleanup, true);
|
|
||||||
assert.equal(parsed.statsCleanupVocab, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('parseArgs maps lifetime stats cleanup flag', () => {
|
test('parseArgs maps lifetime stats cleanup flag', () => {
|
||||||
const parsed = parseArgs(['stats', 'cleanup', '--lifetime'], 'subminer', {});
|
const parsed = parseArgs(['stats', 'cleanup', '--lifetime'], 'subminer', {});
|
||||||
|
|
||||||
|
|||||||
+19
-3
@@ -119,11 +119,27 @@ export async function promptOptionalJellyfinSearch(
|
|||||||
themePath: string | null = null,
|
themePath: string | null = null,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
if (useRofi && commandExists('rofi')) {
|
if (useRofi && commandExists('rofi')) {
|
||||||
const rofiArgs = ['-dmenu', '-i', '-p', formatRofiPrompt('Jellyfin Search (optional)')];
|
// Input-only prompt: the shipped theme pins a tall window and has no message widget, so
|
||||||
|
// drop the listview (an empty row there reads as "no results") and show the hint instead.
|
||||||
|
const inputOnlyTheme =
|
||||||
|
'window { height: 0; } mainbox { children: [inputbar, message]; } ' +
|
||||||
|
'message { background-color: transparent; padding: 10px 18px 4px 18px; } ' +
|
||||||
|
'textbox { background-color: transparent; }';
|
||||||
|
const rofiArgs = [
|
||||||
|
'-dmenu',
|
||||||
|
'-i',
|
||||||
|
'-p',
|
||||||
|
formatRofiPrompt('Jellyfin Search (optional)'),
|
||||||
|
'-mesg',
|
||||||
|
'Type to search, or press Enter to browse all',
|
||||||
|
];
|
||||||
if (themePath) {
|
if (themePath) {
|
||||||
rofiArgs.push('-theme', themePath);
|
rofiArgs.push('-theme', themePath, '-theme-str', inputOnlyTheme);
|
||||||
} else {
|
} else {
|
||||||
rofiArgs.push('-theme-str', 'configuration { font: "Noto Sans CJK JP Regular 8";}');
|
rofiArgs.push(
|
||||||
|
'-theme-str',
|
||||||
|
`configuration { font: "Noto Sans CJK JP Regular 8";} ${inputOnlyTheme}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
const result = spawnSync('rofi', rofiArgs, {
|
const result = spawnSync('rofi', rofiArgs, {
|
||||||
input: '\n',
|
input: '\n',
|
||||||
|
|||||||
@@ -8,282 +8,168 @@ import {
|
|||||||
installManagedPluginAssetsViaApp,
|
installManagedPluginAssetsViaApp,
|
||||||
} from './runtime-plugin-preflight';
|
} from './runtime-plugin-preflight';
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable is a no-op on non-Linux platforms', async () => {
|
type EnsureOptions = Parameters<typeof ensureLinuxRuntimePluginAvailable>[0];
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
await ensureLinuxRuntimePluginAvailable({
|
/**
|
||||||
platform: 'darwin',
|
* Linux preflight harness: by default every managed asset resolves, so tests override only
|
||||||
detectInstalledPlugin: () => {
|
* the probes that should report something missing. Counts installs and collects log messages.
|
||||||
calls.push('detect');
|
*/
|
||||||
return false;
|
function makeEnsureHarness(overrides: Partial<EnsureOptions> = {}) {
|
||||||
},
|
const state = { installs: 0, logs: [] as string[] };
|
||||||
resolveRuntimePluginPath: () => {
|
const options: EnsureOptions = {
|
||||||
calls.push('resolve');
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
installManagedPluginAssets: async () => {
|
|
||||||
calls.push('install');
|
|
||||||
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
|
||||||
},
|
|
||||||
log: () => {
|
|
||||||
calls.push('log');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(calls, []);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable skips install when plugin, theme, and thumbnailer exist', async () => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
await ensureLinuxRuntimePluginAvailable({
|
|
||||||
platform: 'linux',
|
|
||||||
detectInstalledPlugin: () => {
|
|
||||||
calls.push('detect');
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
resolveRuntimePluginPath: () => {
|
|
||||||
calls.push('resolve');
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
installManagedPluginAssets: async () => {
|
|
||||||
calls.push('install');
|
|
||||||
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
|
||||||
},
|
|
||||||
isManagedThemeAvailable: () => {
|
|
||||||
calls.push('theme');
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
isManagedThumbnailerAvailable: () => {
|
|
||||||
calls.push('thumbnailer');
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
log: () => {},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(calls, ['detect', 'theme', 'thumbnailer']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable skips install when all managed assets resolve', async () => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
|
|
||||||
await ensureLinuxRuntimePluginAvailable({
|
|
||||||
platform: 'linux',
|
|
||||||
xdgDataHome: '/tmp/xdg-data',
|
|
||||||
detectInstalledPlugin: () => {
|
|
||||||
calls.push('detect');
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
resolveRuntimePluginPath: () => {
|
|
||||||
calls.push('resolve');
|
|
||||||
return '/tmp/plugin/main.lua';
|
|
||||||
},
|
|
||||||
installManagedPluginAssets: async () => {
|
|
||||||
calls.push('install');
|
|
||||||
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
|
||||||
},
|
|
||||||
isManagedThemeAvailable: () => {
|
|
||||||
calls.push('theme');
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
isManagedThumbnailerAvailable: () => {
|
|
||||||
calls.push('thumbnailer');
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
log: () => {},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(calls, ['detect', 'resolve', 'theme', 'thumbnailer']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable installs managed assets when rofi theme is missing', async () => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
let themeAvailable = false;
|
|
||||||
|
|
||||||
await ensureLinuxRuntimePluginAvailable({
|
|
||||||
platform: 'linux',
|
|
||||||
xdgDataHome: '/tmp/xdg-data',
|
|
||||||
detectInstalledPlugin: () => {
|
|
||||||
calls.push('detect');
|
|
||||||
return false;
|
|
||||||
},
|
|
||||||
resolveRuntimePluginPath: () => {
|
|
||||||
calls.push('resolve');
|
|
||||||
return '/tmp/plugin/main.lua';
|
|
||||||
},
|
|
||||||
isManagedThemeAvailable: () => {
|
|
||||||
calls.push('theme');
|
|
||||||
return themeAvailable;
|
|
||||||
},
|
|
||||||
isManagedThumbnailerAvailable: () => {
|
|
||||||
calls.push('thumbnailer');
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
installManagedPluginAssets: async () => {
|
|
||||||
calls.push('install');
|
|
||||||
themeAvailable = true;
|
|
||||||
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
|
||||||
},
|
|
||||||
log: (level, _configured, message) => {
|
|
||||||
calls.push(`${level}:${message}`);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(calls, [
|
|
||||||
'detect',
|
|
||||||
'resolve',
|
|
||||||
'theme',
|
|
||||||
'info:Linux runtime support assets missing; installing managed plugin/theme/thumbnailer assets.',
|
|
||||||
'install',
|
|
||||||
'info:Managed Linux runtime support assets installed: plugin=/tmp/plugin/main.lua theme=/tmp/xdg-data/SubMiner/themes/subminer.rasi thumbnailer=/tmp/xdg-data/SubMiner/thumbnailers/subminer-ffmpegthumbnailer.thumbnailer',
|
|
||||||
'resolve',
|
|
||||||
'theme',
|
|
||||||
'thumbnailer',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable installs managed assets when thumbnailer is missing', async () => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
let thumbnailerAvailable = false;
|
|
||||||
|
|
||||||
await ensureLinuxRuntimePluginAvailable({
|
|
||||||
platform: 'linux',
|
|
||||||
xdgDataHome: '/tmp/xdg-data',
|
|
||||||
detectInstalledPlugin: () => true,
|
|
||||||
resolveRuntimePluginPath: () => '/tmp/plugin/main.lua',
|
|
||||||
isManagedThemeAvailable: () => true,
|
|
||||||
isManagedThumbnailerAvailable: () => thumbnailerAvailable,
|
|
||||||
installManagedPluginAssets: async () => {
|
|
||||||
calls.push('install');
|
|
||||||
thumbnailerAvailable = true;
|
|
||||||
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
|
||||||
},
|
|
||||||
log: (_level, _configured, message) => {
|
|
||||||
calls.push(message);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(calls, [
|
|
||||||
'Linux runtime support assets missing; installing managed plugin/theme/thumbnailer assets.',
|
|
||||||
'install',
|
|
||||||
'Managed Linux runtime support assets installed: plugin=/tmp/plugin/main.lua theme=/tmp/xdg-data/SubMiner/themes/subminer.rasi thumbnailer=/tmp/xdg-data/SubMiner/thumbnailers/subminer-ffmpegthumbnailer.thumbnailer',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable retains an installed plugin after installing support assets', async () => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
let thumbnailerAvailable = false;
|
|
||||||
|
|
||||||
await ensureLinuxRuntimePluginAvailable({
|
|
||||||
platform: 'linux',
|
|
||||||
xdgDataHome: '/tmp/xdg-data',
|
|
||||||
detectInstalledPlugin: () => true,
|
|
||||||
resolveRuntimePluginPath: () => {
|
|
||||||
calls.push('resolve');
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
isManagedThemeAvailable: () => true,
|
|
||||||
isManagedThumbnailerAvailable: () => thumbnailerAvailable,
|
|
||||||
installManagedPluginAssets: async () => {
|
|
||||||
calls.push('install');
|
|
||||||
thumbnailerAvailable = true;
|
|
||||||
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
|
||||||
},
|
|
||||||
log: () => {},
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.deepEqual(calls, ['install']);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable installs managed assets and re-resolves plugin path', async () => {
|
|
||||||
const calls: string[] = [];
|
|
||||||
let resolveCount = 0;
|
|
||||||
|
|
||||||
await ensureLinuxRuntimePluginAvailable({
|
|
||||||
platform: 'linux',
|
platform: 'linux',
|
||||||
xdgDataHome: '/tmp/xdg-data',
|
xdgDataHome: '/tmp/xdg-data',
|
||||||
detectInstalledPlugin: () => false,
|
detectInstalledPlugin: () => false,
|
||||||
resolveRuntimePluginPath: () => {
|
resolveRuntimePluginPath: () => '/tmp/plugin/main.lua',
|
||||||
resolveCount += 1;
|
|
||||||
calls.push(`resolve:${resolveCount}`);
|
|
||||||
return resolveCount === 1 ? null : '/tmp/plugin/main.lua';
|
|
||||||
},
|
|
||||||
isManagedThemeAvailable: () => true,
|
isManagedThemeAvailable: () => true,
|
||||||
isManagedThumbnailerAvailable: () => true,
|
isManagedThumbnailerAvailable: () => true,
|
||||||
installManagedPluginAssets: async () => {
|
installManagedPluginAssets: async () => {
|
||||||
calls.push('install');
|
state.installs += 1;
|
||||||
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
||||||
},
|
},
|
||||||
log: (level, _configured, message) => {
|
log: (_level, _configured, message) => {
|
||||||
calls.push(`${level}:${message}`);
|
state.logs.push(message);
|
||||||
|
},
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
return { state, run: () => ensureLinuxRuntimePluginAvailable(options) };
|
||||||
|
}
|
||||||
|
|
||||||
|
test('ensureLinuxRuntimePluginAvailable is a no-op on non-Linux platforms', async () => {
|
||||||
|
const unexpected = () => {
|
||||||
|
throw new Error('probed on a non-Linux platform');
|
||||||
|
};
|
||||||
|
const harness = makeEnsureHarness({
|
||||||
|
platform: 'darwin',
|
||||||
|
detectInstalledPlugin: unexpected,
|
||||||
|
resolveRuntimePluginPath: unexpected,
|
||||||
|
isManagedThemeAvailable: unexpected,
|
||||||
|
isManagedThumbnailerAvailable: unexpected,
|
||||||
|
});
|
||||||
|
|
||||||
|
await harness.run();
|
||||||
|
|
||||||
|
assert.equal(harness.state.installs, 0);
|
||||||
|
assert.deepEqual(harness.state.logs, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
const skipInstallCases: Array<{ name: string; overrides: Partial<EnsureOptions> }> = [
|
||||||
|
{
|
||||||
|
name: 'plugin, theme, and thumbnailer exist',
|
||||||
|
overrides: { detectInstalledPlugin: () => true, resolveRuntimePluginPath: () => null },
|
||||||
|
},
|
||||||
|
{ name: 'all managed assets resolve', overrides: {} },
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const c of skipInstallCases) {
|
||||||
|
test(`ensureLinuxRuntimePluginAvailable skips install when ${c.name}`, async () => {
|
||||||
|
const harness = makeEnsureHarness(c.overrides);
|
||||||
|
|
||||||
|
await harness.run();
|
||||||
|
|
||||||
|
assert.equal(harness.state.installs, 0);
|
||||||
|
assert.deepEqual(harness.state.logs, []);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const installWhenMissingCases: Array<{ name: string; missing: 'theme' | 'thumbnailer' }> = [
|
||||||
|
{ name: 'rofi theme is missing', missing: 'theme' },
|
||||||
|
{ name: 'thumbnailer is missing', missing: 'thumbnailer' },
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const c of installWhenMissingCases) {
|
||||||
|
test(`ensureLinuxRuntimePluginAvailable installs managed assets when ${c.name}`, async () => {
|
||||||
|
let available = false;
|
||||||
|
const probe = {
|
||||||
|
[c.missing === 'theme' ? 'isManagedThemeAvailable' : 'isManagedThumbnailerAvailable']: () =>
|
||||||
|
available,
|
||||||
|
};
|
||||||
|
const harness = makeEnsureHarness({
|
||||||
|
...probe,
|
||||||
|
installManagedPluginAssets: async () => {
|
||||||
|
harness.state.installs += 1;
|
||||||
|
available = true;
|
||||||
|
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(calls, [
|
await harness.run();
|
||||||
'resolve:1',
|
|
||||||
'info:Linux runtime support assets missing; installing managed plugin/theme/thumbnailer assets.',
|
assert.equal(harness.state.installs, 1);
|
||||||
'install',
|
assert.equal(harness.state.logs.length, 2);
|
||||||
'info:Managed Linux runtime support assets installed: plugin=/tmp/plugin/main.lua theme=/tmp/xdg-data/SubMiner/themes/subminer.rasi thumbnailer=/tmp/xdg-data/SubMiner/thumbnailers/subminer-ffmpegthumbnailer.thumbnailer',
|
assert.match(harness.state.logs[0]!, /support assets missing; installing/);
|
||||||
'resolve:2',
|
assert.match(
|
||||||
]);
|
harness.state.logs[1]!,
|
||||||
|
/installed: plugin=\/tmp\/plugin\/main\.lua theme=.*subminer\.rasi thumbnailer=.*\.thumbnailer/,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test('ensureLinuxRuntimePluginAvailable retains an installed plugin after installing support assets', async () => {
|
||||||
|
let thumbnailerAvailable = false;
|
||||||
|
const harness = makeEnsureHarness({
|
||||||
|
detectInstalledPlugin: () => true,
|
||||||
|
// An installed plugin means the bundled path is never needed, even after the install.
|
||||||
|
resolveRuntimePluginPath: () => null,
|
||||||
|
isManagedThumbnailerAvailable: () => thumbnailerAvailable,
|
||||||
|
installManagedPluginAssets: async () => {
|
||||||
|
harness.state.installs += 1;
|
||||||
|
thumbnailerAvailable = true;
|
||||||
|
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await harness.run();
|
||||||
|
|
||||||
|
assert.equal(harness.state.installs, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable fails when install result is not ok', async () => {
|
test('ensureLinuxRuntimePluginAvailable installs managed assets and re-resolves plugin path', async () => {
|
||||||
await assert.rejects(
|
let installed = false;
|
||||||
() =>
|
const harness = makeEnsureHarness({
|
||||||
ensureLinuxRuntimePluginAvailable({
|
resolveRuntimePluginPath: () => (installed ? '/tmp/plugin/main.lua' : null),
|
||||||
platform: 'linux',
|
installManagedPluginAssets: async () => {
|
||||||
detectInstalledPlugin: () => false,
|
harness.state.installs += 1;
|
||||||
|
installed = true;
|
||||||
|
return { ok: true, status: 'installed', path: '/tmp/plugin/main.lua' };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await harness.run();
|
||||||
|
|
||||||
|
assert.equal(harness.state.installs, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
const failureCases: Array<{ name: string; overrides: Partial<EnsureOptions>; error: RegExp }> = [
|
||||||
|
{
|
||||||
|
name: 'install result is not ok',
|
||||||
|
overrides: {
|
||||||
resolveRuntimePluginPath: () => null,
|
resolveRuntimePluginPath: () => null,
|
||||||
installManagedPluginAssets: async () => ({
|
installManagedPluginAssets: async () => ({
|
||||||
ok: false,
|
ok: false,
|
||||||
status: 'failed',
|
status: 'failed',
|
||||||
error: 'copy failed',
|
error: 'copy failed',
|
||||||
}),
|
}),
|
||||||
log: () => {},
|
},
|
||||||
}),
|
error: /copy failed/,
|
||||||
/copy failed/,
|
},
|
||||||
);
|
{
|
||||||
});
|
name: 'runtime path remains unresolved after install',
|
||||||
|
overrides: { resolveRuntimePluginPath: () => null },
|
||||||
|
error: /managed runtime plugin assets could not be installed/i,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'thumbnailer remains missing after install',
|
||||||
|
overrides: { detectInstalledPlugin: () => true, isManagedThumbnailerAvailable: () => false },
|
||||||
|
error: /thumbnailer=.*subminer-ffmpegthumbnailer\.thumbnailer/i,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable fails when runtime path remains unresolved after install', async () => {
|
for (const c of failureCases) {
|
||||||
await assert.rejects(
|
test(`ensureLinuxRuntimePluginAvailable fails when ${c.name}`, async () => {
|
||||||
() =>
|
await assert.rejects(() => makeEnsureHarness(c.overrides).run(), c.error);
|
||||||
ensureLinuxRuntimePluginAvailable({
|
});
|
||||||
platform: 'linux',
|
}
|
||||||
detectInstalledPlugin: () => false,
|
|
||||||
resolveRuntimePluginPath: () => null,
|
|
||||||
installManagedPluginAssets: async () => ({
|
|
||||||
ok: true,
|
|
||||||
status: 'installed',
|
|
||||||
path: '/tmp/plugin/main.lua',
|
|
||||||
}),
|
|
||||||
log: () => {},
|
|
||||||
}),
|
|
||||||
/managed runtime plugin assets could not be installed/i,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable fails when thumbnailer remains missing after install', async () => {
|
|
||||||
await assert.rejects(
|
|
||||||
() =>
|
|
||||||
ensureLinuxRuntimePluginAvailable({
|
|
||||||
platform: 'linux',
|
|
||||||
xdgDataHome: '/tmp/xdg-data',
|
|
||||||
detectInstalledPlugin: () => true,
|
|
||||||
resolveRuntimePluginPath: () => '/tmp/plugin/main.lua',
|
|
||||||
isManagedThemeAvailable: () => true,
|
|
||||||
isManagedThumbnailerAvailable: () => false,
|
|
||||||
installManagedPluginAssets: async () => ({
|
|
||||||
ok: true,
|
|
||||||
status: 'installed',
|
|
||||||
path: '/tmp/plugin/main.lua',
|
|
||||||
}),
|
|
||||||
log: () => {},
|
|
||||||
}),
|
|
||||||
/thumbnailer=.*subminer-ffmpegthumbnailer\.thumbnailer/i,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('ensureLinuxRuntimePluginAvailable rejects a thumbnailer directory before and after install', async () => {
|
test('ensureLinuxRuntimePluginAvailable rejects a thumbnailer directory before and after install', async () => {
|
||||||
const xdgDataHome = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-thumbnailer-directory-'));
|
const xdgDataHome = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-thumbnailer-directory-'));
|
||||||
|
|||||||
+95
-201
@@ -3,104 +3,90 @@ import assert from 'node:assert/strict';
|
|||||||
import { ensureLauncherSetupReady, waitForSetupCompletion } from './setup-gate';
|
import { ensureLauncherSetupReady, waitForSetupCompletion } from './setup-gate';
|
||||||
import type { SetupState } from '../src/shared/setup-state';
|
import type { SetupState } from '../src/shared/setup-state';
|
||||||
|
|
||||||
const commandLineSetupDefaults = {
|
/** An in-progress setup state; tests override only the fields that matter. */
|
||||||
|
function makeState(overrides: Partial<SetupState> = {}): SetupState {
|
||||||
|
return {
|
||||||
|
version: 4,
|
||||||
|
status: 'in_progress',
|
||||||
|
completedAt: null,
|
||||||
|
completionSource: null,
|
||||||
|
yomitanSetupMode: null,
|
||||||
|
lastSeenYomitanDictionaryCount: 0,
|
||||||
|
pluginInstallStatus: 'unknown',
|
||||||
|
pluginInstallPathSummary: null,
|
||||||
|
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
||||||
|
windowsMpvShortcutLastStatus: 'unknown',
|
||||||
bunInstallStatus: 'unknown',
|
bunInstallStatus: 'unknown',
|
||||||
launcherInstallStatus: 'unknown',
|
launcherInstallStatus: 'unknown',
|
||||||
launcherInstallPath: null,
|
launcherInstallPath: null,
|
||||||
} satisfies Pick<SetupState, 'bunInstallStatus' | 'launcherInstallStatus' | 'launcherInstallPath'>;
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
test('waitForSetupCompletion resolves completed and cancelled states', async () => {
|
function completedState(overrides: Partial<SetupState> = {}): SetupState {
|
||||||
const sequence: Array<SetupState | null> = [
|
return makeState({
|
||||||
null,
|
|
||||||
{
|
|
||||||
version: 4,
|
|
||||||
status: 'in_progress',
|
|
||||||
completedAt: null,
|
|
||||||
completionSource: null,
|
|
||||||
yomitanSetupMode: null,
|
|
||||||
lastSeenYomitanDictionaryCount: 0,
|
|
||||||
pluginInstallStatus: 'unknown',
|
|
||||||
pluginInstallPathSummary: null,
|
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
version: 4,
|
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
completedAt: '2026-03-07T00:00:00.000Z',
|
completedAt: '2026-03-07T00:00:00.000Z',
|
||||||
completionSource: 'user',
|
completionSource: 'user',
|
||||||
yomitanSetupMode: 'internal',
|
yomitanSetupMode: 'internal',
|
||||||
lastSeenYomitanDictionaryCount: 1,
|
lastSeenYomitanDictionaryCount: 1,
|
||||||
pluginInstallStatus: 'skipped',
|
...overrides,
|
||||||
pluginInstallPathSummary: null,
|
});
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
}
|
||||||
windowsMpvShortcutLastStatus: 'skipped',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const result = await waitForSetupCompletion({
|
const cancelledState = () => makeState({ status: 'cancelled' });
|
||||||
readSetupState: () => sequence.shift() ?? null,
|
|
||||||
sleep: async () => undefined,
|
/** Deterministic clock: every `now()` advances 100ms and `sleep` returns immediately. */
|
||||||
now: (() => {
|
function fakeClock() {
|
||||||
let value = 0;
|
let value = 0;
|
||||||
return () => (value += 100);
|
return {
|
||||||
})(),
|
sleep: async () => undefined,
|
||||||
|
now: () => (value += 100),
|
||||||
timeoutMs: 5_000,
|
timeoutMs: 5_000,
|
||||||
pollIntervalMs: 100,
|
pollIntervalMs: 100,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reader that serves `states` in order, then repeats the last one; counts its reads. */
|
||||||
|
function sequenceReader(states: Array<SetupState | null>) {
|
||||||
|
const reader = {
|
||||||
|
reads: 0,
|
||||||
|
read: (): SetupState | null => states[Math.min(reader.reads++, states.length - 1)] ?? null,
|
||||||
|
};
|
||||||
|
return reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const c of [
|
||||||
|
{ name: 'completed', last: completedState(), expected: 'completed' },
|
||||||
|
{ name: 'cancelled', last: cancelledState(), expected: 'cancelled' },
|
||||||
|
] as const) {
|
||||||
|
test(`waitForSetupCompletion resolves ${c.name} state after polling through earlier states`, async () => {
|
||||||
|
const reader = sequenceReader([null, makeState(), c.last]);
|
||||||
|
|
||||||
|
const result = await waitForSetupCompletion({
|
||||||
|
readSetupState: reader.read,
|
||||||
|
...fakeClock(),
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(result, 'completed');
|
assert.equal(result, c.expected);
|
||||||
});
|
assert.equal(reader.reads, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test('ensureLauncherSetupReady launches setup app and resumes only after completion', async () => {
|
test('ensureLauncherSetupReady launches setup app and resumes only after completion', async () => {
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
let reads = 0;
|
const reader = sequenceReader([
|
||||||
|
null,
|
||||||
|
makeState(),
|
||||||
|
completedState({ pluginInstallStatus: 'installed', pluginInstallPathSummary: '/tmp/mpv' }),
|
||||||
|
]);
|
||||||
|
|
||||||
const ready = await ensureLauncherSetupReady({
|
const ready = await ensureLauncherSetupReady({
|
||||||
readSetupState: () => {
|
readSetupState: reader.read,
|
||||||
reads += 1;
|
|
||||||
if (reads === 1) return null;
|
|
||||||
if (reads === 2) {
|
|
||||||
return {
|
|
||||||
version: 4,
|
|
||||||
status: 'in_progress',
|
|
||||||
completedAt: null,
|
|
||||||
completionSource: null,
|
|
||||||
yomitanSetupMode: null,
|
|
||||||
lastSeenYomitanDictionaryCount: 0,
|
|
||||||
pluginInstallStatus: 'unknown',
|
|
||||||
pluginInstallPathSummary: null,
|
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
version: 4,
|
|
||||||
status: 'completed',
|
|
||||||
completedAt: '2026-03-07T00:00:00.000Z',
|
|
||||||
completionSource: 'user',
|
|
||||||
yomitanSetupMode: 'internal',
|
|
||||||
lastSeenYomitanDictionaryCount: 1,
|
|
||||||
pluginInstallStatus: 'installed',
|
|
||||||
pluginInstallPathSummary: '/tmp/mpv',
|
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'installed',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
launchSetupApp: () => {
|
launchSetupApp: () => {
|
||||||
calls.push('launch');
|
calls.push('launch');
|
||||||
},
|
},
|
||||||
sleep: async () => undefined,
|
...fakeClock(),
|
||||||
now: (() => {
|
|
||||||
let value = 0;
|
|
||||||
return () => (value += 100);
|
|
||||||
})(),
|
|
||||||
timeoutMs: 5_000,
|
|
||||||
pollIntervalMs: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(ready, true);
|
assert.equal(ready, true);
|
||||||
@@ -116,10 +102,7 @@ test('ensureLauncherSetupReady bypasses setup gate when external yomitan is conf
|
|||||||
launchSetupApp: () => {
|
launchSetupApp: () => {
|
||||||
calls.push('launch');
|
calls.push('launch');
|
||||||
},
|
},
|
||||||
sleep: async () => undefined,
|
...fakeClock(),
|
||||||
now: () => 0,
|
|
||||||
timeoutMs: 5_000,
|
|
||||||
pollIntervalMs: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(ready, true);
|
assert.equal(ready, true);
|
||||||
@@ -129,76 +112,47 @@ test('ensureLauncherSetupReady bypasses setup gate when external yomitan is conf
|
|||||||
test('ensureLauncherSetupReady waits for finish after legacy mpv plugin removal', async () => {
|
test('ensureLauncherSetupReady waits for finish after legacy mpv plugin removal', async () => {
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
let legacyPluginInstalled = true;
|
let legacyPluginInstalled = true;
|
||||||
let reads = 0;
|
// The completion timestamp moves forward once the setup app has finished.
|
||||||
|
const reader = sequenceReader([
|
||||||
const ready = await ensureLauncherSetupReady({
|
completedState({ yomitanSetupMode: null, lastSeenYomitanDictionaryCount: 0 }),
|
||||||
readSetupState: () => {
|
completedState({ yomitanSetupMode: null, lastSeenYomitanDictionaryCount: 0 }),
|
||||||
reads += 1;
|
completedState({
|
||||||
return {
|
completedAt: '2026-05-12T14:40:00.000Z',
|
||||||
version: 4,
|
|
||||||
status: 'completed',
|
|
||||||
completedAt: reads < 3 ? '2026-03-07T00:00:00.000Z' : '2026-05-12T14:40:00.000Z',
|
|
||||||
completionSource: 'user',
|
|
||||||
yomitanSetupMode: null,
|
yomitanSetupMode: null,
|
||||||
lastSeenYomitanDictionaryCount: 0,
|
lastSeenYomitanDictionaryCount: 0,
|
||||||
pluginInstallStatus: 'unknown',
|
}),
|
||||||
pluginInstallPathSummary: null,
|
]);
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
const ready = await ensureLauncherSetupReady({
|
||||||
...commandLineSetupDefaults,
|
readSetupState: reader.read,
|
||||||
};
|
|
||||||
},
|
|
||||||
hasLegacyMpvPlugin: () => legacyPluginInstalled,
|
hasLegacyMpvPlugin: () => legacyPluginInstalled,
|
||||||
launchSetupApp: () => {
|
launchSetupApp: () => {
|
||||||
calls.push('launch');
|
calls.push('launch');
|
||||||
legacyPluginInstalled = false;
|
legacyPluginInstalled = false;
|
||||||
},
|
},
|
||||||
sleep: async () => undefined,
|
...fakeClock(),
|
||||||
now: (() => {
|
|
||||||
let value = 0;
|
|
||||||
return () => (value += 100);
|
|
||||||
})(),
|
|
||||||
timeoutMs: 5_000,
|
|
||||||
pollIntervalMs: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(ready, true);
|
assert.equal(ready, true);
|
||||||
assert.deepEqual(calls, ['launch']);
|
assert.deepEqual(calls, ['launch']);
|
||||||
assert.equal(reads >= 3, true);
|
assert.equal(reader.reads >= 3, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ensureLauncherSetupReady lets users continue without removing a legacy mpv plugin', async () => {
|
test('ensureLauncherSetupReady lets users continue without removing a legacy mpv plugin', async () => {
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
let reads = 0;
|
const reader = sequenceReader([
|
||||||
|
completedState({ lastSeenYomitanDictionaryCount: 2 }),
|
||||||
|
completedState({ lastSeenYomitanDictionaryCount: 2 }),
|
||||||
|
completedState({ completedAt: '2026-05-12T14:30:00.000Z', lastSeenYomitanDictionaryCount: 2 }),
|
||||||
|
]);
|
||||||
|
|
||||||
const ready = await ensureLauncherSetupReady({
|
const ready = await ensureLauncherSetupReady({
|
||||||
readSetupState: () => {
|
readSetupState: reader.read,
|
||||||
reads += 1;
|
|
||||||
return {
|
|
||||||
version: 4,
|
|
||||||
status: 'completed',
|
|
||||||
completedAt: reads < 3 ? '2026-03-07T00:00:00.000Z' : '2026-05-12T14:30:00.000Z',
|
|
||||||
completionSource: 'user',
|
|
||||||
yomitanSetupMode: 'internal',
|
|
||||||
lastSeenYomitanDictionaryCount: 2,
|
|
||||||
pluginInstallStatus: 'unknown',
|
|
||||||
pluginInstallPathSummary: null,
|
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
hasLegacyMpvPlugin: () => true,
|
hasLegacyMpvPlugin: () => true,
|
||||||
launchSetupApp: () => {
|
launchSetupApp: () => {
|
||||||
calls.push('launch');
|
calls.push('launch');
|
||||||
},
|
},
|
||||||
sleep: async () => undefined,
|
...fakeClock(),
|
||||||
now: (() => {
|
|
||||||
let value = 0;
|
|
||||||
return () => (value += 100);
|
|
||||||
})(),
|
|
||||||
timeoutMs: 5_000,
|
|
||||||
pollIntervalMs: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(ready, true);
|
assert.equal(ready, true);
|
||||||
@@ -207,90 +161,30 @@ test('ensureLauncherSetupReady lets users continue without removing a legacy mpv
|
|||||||
|
|
||||||
test('ensureLauncherSetupReady fails on timeout/cancelled state', async () => {
|
test('ensureLauncherSetupReady fails on timeout/cancelled state', async () => {
|
||||||
const result = await ensureLauncherSetupReady({
|
const result = await ensureLauncherSetupReady({
|
||||||
readSetupState: () => ({
|
readSetupState: cancelledState,
|
||||||
version: 4,
|
|
||||||
status: 'cancelled',
|
|
||||||
completedAt: null,
|
|
||||||
completionSource: null,
|
|
||||||
yomitanSetupMode: null,
|
|
||||||
lastSeenYomitanDictionaryCount: 0,
|
|
||||||
pluginInstallStatus: 'unknown',
|
|
||||||
pluginInstallPathSummary: null,
|
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
}),
|
|
||||||
launchSetupApp: () => undefined,
|
launchSetupApp: () => undefined,
|
||||||
sleep: async () => undefined,
|
...fakeClock(),
|
||||||
now: (() => {
|
|
||||||
let value = 0;
|
|
||||||
return () => (value += 100);
|
|
||||||
})(),
|
|
||||||
timeoutMs: 5_000,
|
|
||||||
pollIntervalMs: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(result, false);
|
assert.equal(result, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('ensureLauncherSetupReady ignores stale cancelled state after launching setup app', async () => {
|
test('ensureLauncherSetupReady ignores stale cancelled state after launching setup app', async () => {
|
||||||
let reads = 0;
|
const reader = sequenceReader([
|
||||||
|
cancelledState(),
|
||||||
const result = await ensureLauncherSetupReady({
|
cancelledState(),
|
||||||
readSetupState: () => {
|
makeState(),
|
||||||
reads += 1;
|
completedState({
|
||||||
if (reads <= 2) {
|
|
||||||
return {
|
|
||||||
version: 4,
|
|
||||||
status: 'cancelled',
|
|
||||||
completedAt: null,
|
|
||||||
completionSource: null,
|
|
||||||
yomitanSetupMode: null,
|
|
||||||
lastSeenYomitanDictionaryCount: 0,
|
|
||||||
pluginInstallStatus: 'unknown',
|
|
||||||
pluginInstallPathSummary: null,
|
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (reads === 3) {
|
|
||||||
return {
|
|
||||||
version: 4,
|
|
||||||
status: 'in_progress',
|
|
||||||
completedAt: null,
|
|
||||||
completionSource: null,
|
|
||||||
yomitanSetupMode: null,
|
|
||||||
lastSeenYomitanDictionaryCount: 0,
|
|
||||||
pluginInstallStatus: 'unknown',
|
|
||||||
pluginInstallPathSummary: null,
|
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
|
||||||
...commandLineSetupDefaults,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
version: 4,
|
|
||||||
status: 'completed',
|
|
||||||
completedAt: '2026-03-07T00:00:00.000Z',
|
|
||||||
completionSource: 'legacy_auto_detected',
|
completionSource: 'legacy_auto_detected',
|
||||||
yomitanSetupMode: 'internal',
|
|
||||||
lastSeenYomitanDictionaryCount: 1,
|
|
||||||
pluginInstallStatus: 'installed',
|
pluginInstallStatus: 'installed',
|
||||||
pluginInstallPathSummary: '/tmp/mpv',
|
pluginInstallPathSummary: '/tmp/mpv',
|
||||||
windowsMpvShortcutPreferences: { startMenuEnabled: true, desktopEnabled: true },
|
}),
|
||||||
windowsMpvShortcutLastStatus: 'unknown',
|
]);
|
||||||
...commandLineSetupDefaults,
|
|
||||||
};
|
const result = await ensureLauncherSetupReady({
|
||||||
},
|
readSetupState: reader.read,
|
||||||
launchSetupApp: () => undefined,
|
launchSetupApp: () => undefined,
|
||||||
sleep: async () => undefined,
|
...fakeClock(),
|
||||||
now: (() => {
|
|
||||||
let value = 0;
|
|
||||||
return () => (value += 100);
|
|
||||||
})(),
|
|
||||||
timeoutMs: 5_000,
|
|
||||||
pollIntervalMs: 100,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(result, true);
|
assert.equal(result, true);
|
||||||
|
|||||||
+32
-49
@@ -9,7 +9,6 @@ import {
|
|||||||
createDefaultSetupState,
|
createDefaultSetupState,
|
||||||
getDefaultConfigDir,
|
getDefaultConfigDir,
|
||||||
getSetupStatePath,
|
getSetupStatePath,
|
||||||
readSetupState,
|
|
||||||
writeSetupState,
|
writeSetupState,
|
||||||
} from '../src/shared/setup-state.js';
|
} from '../src/shared/setup-state.js';
|
||||||
|
|
||||||
@@ -407,23 +406,34 @@ setInterval(() => {}, 1000);
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
test('launcher smoke fixture seeds completed setup state', () => {
|
/**
|
||||||
const smokeCase = createSmokeCase('setup-state');
|
* Some sandboxes forbid binding unix sockets (EPERM). The fake mpv needs one, so these tests
|
||||||
|
* cannot pass there; probe once and skip them instead of weakening every assertion.
|
||||||
|
*/
|
||||||
|
function unixSocketsDenied(): boolean {
|
||||||
|
if (process.platform === 'win32') return false;
|
||||||
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-sock-probe-'));
|
||||||
try {
|
try {
|
||||||
const configDir = getDefaultConfigDir({
|
const probe = spawnSync(
|
||||||
xdgConfigHome: smokeCase.xdgConfigHome,
|
process.execPath,
|
||||||
homeDir: smokeCase.homeDir,
|
[
|
||||||
});
|
'-e',
|
||||||
const statePath = getSetupStatePath(configDir);
|
`require('node:net').createServer().on('error', (e) => { process.stderr.write(String(e)); process.exit(1); }).listen(${JSON.stringify(path.join(dir, 's.sock'))}, function () { this.close(() => process.exit(0)); });`,
|
||||||
|
],
|
||||||
assert.equal(readSetupState(statePath)?.status, 'completed');
|
{ encoding: 'utf8', timeout: 5000 },
|
||||||
|
);
|
||||||
|
return probe.status !== 0 && /eperm|operation not permitted/i.test(probe.stderr);
|
||||||
} finally {
|
} finally {
|
||||||
fs.rmSync(smokeCase.root, { recursive: true, force: true });
|
fs.rmSync(dir, { recursive: true, force: true });
|
||||||
fs.rmSync(smokeCase.socketDir, { recursive: true, force: true });
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
test('launcher mpv status returns ready when socket is connectable', async () => {
|
const skipWithoutUnixSockets = unixSocketsDenied() ? 'sandbox denies unix socket binding' : false;
|
||||||
|
|
||||||
|
test(
|
||||||
|
'launcher mpv status returns ready when socket is connectable',
|
||||||
|
{ skip: skipWithoutUnixSockets },
|
||||||
|
async () => {
|
||||||
await withSmokeCase('mpv-status', async (smokeCase) => {
|
await withSmokeCase('mpv-status', async (smokeCase) => {
|
||||||
const env = makeTestEnv(smokeCase);
|
const env = makeTestEnv(smokeCase);
|
||||||
const fakeMpv = spawn(smokeCase.fakeMpvPath, [`--input-ipc-server=${smokeCase.socketPath}`], {
|
const fakeMpv = spawn(smokeCase.fakeMpvPath, [`--input-ipc-server=${smokeCase.socketPath}`], {
|
||||||
@@ -439,20 +449,8 @@ test('launcher mpv status returns ready when socket is connectable', async () =>
|
|||||||
env,
|
env,
|
||||||
'mpv-status',
|
'mpv-status',
|
||||||
);
|
);
|
||||||
const fakeMpvEntries = readJsonLines(path.join(smokeCase.artifactsDir, 'fake-mpv.log'));
|
|
||||||
const fakeMpvError = fakeMpvEntries.find(
|
|
||||||
(entry): entry is { error: string } => typeof entry.error === 'string',
|
|
||||||
)?.error;
|
|
||||||
const unixSocketDenied =
|
|
||||||
typeof fakeMpvError === 'string' && /eperm|operation not permitted/i.test(fakeMpvError);
|
|
||||||
|
|
||||||
if (unixSocketDenied) {
|
|
||||||
assert.equal(result.status, 1);
|
|
||||||
assert.match(result.stdout, /socket not ready/i);
|
|
||||||
} else {
|
|
||||||
assert.equal(result.status, 0);
|
assert.equal(result.status, 0);
|
||||||
assert.match(result.stdout, /socket ready/i);
|
assert.match(result.stdout, /socket ready/i);
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
if (fakeMpv.exitCode === null) {
|
if (fakeMpv.exitCode === null) {
|
||||||
await new Promise<void>((resolve) => {
|
await new Promise<void>((resolve) => {
|
||||||
@@ -461,11 +459,12 @@ test('launcher mpv status returns ready when socket is connectable', async () =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'launcher start-overlay run forwards socket/backend and stops owned background app after mpv exits',
|
'launcher start-overlay run forwards socket/backend and stops owned background app after mpv exits',
|
||||||
{ timeout: LONG_SMOKE_TEST_TIMEOUT_MS },
|
{ timeout: LONG_SMOKE_TEST_TIMEOUT_MS, skip: skipWithoutUnixSockets },
|
||||||
async () => {
|
async () => {
|
||||||
await withSmokeCase('overlay-start-stop', async (smokeCase) => {
|
await withSmokeCase('overlay-start-stop', async (smokeCase) => {
|
||||||
const env = makeTestEnv(smokeCase);
|
const env = makeTestEnv(smokeCase);
|
||||||
@@ -484,13 +483,8 @@ test(
|
|||||||
const appStartEntries = readJsonLines(appStartPath);
|
const appStartEntries = readJsonLines(appStartPath);
|
||||||
const appStopEntries = readJsonLines(appStopPath);
|
const appStopEntries = readJsonLines(appStopPath);
|
||||||
const mpvEntries = readJsonLines(path.join(smokeCase.artifactsDir, 'fake-mpv.log'));
|
const mpvEntries = readJsonLines(path.join(smokeCase.artifactsDir, 'fake-mpv.log'));
|
||||||
const mpvError = mpvEntries.find(
|
|
||||||
(entry): entry is { error: string } => typeof entry.error === 'string',
|
|
||||||
)?.error;
|
|
||||||
const unixSocketDenied =
|
|
||||||
typeof mpvError === 'string' && /eperm|operation not permitted/i.test(mpvError);
|
|
||||||
|
|
||||||
assert.equal(result.status, unixSocketDenied ? 3 : 0);
|
assert.equal(result.status, 0);
|
||||||
assert.match(result.stdout, /Starting SubMiner overlay/i);
|
assert.match(result.stdout, /Starting SubMiner overlay/i);
|
||||||
|
|
||||||
assert.equal(appStartEntries.length, 1);
|
assert.equal(appStartEntries.length, 1);
|
||||||
@@ -523,7 +517,7 @@ test(
|
|||||||
|
|
||||||
test(
|
test(
|
||||||
'launcher start-overlay attaches to a running background app without spawning another app start command',
|
'launcher start-overlay attaches to a running background app without spawning another app start command',
|
||||||
{ timeout: LONG_SMOKE_TEST_TIMEOUT_MS },
|
{ timeout: LONG_SMOKE_TEST_TIMEOUT_MS, skip: skipWithoutUnixSockets },
|
||||||
async () => {
|
async () => {
|
||||||
await withSmokeCase('overlay-borrow-background', async (smokeCase) => {
|
await withSmokeCase('overlay-borrow-background', async (smokeCase) => {
|
||||||
const controlServer = await startFakeControlServer(smokeCase);
|
const controlServer = await startFakeControlServer(smokeCase);
|
||||||
@@ -549,14 +543,8 @@ test(
|
|||||||
const appStartEntries = readJsonLines(appStartPath);
|
const appStartEntries = readJsonLines(appStartPath);
|
||||||
const appStopEntries = readJsonLines(appStopPath);
|
const appStopEntries = readJsonLines(appStopPath);
|
||||||
const controlEntries = readJsonLines(controlServer.logPath);
|
const controlEntries = readJsonLines(controlServer.logPath);
|
||||||
const mpvEntries = readJsonLines(path.join(smokeCase.artifactsDir, 'fake-mpv.log'));
|
|
||||||
const mpvError = mpvEntries.find(
|
|
||||||
(entry): entry is { error: string } => typeof entry.error === 'string',
|
|
||||||
)?.error;
|
|
||||||
const unixSocketDenied =
|
|
||||||
typeof mpvError === 'string' && /eperm|operation not permitted/i.test(mpvError);
|
|
||||||
|
|
||||||
assert.equal(result.status, unixSocketDenied ? 3 : 0);
|
assert.equal(result.status, 0);
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
assert.equal(appEntries.length > 0, true);
|
assert.equal(appEntries.length > 0, true);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -583,7 +571,7 @@ test(
|
|||||||
|
|
||||||
test(
|
test(
|
||||||
'launcher starts mpv paused when plugin auto-start visible overlay gate is enabled',
|
'launcher starts mpv paused when plugin auto-start visible overlay gate is enabled',
|
||||||
{ timeout: LONG_SMOKE_TEST_TIMEOUT_MS },
|
{ timeout: LONG_SMOKE_TEST_TIMEOUT_MS, skip: skipWithoutUnixSockets },
|
||||||
async () => {
|
async () => {
|
||||||
await withSmokeCase('autoplay-ready-gate', async (smokeCase) => {
|
await withSmokeCase('autoplay-ready-gate', async (smokeCase) => {
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
@@ -607,14 +595,9 @@ test(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const mpvEntries = readJsonLines(path.join(smokeCase.artifactsDir, 'fake-mpv.log'));
|
const mpvEntries = readJsonLines(path.join(smokeCase.artifactsDir, 'fake-mpv.log'));
|
||||||
const mpvError = mpvEntries.find(
|
|
||||||
(entry): entry is { error: string } => typeof entry.error === 'string',
|
|
||||||
)?.error;
|
|
||||||
const unixSocketDenied =
|
|
||||||
typeof mpvError === 'string' && /eperm|operation not permitted/i.test(mpvError);
|
|
||||||
const mpvFirstArgs = mpvEntries[0]?.argv;
|
const mpvFirstArgs = mpvEntries[0]?.argv;
|
||||||
|
|
||||||
assert.equal(result.status, unixSocketDenied ? 3 : 0);
|
assert.equal(result.status, 0);
|
||||||
assert.equal(Array.isArray(mpvFirstArgs), true);
|
assert.equal(Array.isArray(mpvFirstArgs), true);
|
||||||
assert.equal((mpvFirstArgs as string[]).includes('--pause=yes'), true);
|
assert.equal((mpvFirstArgs as string[]).includes('--pause=yes'), true);
|
||||||
assert.match(
|
assert.match(
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { parseArgs } from '../config.js';
|
||||||
|
import type { Args } from '../types.js';
|
||||||
|
|
||||||
|
/** Default launcher `Args` (as if run with no CLI input), with `overrides` applied. */
|
||||||
|
export function makeLauncherArgs(overrides: Partial<Args> = {}): Args {
|
||||||
|
return { ...parseArgs([], 'subminer', {}), ...overrides };
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* Runs `run` with the given process env values (`undefined` deletes a key) and restores the
|
||||||
|
* originals afterwards, even if `run` throws or rejects.
|
||||||
|
*/
|
||||||
|
export async function withEnv<T>(
|
||||||
|
overrides: Record<string, string | undefined>,
|
||||||
|
run: () => T | Promise<T>,
|
||||||
|
): Promise<T> {
|
||||||
|
const originals = Object.fromEntries(
|
||||||
|
Object.keys(overrides).map((key) => [key, process.env[key]]),
|
||||||
|
);
|
||||||
|
const apply = (values: Record<string, string | undefined>): void => {
|
||||||
|
for (const [key, value] of Object.entries(values)) {
|
||||||
|
if (value === undefined) delete process.env[key];
|
||||||
|
else process.env[key] = value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
apply(overrides);
|
||||||
|
try {
|
||||||
|
return await run();
|
||||||
|
} finally {
|
||||||
|
apply(originals);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@ import os from 'node:os';
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { Database as BunDatabase } from 'bun:sqlite';
|
import { Database as BunDatabase } from 'bun:sqlite';
|
||||||
import { ensureSchema } from '../../src/core/services/immersion-tracker/storage.js';
|
import { ensureSchema } from '../../src/core/services/immersion-tracker/storage.js';
|
||||||
import { createImmersionDbFixture, insertFixtureSession } from './immersion-db-fixture.js';
|
import { createImmersionDbFixture } from './immersion-db-fixture.js';
|
||||||
|
|
||||||
type SchemaRow = { type: string; name: string; tbl_name: string; sql: string | null };
|
type SchemaRow = { type: string; name: string; tbl_name: string; sql: string | null };
|
||||||
|
|
||||||
@@ -108,65 +108,3 @@ test('fixture schema stays aligned with production sync-touched tables and index
|
|||||||
fs.rmSync(dir, { recursive: true, force: true });
|
fs.rmSync(dir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fixture leaves lexical rollups pending when their table is absent', () => {
|
|
||||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-fixture-rollup-state-'));
|
|
||||||
const fixturePath = path.join(dir, 'fixture.sqlite');
|
|
||||||
try {
|
|
||||||
createImmersionDbFixture(fixturePath);
|
|
||||||
const db = new BunDatabase(fixturePath, { readonly: true });
|
|
||||||
try {
|
|
||||||
const state = db
|
|
||||||
.query<{ state_value: string }>(
|
|
||||||
`SELECT state_value FROM imm_rollup_state
|
|
||||||
WHERE state_key = 'lexical_daily_rollups_version'`,
|
|
||||||
)
|
|
||||||
.get();
|
|
||||||
const rollupTable = db
|
|
||||||
.query<{ name: string }>(
|
|
||||||
`SELECT name FROM sqlite_schema
|
|
||||||
WHERE type = 'table' AND name = 'imm_lexical_daily_rollups'`,
|
|
||||||
)
|
|
||||||
.get();
|
|
||||||
|
|
||||||
assert.equal(state?.state_value, '0');
|
|
||||||
assert.equal(rollupTable, null);
|
|
||||||
} finally {
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
fs.rmSync(dir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('fixture session inserts enforce foreign keys', () => {
|
|
||||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'subminer-fixture-foreign-keys-'));
|
|
||||||
const fixturePath = path.join(dir, 'fixture.sqlite');
|
|
||||||
try {
|
|
||||||
createImmersionDbFixture(fixturePath);
|
|
||||||
const db = new BunDatabase(fixturePath, { readwrite: true });
|
|
||||||
try {
|
|
||||||
db.run(`
|
|
||||||
CREATE TRIGGER remove_fixture_video
|
|
||||||
BEFORE INSERT ON imm_sessions
|
|
||||||
BEGIN
|
|
||||||
DELETE FROM imm_videos WHERE video_id = NEW.video_id;
|
|
||||||
END
|
|
||||||
`);
|
|
||||||
} finally {
|
|
||||||
db.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.throws(
|
|
||||||
() =>
|
|
||||||
insertFixtureSession(fixturePath, {
|
|
||||||
uuid: 'foreign-key-check',
|
|
||||||
videoKey: 'foreign-key-check',
|
|
||||||
startedAtMs: Date.UTC(2026, 6, 9),
|
|
||||||
}),
|
|
||||||
/FOREIGN KEY constraint failed/,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
fs.rmSync(dir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -52,7 +52,6 @@ export function getDefaultMpvLogFile(options?: {
|
|||||||
|
|
||||||
export const DEFAULT_MPV_LOG_FILE = getDefaultMpvLogFile();
|
export const DEFAULT_MPV_LOG_FILE = getDefaultMpvLogFile();
|
||||||
export const DEFAULT_YOUTUBE_YTDL_FORMAT = 'bestvideo*+bestaudio/best';
|
export const DEFAULT_YOUTUBE_YTDL_FORMAT = 'bestvideo*+bestaudio/best';
|
||||||
export const DEFAULT_JIMAKU_API_BASE_URL = 'https://jimaku.cc';
|
|
||||||
export const DEFAULT_MPV_SUBMINER_ARGS = [
|
export const DEFAULT_MPV_SUBMINER_ARGS = [
|
||||||
'--sub-auto=fuzzy',
|
'--sub-auto=fuzzy',
|
||||||
'--sub-file-paths=.;subs;subtitles',
|
'--sub-file-paths=.;subs;subtitles',
|
||||||
@@ -69,7 +68,6 @@ export function shouldForwardLogLevel(level: LogLevel): boolean {
|
|||||||
return level === 'debug' || level === 'error';
|
return level === 'debug' || level === 'error';
|
||||||
}
|
}
|
||||||
export type Backend = 'auto' | 'hyprland' | 'sway' | 'x11' | 'macos' | 'windows';
|
export type Backend = 'auto' | 'hyprland' | 'sway' | 'x11' | 'macos' | 'windows';
|
||||||
export type JimakuLanguagePreference = 'ja' | 'en' | 'none';
|
|
||||||
|
|
||||||
export interface Args {
|
export interface Args {
|
||||||
generateSubtitles?: {
|
generateSubtitles?: {
|
||||||
@@ -103,11 +101,6 @@ export interface Args {
|
|||||||
passwordStore: string;
|
passwordStore: string;
|
||||||
target: string;
|
target: string;
|
||||||
targetKind: '' | 'file' | 'url';
|
targetKind: '' | 'file' | 'url';
|
||||||
jimakuApiKey: string;
|
|
||||||
jimakuApiKeyCommand: string;
|
|
||||||
jimakuApiBaseUrl: string;
|
|
||||||
jimakuLanguagePreference: JimakuLanguagePreference;
|
|
||||||
jimakuMaxEntryResults: number;
|
|
||||||
jellyfin: boolean;
|
jellyfin: boolean;
|
||||||
jellyfinLogin: boolean;
|
jellyfinLogin: boolean;
|
||||||
jellyfinLogout: boolean;
|
jellyfinLogout: boolean;
|
||||||
@@ -151,11 +144,6 @@ export interface Args {
|
|||||||
export interface LauncherYoutubeSubgenConfig {
|
export interface LauncherYoutubeSubgenConfig {
|
||||||
primarySubLanguages?: string[];
|
primarySubLanguages?: string[];
|
||||||
secondarySubLanguages?: string[];
|
secondarySubLanguages?: string[];
|
||||||
jimakuApiKey?: string;
|
|
||||||
jimakuApiKeyCommand?: string;
|
|
||||||
jimakuApiBaseUrl?: string;
|
|
||||||
jimakuLanguagePreference?: JimakuLanguagePreference;
|
|
||||||
jimakuMaxEntryResults?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LauncherJellyfinConfig {
|
export interface LauncherJellyfinConfig {
|
||||||
|
|||||||
+3
-3
@@ -62,6 +62,8 @@
|
|||||||
"test:launcher:unit:src": "bun scripts/run-test-lane.mjs bun-launcher-unit",
|
"test:launcher:unit:src": "bun scripts/run-test-lane.mjs bun-launcher-unit",
|
||||||
"test:scripts": "bun scripts/run-test-lane.mjs scripts",
|
"test:scripts": "bun scripts/run-test-lane.mjs scripts",
|
||||||
"test:stats": "bun scripts/run-test-lane.mjs stats",
|
"test:stats": "bun scripts/run-test-lane.mjs stats",
|
||||||
|
"test:e2e": "bun scripts/run-test-lane.mjs e2e --jobs 1",
|
||||||
|
"e2e": "bun e2e/cli.ts",
|
||||||
"test:env": "bun run test:launcher:smoke:src && bun run test:plugin:src && bun run test:immersion:sqlite:src",
|
"test:env": "bun run test:launcher:smoke:src && bun run test:plugin:src && bun run test:immersion:sqlite:src",
|
||||||
"test:runtime:compat": "bun run test:smoke:dist",
|
"test:runtime:compat": "bun run test:smoke:dist",
|
||||||
"test": "bun run test:fast",
|
"test": "bun run test:fast",
|
||||||
@@ -89,6 +91,7 @@
|
|||||||
"brace-expansion": "5.0.11",
|
"brace-expansion": "5.0.11",
|
||||||
"electron-builder-squirrel-windows": "26.16.1",
|
"electron-builder-squirrel-windows": "26.16.1",
|
||||||
"fast-uri": "3.1.7",
|
"fast-uri": "3.1.7",
|
||||||
|
"follow-redirects": "1.16.1",
|
||||||
"form-data": "4.0.6",
|
"form-data": "4.0.6",
|
||||||
"ip-address": "10.2.0",
|
"ip-address": "10.2.0",
|
||||||
"js-yaml": "4.3.2",
|
"js-yaml": "4.3.2",
|
||||||
@@ -112,8 +115,6 @@
|
|||||||
"author": "",
|
"author": "",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource-variable/geist": "^5.2.8",
|
|
||||||
"@fontsource-variable/geist-mono": "^5.2.7",
|
|
||||||
"@xhayper/discord-rpc": "^1.3.4",
|
"@xhayper/discord-rpc": "^1.3.4",
|
||||||
"axios": "^1.20.0",
|
"axios": "^1.20.0",
|
||||||
"commander": "^14.0.3",
|
"commander": "^14.0.3",
|
||||||
@@ -131,7 +132,6 @@
|
|||||||
"electron": "43.7.7",
|
"electron": "43.7.7",
|
||||||
"electron-builder": "26.16.1",
|
"electron-builder": "26.16.1",
|
||||||
"esbuild": "^0.25.12",
|
"esbuild": "^0.25.12",
|
||||||
"eslint": "^10.8.0",
|
|
||||||
"prettier": "^3.8.1",
|
"prettier": "^3.8.1",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"undici": "7.29.1"
|
"undici": "7.29.1"
|
||||||
|
|||||||
@@ -56,9 +56,6 @@ function M.init()
|
|||||||
ctx.binary = make_lazy_proxy("binary", function()
|
ctx.binary = make_lazy_proxy("binary", function()
|
||||||
return require("binary").create(ctx)
|
return require("binary").create(ctx)
|
||||||
end)
|
end)
|
||||||
ctx.hover = make_lazy_proxy("hover", function()
|
|
||||||
return require("hover").create(ctx)
|
|
||||||
end)
|
|
||||||
ctx.process = make_lazy_proxy("process", function()
|
ctx.process = make_lazy_proxy("process", function()
|
||||||
return require("process").create(ctx)
|
return require("process").create(ctx)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -1,430 +0,0 @@
|
|||||||
local M = {}
|
|
||||||
|
|
||||||
local DEFAULT_HOVER_BASE_COLOR = "FFFFFF"
|
|
||||||
local DEFAULT_HOVER_COLOR = "C6A0F6"
|
|
||||||
|
|
||||||
function M.create(ctx)
|
|
||||||
local mp = ctx.mp
|
|
||||||
local msg = ctx.msg
|
|
||||||
local utils = ctx.utils
|
|
||||||
local state = ctx.state
|
|
||||||
|
|
||||||
local function to_hex_color(input)
|
|
||||||
if type(input) ~= "string" then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local hex = input:gsub("[%#%']", ""):gsub("^0x", "")
|
|
||||||
if #hex ~= 6 and #hex ~= 3 then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
if #hex == 3 then
|
|
||||||
return hex:sub(1, 1) .. hex:sub(1, 1) .. hex:sub(2, 2) .. hex:sub(2, 2) .. hex:sub(3, 3) .. hex:sub(3, 3)
|
|
||||||
end
|
|
||||||
return hex
|
|
||||||
end
|
|
||||||
|
|
||||||
local function fix_ass_color(input, fallback)
|
|
||||||
local hex = to_hex_color(input)
|
|
||||||
if not hex then
|
|
||||||
return fallback or DEFAULT_HOVER_BASE_COLOR
|
|
||||||
end
|
|
||||||
local r, g, b = hex:sub(1, 2), hex:sub(3, 4), hex:sub(5, 6)
|
|
||||||
return b .. g .. r
|
|
||||||
end
|
|
||||||
|
|
||||||
local function sanitize_hover_ass_color(input, fallback_rgb)
|
|
||||||
local fallback = fix_ass_color(fallback_rgb or DEFAULT_HOVER_COLOR, DEFAULT_HOVER_COLOR)
|
|
||||||
local converted = fix_ass_color(input, fallback)
|
|
||||||
if converted == "000000" then
|
|
||||||
return fallback
|
|
||||||
end
|
|
||||||
return converted
|
|
||||||
end
|
|
||||||
|
|
||||||
local function escape_ass_text(text)
|
|
||||||
return (text or ""):gsub("\\", "\\\\"):gsub("{", "\\{"):gsub("}", "\\}"):gsub("\n", "\\N")
|
|
||||||
end
|
|
||||||
|
|
||||||
local function resolve_osd_dimensions()
|
|
||||||
local width = mp.get_property_number("osd-width", 0) or 0
|
|
||||||
local height = mp.get_property_number("osd-height", 0) or 0
|
|
||||||
|
|
||||||
if width <= 0 or height <= 0 then
|
|
||||||
local osd_dims = mp.get_property_native("osd-dimensions")
|
|
||||||
if type(osd_dims) == "table" and type(osd_dims.w) == "number" and osd_dims.w > 0 then
|
|
||||||
width = osd_dims.w
|
|
||||||
end
|
|
||||||
if type(osd_dims) == "table" and type(osd_dims.h) == "number" and osd_dims.h > 0 then
|
|
||||||
height = osd_dims.h
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if width <= 0 then
|
|
||||||
width = 1280
|
|
||||||
end
|
|
||||||
if height <= 0 then
|
|
||||||
height = 720
|
|
||||||
end
|
|
||||||
|
|
||||||
return width, height
|
|
||||||
end
|
|
||||||
|
|
||||||
local function resolve_metrics()
|
|
||||||
local sub_font_size = mp.get_property_number("sub-font-size", 36) or 36
|
|
||||||
local sub_scale = mp.get_property_number("sub-scale", 1) or 1
|
|
||||||
local sub_scale_by_window = mp.get_property_bool("sub-scale-by-window", true) == true
|
|
||||||
local sub_pos = mp.get_property_number("sub-pos", 100) or 100
|
|
||||||
local sub_margin_y = mp.get_property_number("sub-margin-y", 0) or 0
|
|
||||||
local sub_font = mp.get_property("sub-font", "sans-serif") or "sans-serif"
|
|
||||||
local sub_spacing = mp.get_property_number("sub-spacing", 0) or 0
|
|
||||||
local sub_bold = mp.get_property_bool("sub-bold", false) == true
|
|
||||||
local sub_italic = mp.get_property_bool("sub-italic", false) == true
|
|
||||||
local sub_border_size = mp.get_property_number("sub-border-size", 2) or 2
|
|
||||||
local sub_shadow_offset = mp.get_property_number("sub-shadow-offset", 0) or 0
|
|
||||||
local osd_w, osd_h = resolve_osd_dimensions()
|
|
||||||
local window_scale = 1
|
|
||||||
if sub_scale_by_window and osd_h > 0 then
|
|
||||||
window_scale = osd_h / 720
|
|
||||||
end
|
|
||||||
local effective_margin_y = sub_margin_y * window_scale
|
|
||||||
|
|
||||||
return {
|
|
||||||
font_size = sub_font_size * (sub_scale > 0 and sub_scale or 1) * window_scale,
|
|
||||||
pos = sub_pos,
|
|
||||||
margin_y = effective_margin_y,
|
|
||||||
font = sub_font,
|
|
||||||
spacing = sub_spacing,
|
|
||||||
bold = sub_bold,
|
|
||||||
italic = sub_italic,
|
|
||||||
border = sub_border_size * window_scale,
|
|
||||||
shadow = sub_shadow_offset * window_scale,
|
|
||||||
base_color = fix_ass_color(mp.get_property("sub-color"), DEFAULT_HOVER_BASE_COLOR),
|
|
||||||
hover_color = sanitize_hover_ass_color(nil, DEFAULT_HOVER_COLOR),
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_subtitle_ass_property()
|
|
||||||
local ass_text = mp.get_property("sub-text/ass")
|
|
||||||
if ass_text ~= nil then
|
|
||||||
if type(ass_text) == "string" and ass_text ~= "" then
|
|
||||||
return ass_text
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
ass_text = mp.get_property("sub-text-ass")
|
|
||||||
if type(ass_text) == "string" and ass_text ~= "" then
|
|
||||||
return ass_text
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local function plain_text_and_ass_map(text)
|
|
||||||
local plain = {}
|
|
||||||
local map = {}
|
|
||||||
local plain_len = 0
|
|
||||||
local i = 1
|
|
||||||
local text_len = #text
|
|
||||||
|
|
||||||
while i <= text_len do
|
|
||||||
local ch = text:sub(i, i)
|
|
||||||
if ch == "{" then
|
|
||||||
local close = text:find("}", i + 1, true)
|
|
||||||
if not close then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
i = close + 1
|
|
||||||
elseif ch == "\\" then
|
|
||||||
local esc = text:sub(i + 1, i + 1)
|
|
||||||
if esc == "N" or esc == "n" then
|
|
||||||
plain_len = plain_len + 1
|
|
||||||
plain[plain_len] = "\n"
|
|
||||||
map[plain_len] = i
|
|
||||||
i = i + 2
|
|
||||||
elseif esc == "h" then
|
|
||||||
plain_len = plain_len + 1
|
|
||||||
plain[plain_len] = " "
|
|
||||||
map[plain_len] = i
|
|
||||||
i = i + 2
|
|
||||||
elseif esc == "{" then
|
|
||||||
plain_len = plain_len + 1
|
|
||||||
plain[plain_len] = "{"
|
|
||||||
map[plain_len] = i
|
|
||||||
i = i + 2
|
|
||||||
elseif esc == "}" then
|
|
||||||
plain_len = plain_len + 1
|
|
||||||
plain[plain_len] = "}"
|
|
||||||
map[plain_len] = i
|
|
||||||
i = i + 2
|
|
||||||
elseif esc == "\\" then
|
|
||||||
plain_len = plain_len + 1
|
|
||||||
plain[plain_len] = "\\"
|
|
||||||
map[plain_len] = i
|
|
||||||
i = i + 2
|
|
||||||
else
|
|
||||||
local seq_end = i + 1
|
|
||||||
while seq_end <= text_len and text:sub(seq_end, seq_end):match("[%a]") do
|
|
||||||
seq_end = seq_end + 1
|
|
||||||
end
|
|
||||||
if text:sub(seq_end, seq_end) == "(" then
|
|
||||||
local close = text:find(")", seq_end, true)
|
|
||||||
if close then
|
|
||||||
i = close + 1
|
|
||||||
else
|
|
||||||
i = seq_end + 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
i = seq_end + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
plain_len = plain_len + 1
|
|
||||||
plain[plain_len] = ch
|
|
||||||
map[plain_len] = i
|
|
||||||
i = i + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return table.concat(plain), map
|
|
||||||
end
|
|
||||||
|
|
||||||
local function find_hover_span(payload, plain)
|
|
||||||
local source_len = #plain
|
|
||||||
local cursor = 1
|
|
||||||
for _, token in ipairs(payload.tokens or {}) do
|
|
||||||
if type(token) == "table" and type(token.text) == "string" and token.text ~= "" then
|
|
||||||
local token_text = token.text
|
|
||||||
local start_pos = nil
|
|
||||||
local end_pos = nil
|
|
||||||
|
|
||||||
if type(token.startPos) == "number" and type(token.endPos) == "number" then
|
|
||||||
if token.startPos >= 0 and token.endPos >= token.startPos then
|
|
||||||
local candidate_start = token.startPos + 1
|
|
||||||
local candidate_stop = token.endPos
|
|
||||||
if candidate_start >= 1 and candidate_stop <= source_len and candidate_stop >= candidate_start and plain:sub(candidate_start, candidate_stop) == token_text then
|
|
||||||
start_pos = candidate_start
|
|
||||||
end_pos = candidate_stop
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not start_pos or not end_pos then
|
|
||||||
local fallback_start, fallback_stop = plain:find(token_text, cursor, true)
|
|
||||||
if not fallback_start then
|
|
||||||
fallback_start, fallback_stop = plain:find(token_text, 1, true)
|
|
||||||
end
|
|
||||||
start_pos, end_pos = fallback_start, fallback_stop
|
|
||||||
end
|
|
||||||
|
|
||||||
if start_pos and end_pos then
|
|
||||||
if token.index == payload.hoveredTokenIndex then
|
|
||||||
return start_pos, end_pos
|
|
||||||
end
|
|
||||||
cursor = end_pos + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local function inject_hover_color_to_ass(raw_ass, plain_map, hover_start, hover_end, hover_color, base_color)
|
|
||||||
if hover_start == nil or hover_end == nil then
|
|
||||||
return raw_ass
|
|
||||||
end
|
|
||||||
|
|
||||||
local raw_open_idx = plain_map[hover_start] or 1
|
|
||||||
local raw_close_idx = plain_map[hover_end + 1] or (#raw_ass + 1)
|
|
||||||
if raw_open_idx < 1 then
|
|
||||||
raw_open_idx = 1
|
|
||||||
end
|
|
||||||
if raw_close_idx < 1 then
|
|
||||||
raw_close_idx = 1
|
|
||||||
end
|
|
||||||
if raw_open_idx > #raw_ass + 1 then
|
|
||||||
raw_open_idx = #raw_ass + 1
|
|
||||||
end
|
|
||||||
if raw_close_idx > #raw_ass + 1 then
|
|
||||||
raw_close_idx = #raw_ass + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
local before = raw_ass:sub(1, raw_open_idx - 1)
|
|
||||||
local hovered = raw_ass:sub(raw_open_idx, raw_close_idx - 1)
|
|
||||||
local after = raw_ass:sub(raw_close_idx)
|
|
||||||
local hover_suffix = string.format("\\1c&H%s&", hover_color)
|
|
||||||
|
|
||||||
-- Keep hover foreground stable even when inline ASS override tags (\1c/\c/\r) appear inside token.
|
|
||||||
hovered = hovered:gsub("{([^}]*)}", function(inner)
|
|
||||||
if inner:find("\\1c&H", 1, true) or inner:find("\\c&H", 1, true) or inner:find("\\r", 1, true) then
|
|
||||||
return "{" .. inner .. hover_suffix .. "}"
|
|
||||||
end
|
|
||||||
return "{" .. inner .. "}"
|
|
||||||
end)
|
|
||||||
|
|
||||||
local open_tag = string.format("{\\1c&H%s&}", hover_color)
|
|
||||||
local close_tag = string.format("{\\1c&H%s&}", base_color)
|
|
||||||
return before .. open_tag .. hovered .. close_tag .. after
|
|
||||||
end
|
|
||||||
|
|
||||||
local function build_hover_subtitle_content(payload)
|
|
||||||
local source_ass = get_subtitle_ass_property()
|
|
||||||
if type(source_ass) == "string" and source_ass ~= "" then
|
|
||||||
state.hover_highlight.cached_ass = source_ass
|
|
||||||
else
|
|
||||||
source_ass = state.hover_highlight.cached_ass
|
|
||||||
end
|
|
||||||
if type(source_ass) ~= "string" or source_ass == "" then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local plain_source, plain_map = plain_text_and_ass_map(source_ass)
|
|
||||||
if type(plain_source) ~= "string" or plain_source == "" then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local hover_start, hover_end = find_hover_span(payload, plain_source)
|
|
||||||
if not hover_start or not hover_end then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local metrics = resolve_metrics()
|
|
||||||
local hover_color = sanitize_hover_ass_color(payload.colors and payload.colors.hover or nil, DEFAULT_HOVER_COLOR)
|
|
||||||
local base_color = fix_ass_color(payload.colors and payload.colors.base or nil, metrics.base_color)
|
|
||||||
return inject_hover_color_to_ass(source_ass, plain_map, hover_start, hover_end, hover_color, base_color)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function clear_hover_overlay()
|
|
||||||
if state.hover_highlight.clear_timer then
|
|
||||||
state.hover_highlight.clear_timer:kill()
|
|
||||||
state.hover_highlight.clear_timer = nil
|
|
||||||
end
|
|
||||||
if state.hover_highlight.overlay_active then
|
|
||||||
if type(state.hover_highlight.saved_sub_visibility) == "string" then
|
|
||||||
mp.set_property("sub-visibility", state.hover_highlight.saved_sub_visibility)
|
|
||||||
else
|
|
||||||
mp.set_property("sub-visibility", "yes")
|
|
||||||
end
|
|
||||||
if type(state.hover_highlight.saved_secondary_sub_visibility) == "string" then
|
|
||||||
mp.set_property("secondary-sub-visibility", state.hover_highlight.saved_secondary_sub_visibility)
|
|
||||||
end
|
|
||||||
state.hover_highlight.saved_sub_visibility = nil
|
|
||||||
state.hover_highlight.saved_secondary_sub_visibility = nil
|
|
||||||
state.hover_highlight.overlay_active = false
|
|
||||||
end
|
|
||||||
mp.set_osd_ass(0, 0, "")
|
|
||||||
state.hover_highlight.payload = nil
|
|
||||||
state.hover_highlight.revision = -1
|
|
||||||
state.hover_highlight.cached_ass = nil
|
|
||||||
state.hover_highlight.last_hover_update_ts = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local function schedule_hover_clear(delay_seconds)
|
|
||||||
if state.hover_highlight.clear_timer then
|
|
||||||
state.hover_highlight.clear_timer:kill()
|
|
||||||
state.hover_highlight.clear_timer = nil
|
|
||||||
end
|
|
||||||
state.hover_highlight.clear_timer = mp.add_timeout(delay_seconds or 0.08, function()
|
|
||||||
state.hover_highlight.clear_timer = nil
|
|
||||||
clear_hover_overlay()
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function render_hover_overlay(payload)
|
|
||||||
if not payload or payload.hoveredTokenIndex == nil or payload.subtitle == nil then
|
|
||||||
clear_hover_overlay()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local ass = build_hover_subtitle_content(payload)
|
|
||||||
if not ass then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local osd_w, osd_h = resolve_osd_dimensions()
|
|
||||||
local metrics = resolve_metrics()
|
|
||||||
local osd_dims = mp.get_property_native("osd-dimensions")
|
|
||||||
local ml = (type(osd_dims) == "table" and type(osd_dims.ml) == "number") and osd_dims.ml or 0
|
|
||||||
local mr = (type(osd_dims) == "table" and type(osd_dims.mr) == "number") and osd_dims.mr or 0
|
|
||||||
local mt = (type(osd_dims) == "table" and type(osd_dims.mt) == "number") and osd_dims.mt or 0
|
|
||||||
local mb = (type(osd_dims) == "table" and type(osd_dims.mb) == "number") and osd_dims.mb or 0
|
|
||||||
local usable_w = math.max(1, osd_w - ml - mr)
|
|
||||||
local usable_h = math.max(1, osd_h - mt - mb)
|
|
||||||
local anchor_x = math.floor(ml + usable_w / 2)
|
|
||||||
local baseline_adjust = (metrics.border + metrics.shadow) * 5
|
|
||||||
local anchor_y = math.floor(mt + (usable_h * metrics.pos / 100) - metrics.margin_y + baseline_adjust)
|
|
||||||
local font_size = math.max(8, metrics.font_size)
|
|
||||||
local anchor_tag = string.format(
|
|
||||||
"{\\an2\\q2\\pos(%d,%d)\\fn%s\\fs%g\\b%d\\i%d\\fsp%g\\bord%g\\shad%g\\1c&H%s&}",
|
|
||||||
anchor_x,
|
|
||||||
anchor_y,
|
|
||||||
escape_ass_text(metrics.font),
|
|
||||||
font_size,
|
|
||||||
metrics.bold and 1 or 0,
|
|
||||||
metrics.italic and 1 or 0,
|
|
||||||
metrics.spacing,
|
|
||||||
metrics.border,
|
|
||||||
metrics.shadow,
|
|
||||||
metrics.base_color
|
|
||||||
)
|
|
||||||
if not state.hover_highlight.overlay_active then
|
|
||||||
state.hover_highlight.saved_sub_visibility = mp.get_property("sub-visibility")
|
|
||||||
state.hover_highlight.saved_secondary_sub_visibility = mp.get_property("secondary-sub-visibility")
|
|
||||||
mp.set_property("sub-visibility", "no")
|
|
||||||
mp.set_property("secondary-sub-visibility", "no")
|
|
||||||
state.hover_highlight.overlay_active = true
|
|
||||||
end
|
|
||||||
mp.set_osd_ass(osd_w, osd_h, anchor_tag .. ass)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function handle_hover_message(payload_json)
|
|
||||||
local parsed, parse_error = utils.parse_json(payload_json)
|
|
||||||
if not parsed then
|
|
||||||
msg.warn("Invalid hover-highlight payload: " .. tostring(parse_error))
|
|
||||||
clear_hover_overlay()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if type(parsed.revision) ~= "number" then
|
|
||||||
clear_hover_overlay()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if parsed.revision < state.hover_highlight.revision then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if type(parsed.hoveredTokenIndex) == "number" and type(parsed.tokens) == "table" then
|
|
||||||
if state.hover_highlight.clear_timer then
|
|
||||||
state.hover_highlight.clear_timer:kill()
|
|
||||||
state.hover_highlight.clear_timer = nil
|
|
||||||
end
|
|
||||||
state.hover_highlight.revision = parsed.revision
|
|
||||||
state.hover_highlight.payload = parsed
|
|
||||||
state.hover_highlight.last_hover_update_ts = mp.get_time() or 0
|
|
||||||
render_hover_overlay(state.hover_highlight.payload)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local now = mp.get_time() or 0
|
|
||||||
local elapsed_since_hover = now - (state.hover_highlight.last_hover_update_ts or 0)
|
|
||||||
state.hover_highlight.revision = parsed.revision
|
|
||||||
state.hover_highlight.payload = nil
|
|
||||||
if state.hover_highlight.overlay_active then
|
|
||||||
if elapsed_since_hover > 0.35 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
schedule_hover_clear(0.08)
|
|
||||||
else
|
|
||||||
clear_hover_overlay()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
|
||||||
HOVER_MESSAGE_NAME = "subminer-hover-token",
|
|
||||||
HOVER_MESSAGE_NAME_LEGACY = "yomipv-hover-token",
|
|
||||||
handle_hover_message = handle_hover_message,
|
|
||||||
clear_hover_overlay = clear_hover_overlay,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
@@ -10,7 +10,6 @@ function M.create(ctx)
|
|||||||
local state = ctx.state
|
local state = ctx.state
|
||||||
local options_helper = ctx.options_helper
|
local options_helper = ctx.options_helper
|
||||||
local process = ctx.process
|
local process = ctx.process
|
||||||
local hover = ctx.hover
|
|
||||||
local subminer_log = ctx.log.subminer_log
|
local subminer_log = ctx.log.subminer_log
|
||||||
local show_osd = ctx.log.show_osd
|
local show_osd = ctx.log.show_osd
|
||||||
|
|
||||||
@@ -308,7 +307,6 @@ function M.create(ctx)
|
|||||||
|
|
||||||
local function on_shutdown()
|
local function on_shutdown()
|
||||||
next_auto_start_retry_generation()
|
next_auto_start_retry_generation()
|
||||||
hover.clear_hover_overlay()
|
|
||||||
process.disarm_auto_play_ready_gate()
|
process.disarm_auto_play_ready_gate()
|
||||||
process.stop_overlay_loading_osd()
|
process.stop_overlay_loading_osd()
|
||||||
clear_pending_visible_overlay_hide()
|
clear_pending_visible_overlay_hide()
|
||||||
@@ -326,13 +324,9 @@ function M.create(ctx)
|
|||||||
mp.register_event("start-file", on_start_file)
|
mp.register_event("start-file", on_start_file)
|
||||||
mp.register_event("file-loaded", on_file_loaded)
|
mp.register_event("file-loaded", on_file_loaded)
|
||||||
mp.register_event("shutdown", on_shutdown)
|
mp.register_event("shutdown", on_shutdown)
|
||||||
mp.register_event("file-loaded", function()
|
|
||||||
hover.clear_hover_overlay()
|
|
||||||
end)
|
|
||||||
mp.register_event("end-file", function(event)
|
mp.register_event("end-file", function(event)
|
||||||
process.stop_overlay_loading_osd()
|
process.stop_overlay_loading_osd()
|
||||||
process.disarm_auto_play_ready_gate()
|
process.disarm_auto_play_ready_gate()
|
||||||
hover.clear_hover_overlay()
|
|
||||||
local reason = type(event) == "table" and event.reason or nil
|
local reason = type(event) == "table" and event.reason or nil
|
||||||
if is_reload_end_file(reason) then
|
if is_reload_end_file(reason) then
|
||||||
state.pending_reload_media_identity = state.current_media_identity or resolve_media_identity()
|
state.pending_reload_media_identity = state.current_media_identity or resolve_media_identity()
|
||||||
@@ -352,15 +346,6 @@ function M.create(ctx)
|
|||||||
hide_visible_overlay_after_end_file()
|
hide_visible_overlay_after_end_file()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
mp.register_event("shutdown", function()
|
|
||||||
hover.clear_hover_overlay()
|
|
||||||
end)
|
|
||||||
mp.add_hook("on_unload", 10, function()
|
|
||||||
hover.clear_hover_overlay()
|
|
||||||
end)
|
|
||||||
mp.observe_property("sub-start", "native", function()
|
|
||||||
hover.clear_hover_overlay()
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ function M.create(ctx)
|
|||||||
local mp = ctx.mp
|
local mp = ctx.mp
|
||||||
local opts = ctx.opts
|
local opts = ctx.opts
|
||||||
local process = ctx.process
|
local process = ctx.process
|
||||||
local hover = ctx.hover
|
|
||||||
local ui = ctx.ui
|
local ui = ctx.ui
|
||||||
local state = ctx.state
|
local state = ctx.state
|
||||||
|
|
||||||
@@ -49,12 +48,6 @@ function M.create(ctx)
|
|||||||
mp.register_script_message("subminer-overlay-loading-ready", function()
|
mp.register_script_message("subminer-overlay-loading-ready", function()
|
||||||
process.stop_overlay_loading_osd()
|
process.stop_overlay_loading_osd()
|
||||||
end)
|
end)
|
||||||
mp.register_script_message(hover.HOVER_MESSAGE_NAME, function(payload_json)
|
|
||||||
hover.handle_hover_message(payload_json)
|
|
||||||
end)
|
|
||||||
mp.register_script_message(hover.HOVER_MESSAGE_NAME_LEGACY, function(payload_json)
|
|
||||||
hover.handle_hover_message(payload_json)
|
|
||||||
end)
|
|
||||||
mp.register_script_message("subminer-stats-toggle", function()
|
mp.register_script_message("subminer-stats-toggle", function()
|
||||||
if opts.osd_messages then
|
if opts.osd_messages then
|
||||||
mp.osd_message("Stats: press ` (backtick) in overlay", 3)
|
mp.osd_message("Stats: press ` (backtick) in overlay", 3)
|
||||||
|
|||||||
@@ -8,16 +8,6 @@ function M.new()
|
|||||||
binary_available = false,
|
binary_available = false,
|
||||||
binary_path = nil,
|
binary_path = nil,
|
||||||
detected_backend = nil,
|
detected_backend = nil,
|
||||||
hover_highlight = {
|
|
||||||
revision = -1,
|
|
||||||
payload = nil,
|
|
||||||
saved_sub_visibility = nil,
|
|
||||||
saved_secondary_sub_visibility = nil,
|
|
||||||
overlay_active = false,
|
|
||||||
cached_ass = nil,
|
|
||||||
clear_timer = nil,
|
|
||||||
last_hover_update_ts = 0,
|
|
||||||
},
|
|
||||||
auto_play_ready_gate_armed = false,
|
auto_play_ready_gate_armed = false,
|
||||||
auto_play_ready_should_resume_playback = false,
|
auto_play_ready_should_resume_playback = false,
|
||||||
auto_play_ready_timeout = nil,
|
auto_play_ready_timeout = nil,
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
## Highlights
|
|
||||||
### Added
|
|
||||||
- **YouTube Browser Window**:
|
|
||||||
- Browse YouTube in a window that keeps your login across restarts. Open it with `subminer youtube` (or `subminer yt`), or choose **Browse YouTube** from the tray.
|
|
||||||
- Clicking a video plays it in mpv. Middle-click, Shift/Ctrl-click, or the right-click menu adds it to mpv's playlist.
|
|
||||||
- Queued videos get the same Japanese subtitle setup when they start playing.
|
|
||||||
- **Whisper Subtitles for YouTube**: Set `youtube.subtitleSource` to `whisper` to transcribe YouTube videos with Whisper instead of using YouTube's captions. The subtitle generation modal (`Ctrl+Shift+G`) now also works on YouTube videos.
|
|
||||||
- **Scroll Wheel and Mouse Bindings**: `keybindings` now accepts scroll wheel keys, and the settings key editor can capture them. Mouse button and wheel bindings from mpv now work while the cursor is over the overlay.
|
|
||||||
- **Run Commands From Session Help**: Press `Enter` or double-click a row in session help to run that command during playback.
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- **YouTube**:
|
|
||||||
- Japanese subtitles no longer fail with "HTTP 429" on videos that also have a machine-translated Japanese track.
|
|
||||||
- On Windows, the subtitle generation modal now works during YouTube playback.
|
|
||||||
- On Windows, playing a video queued from the YouTube browser window no longer clears the rest of mpv's queue.
|
|
||||||
- **Jellyfin**:
|
|
||||||
- The Japanese subtitle track is selected as soon as it downloads, instead of waiting for every other track.
|
|
||||||
- Japanese and English image-based subtitles (PGS, DVD, DVB) are now selected automatically.
|
|
||||||
- Timing review previews and mined card audio use the audio track you are playing.
|
|
||||||
- **Hyprland Overlay**: The overlay no longer interrupts mpv when it goes fullscreen. With `mpv.backend: x11`, the overlay stays clickable after mpv goes fullscreen.
|
|
||||||
- **mpv Key Bindings**: Keys from mpv's defaults and your `input.conf` (such as `9` and `0` for volume) now work while the overlay has focus, even when the overlay loads before SubMiner connects to mpv.
|
|
||||||
- **Media Timing Review**: Trim handles are now thin lines on the clip edges, and the original subtitle boundaries are plain orange bars. On macOS with Bluetooth headphones such as AirPods, the preview cursor now moves smoothly.
|
|
||||||
- **Stats**:
|
|
||||||
- Each mined card is counted once instead of twice.
|
|
||||||
- Overview totals, charts, the calendar, and the vocabulary summary update right after you delete sessions.
|
|
||||||
- Word and kanji dates stay correct after deletes and pruning, and the new-words charts now agree with the vocabulary summary. Existing data is repaired in the background on the next launch.
|
|
||||||
- **Yomitan Profile Safety**: Electron is updated to 43.7.7, and SubMiner now refuses to load your Yomitan data with an older or unsupported runtime. Automatic character-dictionary updates stop if a profile that had dictionaries suddenly reports none.
|
|
||||||
- **Security Updates**: Updated Electron and undici to resolve security advisories.
|
|
||||||
- **AppImage in Sandboxes**: The AppImage now opens a window when launched inside a sandbox such as `firejail --appimage`.
|
|
||||||
- **Ctrl+C Crash**: SubMiner no longer crashes with "write EPIPE" when you stop the terminal command that started it with Ctrl+C.
|
|
||||||
|
|
||||||
### Docs
|
|
||||||
- **Docs Site**: The docs site is shorter and easier to scan, and the configuration reference now has a table of keys and defaults for each section. Outdated pages were corrected, and the Arch Linux MeCab install now uses the AUR package `mecab-git`.
|
|
||||||
- **Stats**: Added docs on how the Overview refreshes after you delete sessions and how discovery dates are kept after pruning.
|
|
||||||
|
|
||||||
## What's Changed
|
|
||||||
|
|
||||||
- fix(storage): protect Yomitan profiles across Electron runtime changes by @ksyasuda in #211
|
|
||||||
- fix(jellyfin): select subtitles faster and survive failed track downloads by @ksyasuda in #270
|
|
||||||
- fix(jellyfin): use the current audio track for media generation by @ksyasuda in #271
|
|
||||||
- feat(youtube): add YouTube browser window and Whisper subtitle source by @ksyasuda in #273
|
|
||||||
- fix(overlay): thin centered trim handles and label-free subtitle boundaries in timing review by @ksyasuda in #274
|
|
||||||
- feat(overlay): run session help commands with Enter or double-click by @ksyasuda in #275
|
|
||||||
- fix(overlay): keep overlay mapped during Hyprland/Sway fullscreen by @ksyasuda in #276
|
|
||||||
- fix(linux): skip AppImage mount keepalive on sandbox squashfs mounts by @ksyasuda in #277
|
|
||||||
- fix(overlay): reload imported mpv keys after mpv connects by @ksyasuda in #278
|
|
||||||
- feat(overlay): forward mpv mouse button and wheel bindings by @ksyasuda in #279
|
|
||||||
- fix(stats): count mined cards once and keep lexical stats exact after deletes by @ksyasuda in #280
|
|
||||||
- fix(youtube): keep mpv queue when advancing to a queued video on Windows by @ksyasuda in #281
|
|
||||||
- fix(subtitles): allow Whisper generation during Windows YouTube stream playback by @ksyasuda in #282
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
See the README and docs/installation guide for full setup steps.
|
|
||||||
|
|
||||||
## Assets
|
|
||||||
|
|
||||||
- Linux: `SubMiner.AppImage`
|
|
||||||
- macOS: `SubMiner-*.dmg` and `SubMiner-*.zip`
|
|
||||||
- Windows: `SubMiner-*.exe` and `SubMiner-*-win.zip`
|
|
||||||
- Optional extras: `subminer-assets.tar.gz`, the `subminer` launcher, and the Windows `subminer.cmd` launcher
|
|
||||||
- Bun corresponding source: `bun-v1.3.5-source.tar.gz` and its `.sha256` file
|
|
||||||
|
|
||||||
Both launcher downloads use Bun included with the SubMiner app. Download `subminer` on Linux or macOS and `subminer.cmd` on Windows.
|
|
||||||
|
|
||||||
The app bundles an unmodified Bun 1.3.5 runtime. Bun is MIT licensed and statically links JavaScriptCore (LGPL 2.0) and TinyCC (LGPL 2.1). License texts and third-party notices ship inside the app under `resources/bun/licenses`, and the source archive above contains the matching Bun, WebKit, and dependency sources for relinking.
|
|
||||||
+481
-965
File diff suppressed because it is too large.
Load diff
@@ -1,26 +0,0 @@
|
|||||||
import assert from 'node:assert/strict';
|
|
||||||
import { readFileSync } from 'node:fs';
|
|
||||||
import test from 'node:test';
|
|
||||||
|
|
||||||
const source = readFileSync('scripts/compare-yomitan-api.ts', 'utf8');
|
|
||||||
|
|
||||||
test('creates the configured Yomitan user-data directory before Electron uses it', () => {
|
|
||||||
const setPathIndex = source.indexOf(
|
|
||||||
"electronModule.app.setPath('userData', options.yomitanUserDataPath)",
|
|
||||||
);
|
|
||||||
assert.notEqual(setPathIndex, -1);
|
|
||||||
|
|
||||||
const mkdirIndex = source.lastIndexOf(
|
|
||||||
'fs.mkdirSync(options.yomitanUserDataPath, { recursive: true })',
|
|
||||||
setPathIndex,
|
|
||||||
);
|
|
||||||
assert.ok(mkdirIndex > -1, 'must create the user-data directory');
|
|
||||||
assert.ok(mkdirIndex < setPathIndex, 'must create the directory before app.setPath');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('lets output drain by using exitCode in the top-level completion handlers', () => {
|
|
||||||
const completionHandlers = source.slice(source.lastIndexOf('\nmain()'));
|
|
||||||
assert.match(completionHandlers, /process\.exitCode = process\.exitCode \?\? 0/);
|
|
||||||
assert.match(completionHandlers, /process\.exitCode = 1/);
|
|
||||||
assert.doesNotMatch(completionHandlers, /process\.exit\(/);
|
|
||||||
});
|
|
||||||
@@ -21,6 +21,7 @@ const requiredDocs = [
|
|||||||
'docs/workflow/README.md',
|
'docs/workflow/README.md',
|
||||||
'docs/workflow/agent-skills.md',
|
'docs/workflow/agent-skills.md',
|
||||||
'docs/workflow/planning.md',
|
'docs/workflow/planning.md',
|
||||||
|
'docs/workflow/testing.md',
|
||||||
'docs/workflow/verification.md',
|
'docs/workflow/verification.md',
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
import assert from 'node:assert/strict';
|
|
||||||
import { readFileSync } from 'node:fs';
|
|
||||||
import test from 'node:test';
|
|
||||||
|
|
||||||
const source = readFileSync('scripts/get-mpv-window-macos.swift', 'utf8');
|
|
||||||
|
|
||||||
test('minimized Accessibility windows are validated by PID and socket before reporting minimized', () => {
|
|
||||||
const minimizedAssignmentIndex = source.indexOf('foundMinimizedTargetWindow = true');
|
|
||||||
assert.notEqual(minimizedAssignmentIndex, -1);
|
|
||||||
|
|
||||||
const loopStartIndex = source.lastIndexOf('for window in windows', minimizedAssignmentIndex);
|
|
||||||
assert.notEqual(loopStartIndex, -1);
|
|
||||||
|
|
||||||
const pidExtractionIndex = source.indexOf(
|
|
||||||
'AXUIElementGetPid(window, &windowPid)',
|
|
||||||
loopStartIndex,
|
|
||||||
);
|
|
||||||
const appPidMatchIndex = source.indexOf('windowPid != app.processIdentifier', loopStartIndex);
|
|
||||||
const socketCheckIndex = source.indexOf('if !windowHasTargetSocket(windowPid)', loopStartIndex);
|
|
||||||
|
|
||||||
assert.ok(
|
|
||||||
pidExtractionIndex > loopStartIndex && pidExtractionIndex < minimizedAssignmentIndex,
|
|
||||||
'window PID must be extracted before accepting a minimized window',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
appPidMatchIndex > pidExtractionIndex && appPidMatchIndex < minimizedAssignmentIndex,
|
|
||||||
'window PID must match the owning app before accepting a minimized window',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
socketCheckIndex > appPidMatchIndex && socketCheckIndex < minimizedAssignmentIndex,
|
|
||||||
'target socket must be validated before accepting a minimized window',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('focused mpv window follows the frontmost mpv app signal', () => {
|
|
||||||
const focusHelperIndex = source.indexOf('private func isFocusedMpvWindow');
|
|
||||||
assert.notEqual(focusHelperIndex, -1);
|
|
||||||
|
|
||||||
const nextFunctionIndex = source.indexOf('\nprivate func ', focusHelperIndex + 1);
|
|
||||||
const focusHelperBody = source.slice(focusHelperIndex, nextFunctionIndex);
|
|
||||||
|
|
||||||
assert.ok(
|
|
||||||
focusHelperBody.includes('frontmost.pid == ownerPid'),
|
|
||||||
'matching frontmost PID should mark the mpv window focused',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
focusHelperBody.includes('frontmost.isMpv && windowHasTargetSocket(ownerPid)'),
|
|
||||||
'frontmost mpv app should mark the target mpv window focused even when PIDs differ',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
source.includes('focused: isFocusedMpvWindow(ownerPid: windowPid, frontmost: frontmost)'),
|
|
||||||
'Accessibility path should use the shared focused mpv helper',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
source.includes('focused: isFocusedMpvWindow(ownerPid: ownerPid, frontmost: frontmost)'),
|
|
||||||
'CoreGraphics path should use the shared focused mpv helper',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('frontmost mpv app emits active state when geometry lookup misses', () => {
|
|
||||||
assert.ok(
|
|
||||||
/case\s+\.active:/.test(source),
|
|
||||||
'helper should expose an active state without window geometry',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
source.includes('if windowHasTargetSocket(frontmost.pid)'),
|
|
||||||
'active state should still accept a matching target socket when available',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
source.includes('return targetMpvSocketPath != nil'),
|
|
||||||
'active state should preserve frontmost mpv even if command-line socket detection fails',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
source.includes('return .active'),
|
|
||||||
'lookup should preserve active mpv state after geometry lookup misses',
|
|
||||||
);
|
|
||||||
assert.ok(source.includes('print("active")'), 'active state should be printed for the tracker');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('frontmost non-mpv app emits inactive state when geometry lookup misses', () => {
|
|
||||||
assert.ok(
|
|
||||||
/case\s+\.inactive:/.test(source),
|
|
||||||
'helper should expose an inactive state without window geometry',
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
source.includes('if frontmost != nil'),
|
|
||||||
'helper should distinguish a known non-mpv frontmost app from an unknown miss',
|
|
||||||
);
|
|
||||||
assert.ok(source.includes('return .inactive'), 'known non-mpv focus should return inactive');
|
|
||||||
assert.ok(
|
|
||||||
source.includes('print("inactive")'),
|
|
||||||
'inactive state should be printed for the tracker',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
import assert from 'node:assert/strict';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import path from 'node:path';
|
|
||||||
import test from 'node:test';
|
|
||||||
import { spawnSync } from 'node:child_process';
|
|
||||||
|
|
||||||
function createWorkspace(name: string): string {
|
|
||||||
const baseDir = path.join(process.cwd(), '.tmp', 'get-frequency-typecheck-test');
|
|
||||||
fs.mkdirSync(baseDir, { recursive: true });
|
|
||||||
return fs.mkdtempSync(path.join(baseDir, `${name}-`));
|
|
||||||
}
|
|
||||||
|
|
||||||
test('scripts/get_frequency.ts typechecks in isolation', () => {
|
|
||||||
const workspace = createWorkspace('isolated-script');
|
|
||||||
const tsconfigPath = path.join(workspace, 'tsconfig.json');
|
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
tsconfigPath,
|
|
||||||
JSON.stringify(
|
|
||||||
{
|
|
||||||
extends: '../../../tsconfig.typecheck.json',
|
|
||||||
include: ['../../../scripts/get_frequency.ts'],
|
|
||||||
exclude: [],
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = spawnSync('bunx', ['tsc', '--noEmit', '-p', tsconfigPath], {
|
|
||||||
cwd: process.cwd(),
|
|
||||||
encoding: 'utf8',
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.equal(
|
|
||||||
result.status,
|
|
||||||
0,
|
|
||||||
`expected scripts/get_frequency.ts to typecheck\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`,
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
fs.rmSync(workspace, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -39,24 +39,6 @@ describe('Bun corresponding-source manifest', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('pins the source to the revision reported by the distributed binary', async () => {
|
|
||||||
const manifest = parseSourceManifest(
|
|
||||||
JSON.parse(
|
|
||||||
await fs.readFile(path.join(projectRoot, 'build/bun-source-manifest.json'), 'utf8'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(manifest.version).toBe('1.3.5');
|
|
||||||
expect(manifest.bunRevision).toBe('1e86cebd74a5723e818b5c0555276b646bcf0e4c');
|
|
||||||
expect(manifest.releaseTagCommit).toBe('fa5a5bbe556a4bda5bde77b4013aa6c3bb4ec9ab');
|
|
||||||
expect(manifest.sources.find((source) => source.name === 'WebKit')?.revision).toBe(
|
|
||||||
'6d0f3aac0b817cc01a846b3754b21271adedac12',
|
|
||||||
);
|
|
||||||
expect(manifest.sources.find((source) => source.name === 'tinycc')?.revision).toBe(
|
|
||||||
'29985a3b59898861442fa3b43f663fc1af2591d7',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('parses commit and tag registrations from Bun CMake', () => {
|
test('parses commit and tag registrations from Bun CMake', () => {
|
||||||
const registrations = parseRegisteredRepositories(`
|
const registrations = parseRegisteredRepositories(`
|
||||||
register_repository(
|
register_repository(
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import test from 'node:test';
|
|
||||||
import assert from 'node:assert/strict';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import path from 'node:path';
|
|
||||||
|
|
||||||
test('build:syncui bundles the sandboxed preload and keeps Electron external', () => {
|
|
||||||
const packageJson = JSON.parse(
|
|
||||||
fs.readFileSync(path.join(import.meta.dir, '..', 'package.json'), 'utf8'),
|
|
||||||
) as { scripts: Record<string, string> };
|
|
||||||
const command = packageJson.scripts['build:syncui'] ?? '';
|
|
||||||
|
|
||||||
assert.match(command, /src\/preload-syncui\.ts/);
|
|
||||||
assert.match(command, /--bundle/);
|
|
||||||
assert.match(command, /--external:electron/);
|
|
||||||
assert.match(command, /--outfile=dist\/preload-syncui\.js/);
|
|
||||||
});
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import assert from 'node:assert/strict';
|
|
||||||
import { readFileSync } from 'node:fs';
|
|
||||||
import test from 'node:test';
|
|
||||||
|
|
||||||
const source = readFileSync('scripts/prepare-build-assets.mjs', 'utf8');
|
|
||||||
|
|
||||||
test('macOS helper build creates dist scripts directory before swiftc output', () => {
|
|
||||||
const buildFunctionIndex = source.indexOf('function buildMacosHelper()');
|
|
||||||
assert.notEqual(buildFunctionIndex, -1);
|
|
||||||
|
|
||||||
const swiftcIndex = source.indexOf("'swiftc'", buildFunctionIndex);
|
|
||||||
assert.notEqual(swiftcIndex, -1);
|
|
||||||
|
|
||||||
const ensureDirIndex = source.lastIndexOf('ensureDir(scriptsOutputDir)', swiftcIndex);
|
|
||||||
|
|
||||||
assert.ok(
|
|
||||||
ensureDirIndex > buildFunctionIndex,
|
|
||||||
'buildMacosHelper must create dist/scripts before swiftc writes the helper binary',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Regression guard for #213: an untargeted swiftc stamps the build machine's OS
|
|
||||||
// version as the helper's minimum, so released builds refuse to load on older macOS.
|
|
||||||
test('macOS helper is compiled with an explicit deployment target', () => {
|
|
||||||
assert.match(source, /-target/);
|
|
||||||
assert.match(source, /apple-macos\$\{MACOS_HELPER_DEPLOYMENT_TARGET\}/);
|
|
||||||
});
|
|
||||||
@@ -12,6 +12,7 @@ paths=(
|
|||||||
".prettierrc.json"
|
".prettierrc.json"
|
||||||
".github"
|
".github"
|
||||||
"build"
|
"build"
|
||||||
|
"e2e"
|
||||||
"launcher"
|
"launcher"
|
||||||
"scripts"
|
"scripts"
|
||||||
"src"
|
"src"
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ test('resolveCoverageDir keeps coverage output inside the repository', () => {
|
|||||||
assert.throws(() => resolveCoverageDir(repoRoot, ['--coverage-dir', '/tmp/escape']));
|
assert.throws(() => resolveCoverageDir(repoRoot, ['--coverage-dir', '/tmp/escape']));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('runCoverageLane returns a failure when a discovered test fails', () => {
|
test('runCoverageLane returns a failure when a discovered test fails', async () => {
|
||||||
const repoRoot = mkdtempSync(join(tmpdir(), 'subminer-coverage-failure-'));
|
const repoRoot = mkdtempSync(join(tmpdir(), 'subminer-coverage-failure-'));
|
||||||
try {
|
try {
|
||||||
mkdirSync(join(repoRoot, 'src'));
|
mkdirSync(join(repoRoot, 'src'));
|
||||||
@@ -93,10 +93,10 @@ test('runCoverageLane returns a failure when a discovered test fails', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
assert.notEqual(
|
assert.notEqual(
|
||||||
runCoverageLane({
|
await runCoverageLane({
|
||||||
repoRootDir: repoRoot,
|
repoRootDir: repoRoot,
|
||||||
argv: ['bun-src-full', '--coverage-dir', 'coverage/test-src'],
|
argv: ['bun-src-full', '--coverage-dir', 'coverage/test-src'],
|
||||||
stdio: 'pipe',
|
quiet: true,
|
||||||
}),
|
}),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||||
import { spawnSync } from 'node:child_process';
|
import { spawn } from 'node:child_process';
|
||||||
|
import { availableParallelism } from 'node:os';
|
||||||
import { isAbsolute, join, relative, resolve } from 'node:path';
|
import { isAbsolute, join, relative, resolve } from 'node:path';
|
||||||
import { collectLaneFiles } from './test-lanes';
|
import { collectLaneFiles } from './test-lanes';
|
||||||
|
|
||||||
@@ -201,9 +202,40 @@ export function mergeLcovReports(reports: string[]): string {
|
|||||||
return chunks.length > 0 ? `${chunks.join('\n')}\n` : '';
|
return chunks.length > 0 ? `${chunks.join('\n')}\n` : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function runCoverageLane(
|
type ShardResult = { status: number; output: string; lcov: string | null };
|
||||||
options: { repoRootDir?: string; argv?: string[]; stdio?: 'inherit' | 'pipe' } = {},
|
|
||||||
): number {
|
// Runs one test file under coverage into its own shard directory, buffering
|
||||||
|
// output so parallel shards do not interleave on the terminal.
|
||||||
|
function runShard(repoRootDir: string, file: string, shardDir: string): Promise<ShardResult> {
|
||||||
|
return new Promise((resolveShard) => {
|
||||||
|
const child = spawn(
|
||||||
|
'bun',
|
||||||
|
['test', '--coverage', '--coverage-reporter=lcov', '--coverage-dir', shardDir, `./${file}`],
|
||||||
|
{ cwd: repoRootDir },
|
||||||
|
);
|
||||||
|
let output = '';
|
||||||
|
child.stdout.on('data', (chunk) => (output += chunk));
|
||||||
|
child.stderr.on('data', (chunk) => (output += chunk));
|
||||||
|
child.on('error', (error) => resolveShard({ status: 1, output: String(error), lcov: null }));
|
||||||
|
child.on('close', (code) => {
|
||||||
|
const lcovPath = join(shardDir, 'lcov.info');
|
||||||
|
const lcov = existsSync(lcovPath) ? readFileSync(lcovPath, 'utf8') : null;
|
||||||
|
resolveShard({ status: code ?? 1, output, lcov });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseJobsArg(argv: string[]): number {
|
||||||
|
const index = argv.indexOf('--jobs');
|
||||||
|
if (index === -1) return availableParallelism();
|
||||||
|
return Math.max(1, Number(argv[index + 1]) || 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shards run in parallel (one per CPU unless --jobs N). The first failing shard
|
||||||
|
// stops scheduling new shards and its exit status becomes the lane result.
|
||||||
|
export async function runCoverageLane(
|
||||||
|
options: { repoRootDir?: string; argv?: string[]; quiet?: boolean } = {},
|
||||||
|
): Promise<number> {
|
||||||
const repoRootDir = options.repoRootDir ?? repoRoot;
|
const repoRootDir = options.repoRootDir ?? repoRoot;
|
||||||
const argv = options.argv ?? process.argv.slice(2);
|
const argv = options.argv ?? process.argv.slice(2);
|
||||||
const laneName = argv[0];
|
const laneName = argv[0];
|
||||||
@@ -225,40 +257,44 @@ export function runCoverageLane(
|
|||||||
process.stderr.write(`${error instanceof Error ? error.message : error}\n`);
|
process.stderr.write(`${error instanceof Error ? error.message : error}\n`);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
const reports: string[] = [];
|
|
||||||
|
const reports: Array<string | null> = new Array(files.length).fill(null);
|
||||||
|
const failures: Array<{ file: string; result: ShardResult }> = [];
|
||||||
|
let nextIndex = 0;
|
||||||
|
|
||||||
|
const worker = async (): Promise<void> => {
|
||||||
|
while (failures.length === 0 && nextIndex < files.length) {
|
||||||
|
const index = nextIndex++;
|
||||||
|
const file = files[index]!;
|
||||||
|
const shardDir = join(shardRoot, String(index + 1).padStart(3, '0'));
|
||||||
|
const result = await runShard(repoRootDir, file, shardDir);
|
||||||
|
if (result.status !== 0) {
|
||||||
|
failures.push({ file, result });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (result.lcov === null && !options.quiet) {
|
||||||
|
process.stdout.write(`Skipping empty coverage shard for ${file}\n`);
|
||||||
|
}
|
||||||
|
reports[index] = result.lcov;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (const [index, file] of files.entries()) {
|
const jobs = Math.min(parseJobsArg(argv), files.length);
|
||||||
const shardDir = join(shardRoot, `${String(index + 1).padStart(3, '0')}`);
|
await Promise.all(Array.from({ length: jobs }, worker));
|
||||||
const result = spawnSync(
|
|
||||||
'bun',
|
|
||||||
['test', '--coverage', '--coverage-reporter=lcov', '--coverage-dir', shardDir, `./${file}`],
|
|
||||||
{
|
|
||||||
cwd: repoRootDir,
|
|
||||||
stdio: options.stdio ?? 'inherit',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result.error) {
|
const [failure] = failures;
|
||||||
throw result.error;
|
if (failure !== undefined) {
|
||||||
|
const { file, result } = failure;
|
||||||
|
if (!options.quiet) {
|
||||||
|
process.stderr.write(`${result.output}\nCoverage shard failed: ${file}\n`);
|
||||||
}
|
}
|
||||||
if ((result.status ?? 1) !== 0) {
|
return result.status;
|
||||||
return result.status ?? 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const lcovPath = join(shardDir, 'lcov.info');
|
const lcovPath = join(coverageDir, 'lcov.info');
|
||||||
if (!existsSync(lcovPath)) {
|
writeFileSync(lcovPath, mergeLcovReports(reports.filter((r) => r !== null)), 'utf8');
|
||||||
process.stdout.write(`Skipping empty coverage shard for ${file}\n`);
|
process.stdout.write(`Merged LCOV written to ${relative(repoRootDir, lcovPath)}\n`);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
reports.push(readFileSync(lcovPath, 'utf8'));
|
|
||||||
}
|
|
||||||
|
|
||||||
writeFileSync(join(coverageDir, 'lcov.info'), mergeLcovReports(reports), 'utf8');
|
|
||||||
process.stdout.write(
|
|
||||||
`Merged LCOV written to ${relative(repoRootDir, join(coverageDir, 'lcov.info'))}\n`,
|
|
||||||
);
|
|
||||||
return 0;
|
return 0;
|
||||||
} finally {
|
} finally {
|
||||||
rmSync(shardRoot, { recursive: true, force: true });
|
rmSync(shardRoot, { recursive: true, force: true });
|
||||||
@@ -267,5 +303,5 @@ export function runCoverageLane(
|
|||||||
|
|
||||||
// @ts-ignore Bun entrypoint detection; TS config for scripts still targets CommonJS.
|
// @ts-ignore Bun entrypoint detection; TS config for scripts still targets CommonJS.
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
process.exit(runCoverageLane());
|
runCoverageLane().then((status) => process.exit(status));
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { resolve } from 'node:path';
|
import { resolve } from 'node:path';
|
||||||
|
import { availableParallelism } from 'node:os';
|
||||||
import { spawn, spawnSync } from 'node:child_process';
|
import { spawn, spawnSync } from 'node:child_process';
|
||||||
import { collectLaneFiles } from './test-lanes.ts';
|
import { collectLaneFiles } from './test-lanes.ts';
|
||||||
|
|
||||||
@@ -7,6 +8,8 @@ import { collectLaneFiles } from './test-lanes.ts';
|
|||||||
// test file so a hanging test or leaked global in one file cannot poison the
|
// test file so a hanging test or leaked global in one file cannot poison the
|
||||||
// rest of the lane. Use --single-process for the old all-in-one-process mode.
|
// rest of the lane. Use --single-process for the old all-in-one-process mode.
|
||||||
//
|
//
|
||||||
|
// Files run in parallel, one worker per CPU by default; --jobs 1 runs serially.
|
||||||
|
//
|
||||||
// Usage: bun scripts/run-test-lane.mjs <lane> [--jobs N] [--timeout-secs N] [--single-process]
|
// Usage: bun scripts/run-test-lane.mjs <lane> [--jobs N] [--timeout-secs N] [--single-process]
|
||||||
|
|
||||||
const repoRoot = resolve(fileURLToPath(new URL('..', import.meta.url)));
|
const repoRoot = resolve(fileURLToPath(new URL('..', import.meta.url)));
|
||||||
@@ -34,7 +37,12 @@ for (const signal of ['SIGINT', 'SIGTERM']) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseArgs(argv) {
|
function parseArgs(argv) {
|
||||||
const options = { lane: undefined, jobs: 1, timeoutSecs: 300, singleProcess: false };
|
const options = {
|
||||||
|
lane: undefined,
|
||||||
|
jobs: availableParallelism(),
|
||||||
|
timeoutSecs: 300,
|
||||||
|
singleProcess: false,
|
||||||
|
};
|
||||||
for (let index = 0; index < argv.length; index += 1) {
|
for (let index = 0; index < argv.length; index += 1) {
|
||||||
const arg = argv[index];
|
const arg = argv[index];
|
||||||
if (arg === '--jobs') {
|
if (arg === '--jobs') {
|
||||||
|
|||||||
@@ -61,15 +61,6 @@ test('normalizeTarget maps each supported electron-builder target without using
|
|||||||
assert.throws(() => normalizeTarget('linux', 0), /Unsupported Bun runtime target architecture/);
|
assert.throws(() => normalizeTarget('linux', 0), /Unsupported Bun runtime target architecture/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('resolveArtifact chooses baseline x64 builds and standard arm64 builds', () => {
|
|
||||||
const config = runtimeConfig();
|
|
||||||
assert.equal(resolveArtifact(config, 'linux', 'x64').file, 'bun-linux-x64-baseline.zip');
|
|
||||||
assert.equal(resolveArtifact(config, 'darwin', 'x64').file, 'bun-darwin-x64-baseline.zip');
|
|
||||||
assert.equal(resolveArtifact(config, 'win32', 'x64').file, 'bun-windows-x64-baseline.zip');
|
|
||||||
assert.equal(resolveArtifact(config, 'linux', 'arm64').file, 'bun-linux-aarch64.zip');
|
|
||||||
assert.equal(resolveArtifact(config, 'darwin', 'arm64').file, 'bun-darwin-aarch64.zip');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('tracked runtime manifest covers every supported target at the packageManager version', async () => {
|
test('tracked runtime manifest covers every supported target at the packageManager version', async () => {
|
||||||
const config = await loadRuntimeConfig();
|
const config = await loadRuntimeConfig();
|
||||||
assert.equal(config.version, '1.3.5');
|
assert.equal(config.version, '1.3.5');
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ export const testLanes: Record<string, TestLane> = {
|
|||||||
roots: ['scripts'],
|
roots: ['scripts'],
|
||||||
include: ['.test.ts'],
|
include: ['.test.ts'],
|
||||||
},
|
},
|
||||||
|
// Boots the built app, mpv, and a fake AnkiConnect on an offscreen display.
|
||||||
|
// Slow and dependent on mpv/ffmpeg/Xvfb, so it stays out of test:fast.
|
||||||
|
e2e: {
|
||||||
|
roots: ['e2e'],
|
||||||
|
include: ['.e2e.test.ts'],
|
||||||
|
},
|
||||||
stats: {
|
stats: {
|
||||||
roots: ['stats/src'],
|
roots: ['stats/src'],
|
||||||
include: ['.test.ts', '.test.tsx'],
|
include: ['.test.ts', '.test.tsx'],
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
local MODULE_PATHS = {
|
local MODULE_PATHS = {
|
||||||
"plugin/subminer/bootstrap.lua",
|
"plugin/subminer/bootstrap.lua",
|
||||||
"plugin/subminer/hover.lua",
|
|
||||||
"plugin/subminer/environment.lua",
|
"plugin/subminer/environment.lua",
|
||||||
"plugin/subminer/version.lua",
|
"plugin/subminer/version.lua",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,7 +267,6 @@ local function run_plugin_scenario(config)
|
|||||||
package.loaded["binary"] = nil
|
package.loaded["binary"] = nil
|
||||||
package.loaded["bootstrap"] = nil
|
package.loaded["bootstrap"] = nil
|
||||||
package.loaded["environment"] = nil
|
package.loaded["environment"] = nil
|
||||||
package.loaded["hover"] = nil
|
|
||||||
package.loaded["init"] = nil
|
package.loaded["init"] = nil
|
||||||
package.loaded["lifecycle"] = nil
|
package.loaded["lifecycle"] = nil
|
||||||
package.loaded["log"] = nil
|
package.loaded["log"] = nil
|
||||||
|
|||||||
@@ -3,20 +3,6 @@ import assert from 'node:assert/strict';
|
|||||||
import { AnkiConnectClient } from './anki-connect';
|
import { AnkiConnectClient } from './anki-connect';
|
||||||
import { setLogLevel } from './logger';
|
import { setLogLevel } from './logger';
|
||||||
|
|
||||||
test('AnkiConnectClient disables keep-alive agents to avoid stale socket retries', () => {
|
|
||||||
const client = new AnkiConnectClient('http://127.0.0.1:8765') as unknown as {
|
|
||||||
client: {
|
|
||||||
defaults: {
|
|
||||||
httpAgent?: { options?: { keepAlive?: boolean } };
|
|
||||||
httpsAgent?: { options?: { keepAlive?: boolean } };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
assert.equal(client.client.defaults.httpAgent?.options?.keepAlive, false);
|
|
||||||
assert.equal(client.client.defaults.httpsAgent?.options?.keepAlive, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('AnkiConnectClient includes action name in retry logs', async () => {
|
test('AnkiConnectClient includes action name in retry logs', async () => {
|
||||||
const client = new AnkiConnectClient('http://127.0.0.1:8765') as unknown as {
|
const client = new AnkiConnectClient('http://127.0.0.1:8765') as unknown as {
|
||||||
client: { post: (url: string, body: unknown, options: unknown) => Promise<unknown> };
|
client: { post: (url: string, body: unknown, options: unknown) => Promise<unknown> };
|
||||||
|
|||||||
+547
-1170
File diff suppressed because it is too large.
Load diff
@@ -41,7 +41,6 @@ import type { NPlusOneMatchMode, SubtitleMiningContext } from './types/subtitle'
|
|||||||
import { DEFAULT_ANKI_CONNECT_CONFIG } from './config';
|
import { DEFAULT_ANKI_CONNECT_CONFIG } from './config';
|
||||||
import {
|
import {
|
||||||
getConfiguredWordFieldCandidates,
|
getConfiguredWordFieldCandidates,
|
||||||
getConfiguredWordFieldName,
|
|
||||||
getPreferredWordValueFromExtractedFields,
|
getPreferredWordValueFromExtractedFields,
|
||||||
} from './anki-field-config';
|
} from './anki-field-config';
|
||||||
import { createLogger } from './logger';
|
import { createLogger } from './logger';
|
||||||
@@ -1632,10 +1631,6 @@ export class AnkiIntegration {
|
|||||||
return sentenceCardConfig.audioField || 'SentenceAudio';
|
return sentenceCardConfig.audioField || 'SentenceAudio';
|
||||||
}
|
}
|
||||||
|
|
||||||
private getConfiguredWordFieldName(): string {
|
|
||||||
return getConfiguredWordFieldName(this.config);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getConfiguredWordFieldCandidates(): string[] {
|
private getConfiguredWordFieldCandidates(): string[] {
|
||||||
return getConfiguredWordFieldCandidates(this.config);
|
return getConfiguredWordFieldCandidates(this.config);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,13 @@ import assert from 'node:assert/strict';
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
|
|
||||||
import { CardCreationService } from './card-creation';
|
import { CardCreationService } from './card-creation';
|
||||||
import type { AnkiConnectConfig } from '../types/anki';
|
import {
|
||||||
|
type CardCreationDeps,
|
||||||
type CardCreationDeps = ConstructorParameters<typeof CardCreationService>[0];
|
createAnkiConfig,
|
||||||
|
createCardCreationDeps,
|
||||||
|
createFakeClient,
|
||||||
|
createFakeMediaGenerator,
|
||||||
|
} from './card-creation-test-utils';
|
||||||
|
|
||||||
test('sentence card writes generated audio only to sentence audio field', async () => {
|
test('sentence card writes generated audio only to sentence audio field', async () => {
|
||||||
const addedFields: Record<string, string>[] = [];
|
const addedFields: Record<string, string>[] = [];
|
||||||
@@ -13,28 +17,23 @@ test('sentence card writes generated audio only to sentence audio field', async
|
|||||||
const requestedProperties: string[] = [];
|
const requestedProperties: string[] = [];
|
||||||
const audioVolumeScales: Array<number | undefined> = [];
|
const audioVolumeScales: Array<number | undefined> = [];
|
||||||
const audioRanges: Array<{ start: number; end: number; padding: number | undefined }> = [];
|
const audioRanges: Array<{ start: number; end: number; padding: number | undefined }> = [];
|
||||||
|
let review: Awaited<ReturnType<NonNullable<CardCreationDeps['reviewMediaTiming']>>> = {
|
||||||
|
action: 'confirm',
|
||||||
|
startTime: 11.4,
|
||||||
|
endTime: 14.2,
|
||||||
|
};
|
||||||
|
|
||||||
const deps: CardCreationDeps = {
|
const service = new CardCreationService(
|
||||||
|
createCardCreationDeps({
|
||||||
getConfig: () =>
|
getConfig: () =>
|
||||||
({
|
createAnkiConfig({
|
||||||
deck: 'Mining',
|
|
||||||
fields: {
|
fields: {
|
||||||
word: 'Expression',
|
word: 'Expression',
|
||||||
sentence: 'Sentence',
|
|
||||||
audio: 'ExpressionAudio',
|
audio: 'ExpressionAudio',
|
||||||
translation: 'SelectionText',
|
translation: 'SelectionText',
|
||||||
},
|
},
|
||||||
media: {
|
media: { generateAudio: true, mirrorMpvVolume: true, maxMediaDuration: 30 },
|
||||||
generateAudio: true,
|
}),
|
||||||
generateImage: false,
|
|
||||||
mirrorMpvVolume: true,
|
|
||||||
maxMediaDuration: 30,
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
getMpvClient: () =>
|
||||||
({
|
({
|
||||||
currentVideoPath: '/video.mp4',
|
currentVideoPath: '/video.mp4',
|
||||||
@@ -48,12 +47,11 @@ test('sentence card writes generated audio only to sentence audio field', async
|
|||||||
return 40;
|
return 40;
|
||||||
},
|
},
|
||||||
}) as never,
|
}) as never,
|
||||||
client: {
|
client: createFakeClient({
|
||||||
addNote: async (_deck, _modelName, fields) => {
|
addNote: async (_deck, _modelName, fields) => {
|
||||||
addedFields.push(fields);
|
addedFields.push(fields);
|
||||||
return 42;
|
return 42;
|
||||||
},
|
},
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => [
|
notesInfo: async () => [
|
||||||
{
|
{
|
||||||
noteId: 42,
|
noteId: 42,
|
||||||
@@ -72,11 +70,8 @@ test('sentence card writes generated audio only to sentence audio field', async
|
|||||||
storeMediaFile: async (filename) => {
|
storeMediaFile: async (filename) => {
|
||||||
storedMedia.push(filename);
|
storedMedia.push(filename);
|
||||||
},
|
},
|
||||||
findNotes: async () => [],
|
}),
|
||||||
retrieveMediaFile: async () => '',
|
mediaGenerator: createFakeMediaGenerator({
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async (
|
generateAudio: async (
|
||||||
_path,
|
_path,
|
||||||
startTime,
|
startTime,
|
||||||
@@ -90,30 +85,7 @@ test('sentence card writes generated audio only to sentence audio field', async
|
|||||||
audioVolumeScales.push(volumeScale);
|
audioVolumeScales.push(volumeScale);
|
||||||
return Buffer.from('audio');
|
return Buffer.from('audio');
|
||||||
},
|
},
|
||||||
generateScreenshot: async () => null,
|
}),
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: (noteInfo, ...preferredNames) => {
|
|
||||||
for (const preferredName of preferredNames) {
|
|
||||||
if (preferredName && preferredName in noteInfo.fields) return preferredName;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
resolveNoteFieldName: (noteInfo, preferredName) =>
|
|
||||||
preferredName && preferredName in noteInfo.fields ? preferredName : null,
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: () => undefined,
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
getEffectiveSentenceCardConfig: () => ({
|
||||||
model: 'Sentence',
|
model: 'Sentence',
|
||||||
sentenceField: 'Sentence',
|
sentenceField: 'Sentence',
|
||||||
@@ -122,19 +94,11 @@ test('sentence card writes generated audio only to sentence audio field', async
|
|||||||
kikuEnabled: false,
|
kikuEnabled: false,
|
||||||
fieldGroupingMode: 'disabled',
|
fieldGroupingMode: 'disabled',
|
||||||
}),
|
}),
|
||||||
getFallbackDurationSeconds: () => 10,
|
reviewMediaTiming: async () => review,
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
}),
|
||||||
removeKnownWordNote: () => undefined,
|
);
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
trackLastAddedNoteId: () => undefined,
|
|
||||||
reviewMediaTiming: async () => ({ action: 'confirm', startTime: 11.4, endTime: 14.2 }),
|
|
||||||
};
|
|
||||||
|
|
||||||
const service = new CardCreationService(deps);
|
assert.equal(await service.createSentenceCard('字幕', 12, 14, 'Subtitle'), true);
|
||||||
const created = await service.createSentenceCard('字幕', 12, 14, 'Subtitle');
|
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.deepEqual(addedFields[0], {
|
assert.deepEqual(addedFields[0], {
|
||||||
Sentence: '字幕',
|
Sentence: '字幕',
|
||||||
SelectionText: 'Subtitle',
|
SelectionText: 'Subtitle',
|
||||||
@@ -149,11 +113,11 @@ test('sentence card writes generated audio only to sentence audio field', async
|
|||||||
assert.equal(mediaUpdate?.SentenceAudio, `[sound:${storedMedia[0]}]`);
|
assert.equal(mediaUpdate?.SentenceAudio, `[sound:${storedMedia[0]}]`);
|
||||||
assert.equal('ExpressionAudio' in mediaUpdate!, false);
|
assert.equal('ExpressionAudio' in mediaUpdate!, false);
|
||||||
|
|
||||||
deps.reviewMediaTiming = async () => ({ action: 'discard' });
|
review = { action: 'discard' };
|
||||||
assert.equal(await service.createSentenceCard('作らない', 20, 22), false);
|
assert.equal(await service.createSentenceCard('作らない', 20, 22), false);
|
||||||
assert.equal(addedFields.length, 1);
|
assert.equal(addedFields.length, 1);
|
||||||
|
|
||||||
deps.reviewMediaTiming = async () => ({ action: 'skip-media' });
|
review = { action: 'skip-media' };
|
||||||
assert.equal(await service.createSentenceCard('メディアなし', 30, 32), true);
|
assert.equal(await service.createSentenceCard('メディアなし', 30, 32), true);
|
||||||
assert.equal(addedFields.length, 2);
|
assert.equal(addedFields.length, 2);
|
||||||
assert.equal(storedMedia.length, 1);
|
assert.equal(storedMedia.length, 1);
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
import { CardCreationService } from './card-creation';
|
||||||
|
import type { AnkiConnectConfig } from '../types/anki';
|
||||||
|
|
||||||
|
export type CardCreationDeps = ConstructorParameters<typeof CardCreationService>[0];
|
||||||
|
|
||||||
|
/** Builds the minimal config the service reads; pass only the sections a test cares about. */
|
||||||
|
export function createAnkiConfig(
|
||||||
|
overrides: {
|
||||||
|
fields?: Record<string, string>;
|
||||||
|
media?: Record<string, unknown>;
|
||||||
|
} = {},
|
||||||
|
): AnkiConnectConfig {
|
||||||
|
return {
|
||||||
|
deck: 'Mining',
|
||||||
|
fields: { sentence: 'Sentence', audio: 'SentenceAudio', ...overrides.fields },
|
||||||
|
media: { generateAudio: false, generateImage: false, ...overrides.media },
|
||||||
|
behavior: {},
|
||||||
|
ai: false,
|
||||||
|
} as AnkiConnectConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake CardCreationService dependencies: a bare mpv session, a client that adds note 42, no media,
|
||||||
|
* and field resolvers that match exact field names. Override only what the test exercises.
|
||||||
|
*/
|
||||||
|
export function createCardCreationDeps(
|
||||||
|
overrides: Partial<CardCreationDeps> = {},
|
||||||
|
): CardCreationDeps {
|
||||||
|
return {
|
||||||
|
getConfig: () => createAnkiConfig(),
|
||||||
|
getAiConfig: () => ({}),
|
||||||
|
getTimingTracker: () => ({}) as never,
|
||||||
|
getMpvClient: () =>
|
||||||
|
({
|
||||||
|
currentVideoPath: '/video.mp4',
|
||||||
|
currentSubText: '字幕',
|
||||||
|
currentSubStart: 1,
|
||||||
|
currentSubEnd: 2,
|
||||||
|
currentTimePos: 1.5,
|
||||||
|
currentAudioStreamIndex: 0,
|
||||||
|
}) as never,
|
||||||
|
client: {
|
||||||
|
addNote: async () => 42,
|
||||||
|
addTags: async () => undefined,
|
||||||
|
notesInfo: async () => [],
|
||||||
|
updateNoteFields: async () => undefined,
|
||||||
|
storeMediaFile: async () => undefined,
|
||||||
|
findNotes: async () => [],
|
||||||
|
retrieveMediaFile: async () => '',
|
||||||
|
deleteNotes: async () => undefined,
|
||||||
|
},
|
||||||
|
mediaGenerator: {
|
||||||
|
generateAudio: async () => null,
|
||||||
|
generateScreenshot: async () => null,
|
||||||
|
generateAnimatedImage: async () => null,
|
||||||
|
},
|
||||||
|
showOsdNotification: () => undefined,
|
||||||
|
showUpdateResult: () => undefined,
|
||||||
|
showStatusNotification: () => undefined,
|
||||||
|
showNotification: async () => undefined,
|
||||||
|
beginUpdateProgress: () => undefined,
|
||||||
|
endUpdateProgress: () => undefined,
|
||||||
|
withUpdateProgress: async (_message, action) => action(),
|
||||||
|
resolveConfiguredFieldName: (noteInfo, ...preferredNames) => {
|
||||||
|
for (const preferredName of preferredNames) {
|
||||||
|
if (preferredName && preferredName in noteInfo.fields) return preferredName;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
resolveNoteFieldName: (noteInfo, preferredName) =>
|
||||||
|
preferredName && preferredName in noteInfo.fields ? preferredName : null,
|
||||||
|
getAnimatedImageLeadInSeconds: async () => 0,
|
||||||
|
extractFields: () => ({}),
|
||||||
|
processSentence: (sentence) => sentence,
|
||||||
|
setCardTypeFields: () => undefined,
|
||||||
|
mergeFieldValue: (_existing, newValue) => newValue,
|
||||||
|
formatMiscInfoPattern: () => '',
|
||||||
|
getEffectiveSentenceCardConfig: () => ({
|
||||||
|
model: 'Sentence',
|
||||||
|
sentenceField: 'Sentence',
|
||||||
|
audioField: 'SentenceAudio',
|
||||||
|
lapisEnabled: false,
|
||||||
|
kikuEnabled: false,
|
||||||
|
fieldGroupingMode: 'disabled',
|
||||||
|
}),
|
||||||
|
getFallbackDurationSeconds: () => 10,
|
||||||
|
appendKnownWordsFromNoteInfo: () => undefined,
|
||||||
|
removeKnownWordNote: () => undefined,
|
||||||
|
isUpdateInProgress: () => false,
|
||||||
|
setUpdateInProgress: () => undefined,
|
||||||
|
trackLastAddedNoteId: () => undefined,
|
||||||
|
...overrides,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Anki client overrides, kept separate so a test can swap one method without redeclaring the rest. */
|
||||||
|
export function createFakeClient(
|
||||||
|
overrides: Partial<CardCreationDeps['client']> = {},
|
||||||
|
): CardCreationDeps['client'] {
|
||||||
|
return { ...createCardCreationDeps().client, ...overrides };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createFakeMediaGenerator(
|
||||||
|
overrides: Partial<CardCreationDeps['mediaGenerator']> = {},
|
||||||
|
): CardCreationDeps['mediaGenerator'] {
|
||||||
|
return { ...createCardCreationDeps().mediaGenerator, ...overrides };
|
||||||
|
}
|
||||||
@@ -2,292 +2,83 @@ import assert from 'node:assert/strict';
|
|||||||
import test from 'node:test';
|
import test from 'node:test';
|
||||||
|
|
||||||
import { CardCreationService } from './card-creation';
|
import { CardCreationService } from './card-creation';
|
||||||
|
import {
|
||||||
|
type CardCreationDeps,
|
||||||
|
createAnkiConfig,
|
||||||
|
createCardCreationDeps,
|
||||||
|
createFakeClient,
|
||||||
|
createFakeMediaGenerator,
|
||||||
|
} from './card-creation-test-utils';
|
||||||
import { toMpvEdlValue } from './mpv-edl-test-utils';
|
import { toMpvEdlValue } from './mpv-edl-test-utils';
|
||||||
import type { MediaInput } from '../media-generator';
|
import type { MediaInput } from '../media-generator';
|
||||||
import type { AnkiConnectConfig } from '../types/anki';
|
|
||||||
|
const YOUTUBE_URL = 'https://www.youtube.com/watch?v=abc123';
|
||||||
|
|
||||||
|
const mediaInputPath = (mediaInput: MediaInput): string =>
|
||||||
|
typeof mediaInput === 'string' ? mediaInput : mediaInput.path;
|
||||||
|
|
||||||
test('CardCreationService counts locally created sentence cards', async () => {
|
test('CardCreationService counts locally created sentence cards', async () => {
|
||||||
const minedCards: Array<{ count: number; noteIds?: number[] }> = [];
|
const minedCards: Array<{ count: number; noteIds?: number[] }> = [];
|
||||||
const service = new CardCreationService({
|
const service = new CardCreationService(
|
||||||
getConfig: () =>
|
createCardCreationDeps({
|
||||||
({
|
|
||||||
deck: 'Mining',
|
|
||||||
fields: {
|
|
||||||
sentence: 'Sentence',
|
|
||||||
audio: 'SentenceAudio',
|
|
||||||
},
|
|
||||||
media: {
|
|
||||||
generateAudio: false,
|
|
||||||
generateImage: false,
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
|
||||||
({
|
|
||||||
currentVideoPath: '/video.mp4',
|
|
||||||
currentSubText: '字幕',
|
|
||||||
currentSubStart: 1,
|
|
||||||
currentSubEnd: 2,
|
|
||||||
currentTimePos: 1.5,
|
|
||||||
currentAudioStreamIndex: 0,
|
|
||||||
}) as never,
|
|
||||||
client: {
|
|
||||||
addNote: async () => 42,
|
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => [],
|
|
||||||
updateNoteFields: async () => undefined,
|
|
||||||
storeMediaFile: async () => undefined,
|
|
||||||
findNotes: async () => [],
|
|
||||||
retrieveMediaFile: async () => '',
|
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async () => null,
|
|
||||||
generateScreenshot: async () => null,
|
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: () => null,
|
|
||||||
resolveNoteFieldName: () => null,
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: () => undefined,
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
|
||||||
model: 'Sentence',
|
|
||||||
sentenceField: 'Sentence',
|
|
||||||
audioField: 'SentenceAudio',
|
|
||||||
lapisEnabled: false,
|
|
||||||
kikuEnabled: false,
|
|
||||||
fieldGroupingMode: 'disabled',
|
|
||||||
}),
|
|
||||||
getFallbackDurationSeconds: () => 10,
|
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
|
||||||
removeKnownWordNote: () => undefined,
|
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
trackLastAddedNoteId: () => undefined,
|
|
||||||
recordCardsMinedCallback: (count, noteIds) => {
|
recordCardsMinedCallback: (count, noteIds) => {
|
||||||
minedCards.push({ count, noteIds });
|
minedCards.push({ count, noteIds });
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const created = await service.createSentenceCard('テスト', 0, 1);
|
assert.equal(await service.createSentenceCard('テスト', 0, 1), true);
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.deepEqual(minedCards, [{ count: 1, noteIds: [42] }]);
|
assert.deepEqual(minedCards, [{ count: 1, noteIds: [42] }]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('CardCreationService keeps updating after trackLastAddedNoteId throws', async () => {
|
const THROWING_HOOKS: Array<{
|
||||||
const calls = {
|
name: string;
|
||||||
notesInfo: 0,
|
hook: Partial<CardCreationDeps>;
|
||||||
updateNoteFields: 0,
|
}> = [
|
||||||
};
|
|
||||||
const service = new CardCreationService({
|
|
||||||
getConfig: () =>
|
|
||||||
({
|
|
||||||
deck: 'Mining',
|
|
||||||
fields: {
|
|
||||||
sentence: 'Sentence',
|
|
||||||
audio: 'SentenceAudio',
|
|
||||||
},
|
|
||||||
media: {
|
|
||||||
generateAudio: false,
|
|
||||||
generateImage: false,
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
|
||||||
({
|
|
||||||
currentVideoPath: '/video.mp4',
|
|
||||||
currentSubText: '字幕',
|
|
||||||
currentSubStart: 1,
|
|
||||||
currentSubEnd: 2,
|
|
||||||
currentTimePos: 1.5,
|
|
||||||
currentAudioStreamIndex: 0,
|
|
||||||
}) as never,
|
|
||||||
client: {
|
|
||||||
addNote: async () => 42,
|
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => {
|
|
||||||
calls.notesInfo += 1;
|
|
||||||
return [
|
|
||||||
{
|
{
|
||||||
noteId: 42,
|
name: 'trackLastAddedNoteId',
|
||||||
fields: {
|
hook: {
|
||||||
Sentence: { value: 'existing' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
updateNoteFields: async () => {
|
|
||||||
calls.updateNoteFields += 1;
|
|
||||||
},
|
|
||||||
storeMediaFile: async () => undefined,
|
|
||||||
findNotes: async () => [],
|
|
||||||
retrieveMediaFile: async () => '',
|
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async () => null,
|
|
||||||
generateScreenshot: async () => null,
|
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: () => null,
|
|
||||||
resolveNoteFieldName: () => null,
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: (updatedFields) => {
|
|
||||||
updatedFields.CardType = 'sentence';
|
|
||||||
},
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
|
||||||
model: 'Sentence',
|
|
||||||
sentenceField: 'Sentence',
|
|
||||||
audioField: 'SentenceAudio',
|
|
||||||
lapisEnabled: false,
|
|
||||||
kikuEnabled: false,
|
|
||||||
fieldGroupingMode: 'disabled',
|
|
||||||
}),
|
|
||||||
getFallbackDurationSeconds: () => 10,
|
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
|
||||||
removeKnownWordNote: () => undefined,
|
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
trackLastAddedNoteId: () => {
|
trackLastAddedNoteId: () => {
|
||||||
throw new Error('track failed');
|
throw new Error('track failed');
|
||||||
},
|
},
|
||||||
});
|
|
||||||
|
|
||||||
const created = await service.createSentenceCard('テスト', 0, 1);
|
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.equal(calls.notesInfo, 1);
|
|
||||||
assert.equal(calls.updateNoteFields, 1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('CardCreationService keeps updating after recordCardsMinedCallback throws', async () => {
|
|
||||||
const calls = {
|
|
||||||
notesInfo: 0,
|
|
||||||
updateNoteFields: 0,
|
|
||||||
};
|
|
||||||
const service = new CardCreationService({
|
|
||||||
getConfig: () =>
|
|
||||||
({
|
|
||||||
deck: 'Mining',
|
|
||||||
fields: {
|
|
||||||
sentence: 'Sentence',
|
|
||||||
audio: 'SentenceAudio',
|
|
||||||
},
|
},
|
||||||
media: {
|
|
||||||
generateAudio: false,
|
|
||||||
generateImage: false,
|
|
||||||
},
|
},
|
||||||
behavior: {},
|
{
|
||||||
ai: false,
|
name: 'recordCardsMinedCallback',
|
||||||
}) as AnkiConnectConfig,
|
hook: {
|
||||||
getAiConfig: () => ({}),
|
recordCardsMinedCallback: () => {
|
||||||
getTimingTracker: () => ({}) as never,
|
throw new Error('record failed');
|
||||||
getMpvClient: () =>
|
},
|
||||||
({
|
},
|
||||||
currentVideoPath: '/video.mp4',
|
},
|
||||||
currentSubText: '字幕',
|
];
|
||||||
currentSubStart: 1,
|
|
||||||
currentSubEnd: 2,
|
for (const c of THROWING_HOOKS) {
|
||||||
currentTimePos: 1.5,
|
test(`CardCreationService keeps updating after ${c.name} throws`, async () => {
|
||||||
currentAudioStreamIndex: 0,
|
const calls = { notesInfo: 0, updateNoteFields: 0 };
|
||||||
}) as never,
|
const service = new CardCreationService(
|
||||||
client: {
|
createCardCreationDeps({
|
||||||
addNote: async () => 42,
|
client: createFakeClient({
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => {
|
notesInfo: async () => {
|
||||||
calls.notesInfo += 1;
|
calls.notesInfo += 1;
|
||||||
return [
|
return [{ noteId: 42, fields: { Sentence: { value: 'existing' } } }];
|
||||||
{
|
|
||||||
noteId: 42,
|
|
||||||
fields: {
|
|
||||||
Sentence: { value: 'existing' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
},
|
||||||
updateNoteFields: async () => {
|
updateNoteFields: async () => {
|
||||||
calls.updateNoteFields += 1;
|
calls.updateNoteFields += 1;
|
||||||
},
|
},
|
||||||
storeMediaFile: async () => undefined,
|
}),
|
||||||
findNotes: async () => [],
|
|
||||||
retrieveMediaFile: async () => '',
|
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async () => null,
|
|
||||||
generateScreenshot: async () => null,
|
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: () => null,
|
|
||||||
resolveNoteFieldName: () => null,
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: (updatedFields) => {
|
setCardTypeFields: (updatedFields) => {
|
||||||
updatedFields.CardType = 'sentence';
|
updatedFields.CardType = 'sentence';
|
||||||
},
|
},
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
...c.hook,
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
|
||||||
model: 'Sentence',
|
|
||||||
sentenceField: 'Sentence',
|
|
||||||
audioField: 'SentenceAudio',
|
|
||||||
lapisEnabled: false,
|
|
||||||
kikuEnabled: false,
|
|
||||||
fieldGroupingMode: 'disabled',
|
|
||||||
}),
|
}),
|
||||||
getFallbackDurationSeconds: () => 10,
|
);
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
|
||||||
removeKnownWordNote: () => undefined,
|
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
recordCardsMinedCallback: () => {
|
|
||||||
throw new Error('record failed');
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const created = await service.createSentenceCard('テスト', 0, 1);
|
assert.equal(await service.createSentenceCard('テスト', 0, 1), true);
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.equal(calls.notesInfo, 1);
|
assert.equal(calls.notesInfo, 1);
|
||||||
assert.equal(calls.updateNoteFields, 1);
|
assert.equal(calls.updateNoteFields, 1);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
test('CardCreationService uses stream-open-filename for remote media generation', async () => {
|
test('CardCreationService uses stream-open-filename for remote media generation', async () => {
|
||||||
let reviewing = false;
|
let reviewing = false;
|
||||||
@@ -295,8 +86,6 @@ test('CardCreationService uses stream-open-filename for remote media generation'
|
|||||||
const imageTimes: number[] = [];
|
const imageTimes: number[] = [];
|
||||||
const audioPaths: string[] = [];
|
const audioPaths: string[] = [];
|
||||||
const imagePaths: string[] = [];
|
const imagePaths: string[] = [];
|
||||||
const recordMediaPath = (mediaInput: MediaInput): string =>
|
|
||||||
typeof mediaInput === 'string' ? mediaInput : mediaInput.path;
|
|
||||||
const audioUrl = 'https://audio.example/videoplayback?mime=audio%2Fwebm';
|
const audioUrl = 'https://audio.example/videoplayback?mime=audio%2Fwebm';
|
||||||
const videoUrl = 'https://video.example/videoplayback?mime=video%2Fmp4';
|
const videoUrl = 'https://video.example/videoplayback?mime=video%2Fmp4';
|
||||||
const edlSource = [
|
const edlSource = [
|
||||||
@@ -305,32 +94,20 @@ test('CardCreationService uses stream-open-filename for remote media generation'
|
|||||||
'!global_tags,title=test',
|
'!global_tags,title=test',
|
||||||
].join(';');
|
].join(';');
|
||||||
|
|
||||||
const service = new CardCreationService({
|
const service = new CardCreationService(
|
||||||
|
createCardCreationDeps({
|
||||||
getConfig: () =>
|
getConfig: () =>
|
||||||
({
|
createAnkiConfig({
|
||||||
deck: 'Mining',
|
fields: { image: 'Picture' },
|
||||||
fields: {
|
media: { generateAudio: true, generateImage: true, imageFormat: 'jpg' },
|
||||||
sentence: 'Sentence',
|
}),
|
||||||
audio: 'SentenceAudio',
|
|
||||||
image: 'Picture',
|
|
||||||
},
|
|
||||||
media: {
|
|
||||||
generateAudio: true,
|
|
||||||
generateImage: true,
|
|
||||||
imageFormat: 'jpg',
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
reviewMediaTiming: async () =>
|
reviewMediaTiming: async () =>
|
||||||
reviewing
|
reviewing
|
||||||
? { action: 'confirm', startTime: 0.2, endTime: 0.8, screenshotTime: 3.125 }
|
? { action: 'confirm', startTime: 0.2, endTime: 0.8, screenshotTime: 3.125 }
|
||||||
: { action: 'use-original' },
|
: { action: 'use-original' },
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
getMpvClient: () =>
|
||||||
({
|
({
|
||||||
currentVideoPath: 'https://www.youtube.com/watch?v=abc123',
|
currentVideoPath: YOUTUBE_URL,
|
||||||
currentSubText: '字幕',
|
currentSubText: '字幕',
|
||||||
currentSubStart: 1,
|
currentSubStart: 1,
|
||||||
currentSubEnd: 2,
|
currentSubEnd: 2,
|
||||||
@@ -341,9 +118,7 @@ test('CardCreationService uses stream-open-filename for remote media generation'
|
|||||||
return edlSource;
|
return edlSource;
|
||||||
},
|
},
|
||||||
}) as never,
|
}) as never,
|
||||||
client: {
|
client: createFakeClient({
|
||||||
addNote: async () => 42,
|
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => [
|
notesInfo: async () => [
|
||||||
{
|
{
|
||||||
noteId: 42,
|
noteId: 42,
|
||||||
@@ -354,71 +129,32 @@ test('CardCreationService uses stream-open-filename for remote media generation'
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
updateNoteFields: async () => undefined,
|
|
||||||
storeMediaFile: async () => undefined,
|
|
||||||
findNotes: async () => [42],
|
findNotes: async () => [42],
|
||||||
retrieveMediaFile: async () => '',
|
}),
|
||||||
deleteNotes: async () => undefined,
|
mediaGenerator: createFakeMediaGenerator({
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async (path, start, end, padding) => {
|
generateAudio: async (path, start, end, padding) => {
|
||||||
audioRanges.push([start, end, padding ?? -1]);
|
audioRanges.push([start, end, padding ?? -1]);
|
||||||
audioPaths.push(recordMediaPath(path));
|
audioPaths.push(mediaInputPath(path));
|
||||||
return Buffer.from('audio');
|
return Buffer.from('audio');
|
||||||
},
|
},
|
||||||
generateScreenshot: async (path, timestamp) => {
|
generateScreenshot: async (path, timestamp) => {
|
||||||
imageTimes.push(timestamp);
|
imageTimes.push(timestamp);
|
||||||
imagePaths.push(recordMediaPath(path));
|
imagePaths.push(mediaInputPath(path));
|
||||||
return Buffer.from('image');
|
return Buffer.from('image');
|
||||||
},
|
},
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: (noteInfo, preferredName) => {
|
|
||||||
if (!preferredName) return null;
|
|
||||||
return Object.keys(noteInfo.fields).find((field) => field === preferredName) ?? null;
|
|
||||||
},
|
|
||||||
resolveNoteFieldName: (noteInfo, preferredName) => {
|
|
||||||
if (!preferredName) return null;
|
|
||||||
return Object.keys(noteInfo.fields).find((field) => field === preferredName) ?? null;
|
|
||||||
},
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: () => undefined,
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
|
||||||
model: 'Sentence',
|
|
||||||
sentenceField: 'Sentence',
|
|
||||||
audioField: 'SentenceAudio',
|
|
||||||
lapisEnabled: false,
|
|
||||||
kikuEnabled: false,
|
|
||||||
fieldGroupingMode: 'disabled',
|
|
||||||
}),
|
}),
|
||||||
getFallbackDurationSeconds: () => 10,
|
}),
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
);
|
||||||
removeKnownWordNote: () => undefined,
|
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
trackLastAddedNoteId: () => undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
const created = await service.createSentenceCard('テスト', 0, 1);
|
assert.equal(await service.createSentenceCard('テスト', 0, 1), true);
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.deepEqual(audioPaths, [audioUrl]);
|
assert.deepEqual(audioPaths, [audioUrl]);
|
||||||
assert.deepEqual(imagePaths, [videoUrl]);
|
assert.deepEqual(imagePaths, [videoUrl]);
|
||||||
|
|
||||||
reviewing = true;
|
reviewing = true;
|
||||||
assert.equal(await service.createSentenceCard('テスト', 0, 1), true);
|
assert.equal(await service.createSentenceCard('テスト', 0, 1), true);
|
||||||
assert.deepEqual(audioRanges.at(-1), [0.2, 0.8, 0]);
|
assert.deepEqual(audioRanges.at(-1), [0.2, 0.8, 0]);
|
||||||
assert.equal(imageTimes.at(-1), 3.125);
|
assert.equal(imageTimes.at(-1), 3.125);
|
||||||
|
|
||||||
await service.markLastCardAsAudioCard();
|
await service.markLastCardAsAudioCard();
|
||||||
assert.equal(imageTimes.length, 3);
|
assert.equal(imageTimes.length, 3);
|
||||||
assert.deepEqual(audioRanges.at(-1), [0.2, 0.8, 0]);
|
assert.deepEqual(audioRanges.at(-1), [0.2, 0.8, 0]);
|
||||||
@@ -428,28 +164,16 @@ test('CardCreationService uses stream-open-filename for remote media generation'
|
|||||||
test('CardCreationService does not use mpv stream indexes for ready cached YouTube media', async () => {
|
test('CardCreationService does not use mpv stream indexes for ready cached YouTube media', async () => {
|
||||||
const audioCalls: Array<{ path: string; audioStreamIndex?: number }> = [];
|
const audioCalls: Array<{ path: string; audioStreamIndex?: number }> = [];
|
||||||
|
|
||||||
const service = new CardCreationService({
|
const service = new CardCreationService(
|
||||||
|
createCardCreationDeps({
|
||||||
getConfig: () =>
|
getConfig: () =>
|
||||||
({
|
createAnkiConfig({
|
||||||
deck: 'Mining',
|
fields: { image: 'Picture' },
|
||||||
fields: {
|
media: { generateAudio: true, imageFormat: 'jpg' },
|
||||||
sentence: 'Sentence',
|
}),
|
||||||
audio: 'SentenceAudio',
|
|
||||||
image: 'Picture',
|
|
||||||
},
|
|
||||||
media: {
|
|
||||||
generateAudio: true,
|
|
||||||
generateImage: false,
|
|
||||||
imageFormat: 'jpg',
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
getMpvClient: () =>
|
||||||
({
|
({
|
||||||
currentVideoPath: 'https://www.youtube.com/watch?v=abc123',
|
currentVideoPath: YOUTUBE_URL,
|
||||||
currentSubText: '字幕',
|
currentSubText: '字幕',
|
||||||
currentSubStart: 10,
|
currentSubStart: 10,
|
||||||
currentSubEnd: 12,
|
currentSubEnd: 12,
|
||||||
@@ -458,9 +182,7 @@ test('CardCreationService does not use mpv stream indexes for ready cached YouTu
|
|||||||
}) as never,
|
}) as never,
|
||||||
getCachedMediaPath: async () => '/tmp/subminer-youtube-media-cache/media.mkv',
|
getCachedMediaPath: async () => '/tmp/subminer-youtube-media-cache/media.mkv',
|
||||||
shouldRequireRemoteMediaCache: () => true,
|
shouldRequireRemoteMediaCache: () => true,
|
||||||
client: {
|
client: createFakeClient({
|
||||||
addNote: async () => 42,
|
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => [
|
notesInfo: async () => [
|
||||||
{
|
{
|
||||||
noteId: 42,
|
noteId: 42,
|
||||||
@@ -471,65 +193,19 @@ test('CardCreationService does not use mpv stream indexes for ready cached YouTu
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
updateNoteFields: async () => undefined,
|
}),
|
||||||
storeMediaFile: async () => undefined,
|
mediaGenerator: createFakeMediaGenerator({
|
||||||
findNotes: async () => [],
|
|
||||||
retrieveMediaFile: async () => '',
|
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async (path, _startTime, _endTime, _padding, audioStreamIndex) => {
|
generateAudio: async (path, _startTime, _endTime, _padding, audioStreamIndex) => {
|
||||||
audioCalls.push({ path: typeof path === 'string' ? path : path.path, audioStreamIndex });
|
audioCalls.push({ path: mediaInputPath(path), audioStreamIndex });
|
||||||
return Buffer.from('audio');
|
return Buffer.from('audio');
|
||||||
},
|
},
|
||||||
generateScreenshot: async () => null,
|
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: (noteInfo, preferredName) => {
|
|
||||||
if (!preferredName) return null;
|
|
||||||
return Object.keys(noteInfo.fields).find((field) => field === preferredName) ?? null;
|
|
||||||
},
|
|
||||||
resolveNoteFieldName: (noteInfo, preferredName) => {
|
|
||||||
if (!preferredName) return null;
|
|
||||||
return Object.keys(noteInfo.fields).find((field) => field === preferredName) ?? null;
|
|
||||||
},
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: () => undefined,
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
|
||||||
model: 'Sentence',
|
|
||||||
sentenceField: 'Sentence',
|
|
||||||
audioField: 'SentenceAudio',
|
|
||||||
lapisEnabled: false,
|
|
||||||
kikuEnabled: false,
|
|
||||||
fieldGroupingMode: 'disabled',
|
|
||||||
}),
|
}),
|
||||||
getFallbackDurationSeconds: () => 10,
|
}),
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
);
|
||||||
removeKnownWordNote: () => undefined,
|
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
trackLastAddedNoteId: () => undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
const created = await service.createSentenceCard('テスト', 10, 12);
|
assert.equal(await service.createSentenceCard('テスト', 10, 12), true);
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.deepEqual(audioCalls, [
|
assert.deepEqual(audioCalls, [
|
||||||
{
|
{ path: '/tmp/subminer-youtube-media-cache/media.mkv', audioStreamIndex: undefined },
|
||||||
path: '/tmp/subminer-youtube-media-cache/media.mkv',
|
|
||||||
audioStreamIndex: undefined,
|
|
||||||
},
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -551,38 +227,23 @@ test('CardCreationService queues YouTube media when required cache is not ready'
|
|||||||
}> = [];
|
}> = [];
|
||||||
let streamRequests = 0;
|
let streamRequests = 0;
|
||||||
|
|
||||||
const service = new CardCreationService({
|
const service = new CardCreationService(
|
||||||
|
createCardCreationDeps({
|
||||||
getConfig: () =>
|
getConfig: () =>
|
||||||
({
|
createAnkiConfig({
|
||||||
deck: 'Mining',
|
fields: { image: 'Picture', miscInfo: 'MiscInfo' },
|
||||||
fields: {
|
media: { generateAudio: true, generateImage: true, imageFormat: 'jpg' },
|
||||||
sentence: 'Sentence',
|
}),
|
||||||
audio: 'SentenceAudio',
|
|
||||||
image: 'Picture',
|
|
||||||
miscInfo: 'MiscInfo',
|
|
||||||
},
|
|
||||||
media: {
|
|
||||||
generateAudio: true,
|
|
||||||
generateImage: true,
|
|
||||||
imageFormat: 'jpg',
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
getMpvClient: () =>
|
||||||
({
|
({
|
||||||
currentVideoPath: 'https://www.youtube.com/watch?v=abc123',
|
currentVideoPath: YOUTUBE_URL,
|
||||||
currentSubText: '字幕',
|
currentSubText: '字幕',
|
||||||
currentSubStart: 10,
|
currentSubStart: 10,
|
||||||
currentSubEnd: 12,
|
currentSubEnd: 12,
|
||||||
currentTimePos: 11,
|
currentTimePos: 11,
|
||||||
currentAudioStreamIndex: 2,
|
currentAudioStreamIndex: 2,
|
||||||
requestProperty: async (name: string) => {
|
requestProperty: async (name: string) => {
|
||||||
if (name === 'volume') {
|
if (name === 'volume') return 35;
|
||||||
return 35;
|
|
||||||
}
|
|
||||||
streamRequests += 1;
|
streamRequests += 1;
|
||||||
return 'https://rr1---sn.example.googlevideo.com/videoplayback?id=123';
|
return 'https://rr1---sn.example.googlevideo.com/videoplayback?id=123';
|
||||||
},
|
},
|
||||||
@@ -592,9 +253,7 @@ test('CardCreationService queues YouTube media when required cache is not ready'
|
|||||||
queuePendingYoutubeMediaUpdate: (job) => {
|
queuePendingYoutubeMediaUpdate: (job) => {
|
||||||
queuedUpdates.push(job);
|
queuedUpdates.push(job);
|
||||||
},
|
},
|
||||||
client: {
|
client: createFakeClient({
|
||||||
addNote: async () => 42,
|
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => [
|
notesInfo: async () => [
|
||||||
{
|
{
|
||||||
noteId: 42,
|
noteId: 42,
|
||||||
@@ -609,12 +268,8 @@ test('CardCreationService queues YouTube media when required cache is not ready'
|
|||||||
updateNoteFields: async (noteId, fields) => {
|
updateNoteFields: async (noteId, fields) => {
|
||||||
updates.push({ noteId, fields });
|
updates.push({ noteId, fields });
|
||||||
},
|
},
|
||||||
storeMediaFile: async () => undefined,
|
}),
|
||||||
findNotes: async () => [],
|
mediaGenerator: createFakeMediaGenerator({
|
||||||
retrieveMediaFile: async () => '',
|
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async () => {
|
generateAudio: async () => {
|
||||||
mediaCalls.push('audio');
|
mediaCalls.push('audio');
|
||||||
return Buffer.from('audio');
|
return Buffer.from('audio');
|
||||||
@@ -623,53 +278,16 @@ test('CardCreationService queues YouTube media when required cache is not ready'
|
|||||||
mediaCalls.push('image');
|
mediaCalls.push('image');
|
||||||
return Buffer.from('image');
|
return Buffer.from('image');
|
||||||
},
|
},
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: (noteInfo, preferredName) => {
|
|
||||||
if (!preferredName) return null;
|
|
||||||
return Object.keys(noteInfo.fields).find((field) => field === preferredName) ?? null;
|
|
||||||
},
|
|
||||||
resolveNoteFieldName: (noteInfo, preferredName) => {
|
|
||||||
if (!preferredName) return null;
|
|
||||||
return Object.keys(noteInfo.fields).find((field) => field === preferredName) ?? null;
|
|
||||||
},
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: () => undefined,
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
|
||||||
model: 'Sentence',
|
|
||||||
sentenceField: 'Sentence',
|
|
||||||
audioField: 'SentenceAudio',
|
|
||||||
lapisEnabled: false,
|
|
||||||
kikuEnabled: false,
|
|
||||||
fieldGroupingMode: 'disabled',
|
|
||||||
}),
|
}),
|
||||||
getFallbackDurationSeconds: () => 10,
|
}),
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
);
|
||||||
removeKnownWordNote: () => undefined,
|
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
trackLastAddedNoteId: () => undefined,
|
|
||||||
});
|
|
||||||
|
|
||||||
const created = await service.createSentenceCard('テスト', 10, 12);
|
assert.equal(await service.createSentenceCard('テスト', 10, 12), true);
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.equal(streamRequests, 0);
|
assert.equal(streamRequests, 0);
|
||||||
assert.deepEqual(mediaCalls, []);
|
assert.deepEqual(mediaCalls, []);
|
||||||
assert.deepEqual(queuedUpdates, [
|
assert.deepEqual(queuedUpdates, [
|
||||||
{
|
{
|
||||||
sourceUrl: 'https://www.youtube.com/watch?v=abc123',
|
sourceUrl: YOUTUBE_URL,
|
||||||
noteId: 42,
|
noteId: 42,
|
||||||
startTime: 10,
|
startTime: 10,
|
||||||
endTime: 12,
|
endTime: 12,
|
||||||
@@ -685,67 +303,28 @@ test('CardCreationService queues YouTube media when required cache is not ready'
|
|||||||
assert.deepEqual(updates, []);
|
assert.deepEqual(updates, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('CardCreationService tracks pre-add duplicate note ids for kiku sentence cards', async () => {
|
const DUPLICATE_TRACKING_CASES = [
|
||||||
const trackedDuplicates: Array<{ noteId: number; duplicateNoteIds: number[] }> = [];
|
{
|
||||||
const duplicateLookupExpressions: string[] = [];
|
name: 'tracks sorted, deduplicated pre-add duplicate note ids for kiku sentence cards',
|
||||||
|
sentence: '重複文',
|
||||||
|
lookupResult: [18, 7, 30, 7],
|
||||||
|
expected: [{ noteId: 42, duplicateNoteIds: [7, 18, 30] }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'does not track duplicate ids when pre-add lookup returns none',
|
||||||
|
sentence: '重複なし',
|
||||||
|
lookupResult: [],
|
||||||
|
expected: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const service = new CardCreationService({
|
for (const c of DUPLICATE_TRACKING_CASES) {
|
||||||
getConfig: () =>
|
test(`CardCreationService ${c.name}`, async () => {
|
||||||
({
|
const trackedDuplicates: Array<{ noteId: number; duplicateNoteIds: number[] }> = [];
|
||||||
deck: 'Mining',
|
const lookedUp: string[] = [];
|
||||||
fields: {
|
const service = new CardCreationService(
|
||||||
word: 'Expression',
|
createCardCreationDeps({
|
||||||
sentence: 'Sentence',
|
getConfig: () => createAnkiConfig({ fields: { word: 'Expression' } }),
|
||||||
audio: 'SentenceAudio',
|
|
||||||
},
|
|
||||||
media: {
|
|
||||||
generateAudio: false,
|
|
||||||
generateImage: false,
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
|
||||||
({
|
|
||||||
currentVideoPath: '/video.mp4',
|
|
||||||
currentSubText: '字幕',
|
|
||||||
currentSubStart: 1,
|
|
||||||
currentSubEnd: 2,
|
|
||||||
currentTimePos: 1.5,
|
|
||||||
currentAudioStreamIndex: 0,
|
|
||||||
}) as never,
|
|
||||||
client: {
|
|
||||||
addNote: async () => 42,
|
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => [],
|
|
||||||
updateNoteFields: async () => undefined,
|
|
||||||
storeMediaFile: async () => undefined,
|
|
||||||
findNotes: async () => [],
|
|
||||||
retrieveMediaFile: async () => '',
|
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async () => null,
|
|
||||||
generateScreenshot: async () => null,
|
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: () => null,
|
|
||||||
resolveNoteFieldName: () => null,
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: () => undefined,
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
getEffectiveSentenceCardConfig: () => ({
|
||||||
model: 'Sentence',
|
model: 'Sentence',
|
||||||
sentenceField: 'Sentence',
|
sentenceField: 'Sentence',
|
||||||
@@ -754,110 +333,18 @@ test('CardCreationService tracks pre-add duplicate note ids for kiku sentence ca
|
|||||||
kikuEnabled: true,
|
kikuEnabled: true,
|
||||||
fieldGroupingMode: 'manual',
|
fieldGroupingMode: 'manual',
|
||||||
}),
|
}),
|
||||||
getFallbackDurationSeconds: () => 10,
|
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
|
||||||
removeKnownWordNote: () => undefined,
|
|
||||||
isUpdateInProgress: () => false,
|
|
||||||
setUpdateInProgress: () => undefined,
|
|
||||||
trackLastAddedNoteId: () => undefined,
|
|
||||||
findDuplicateNoteIds: async (expression) => {
|
findDuplicateNoteIds: async (expression) => {
|
||||||
duplicateLookupExpressions.push(expression);
|
lookedUp.push(expression);
|
||||||
return [18, 7, 30, 7];
|
return c.lookupResult;
|
||||||
},
|
},
|
||||||
trackLastAddedDuplicateNoteIds: (noteId, duplicateNoteIds) => {
|
trackLastAddedDuplicateNoteIds: (noteId, duplicateNoteIds) => {
|
||||||
trackedDuplicates.push({ noteId, duplicateNoteIds });
|
trackedDuplicates.push({ noteId, duplicateNoteIds });
|
||||||
},
|
},
|
||||||
});
|
|
||||||
|
|
||||||
const created = await service.createSentenceCard('重複文', 0, 1);
|
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.deepEqual(duplicateLookupExpressions, ['重複文']);
|
|
||||||
assert.deepEqual(trackedDuplicates, [{ noteId: 42, duplicateNoteIds: [7, 18, 30] }]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('CardCreationService does not track duplicate ids when pre-add lookup returns none', async () => {
|
|
||||||
const trackedDuplicates: Array<{ noteId: number; duplicateNoteIds: number[] }> = [];
|
|
||||||
|
|
||||||
const service = new CardCreationService({
|
|
||||||
getConfig: () =>
|
|
||||||
({
|
|
||||||
deck: 'Mining',
|
|
||||||
fields: {
|
|
||||||
word: 'Expression',
|
|
||||||
sentence: 'Sentence',
|
|
||||||
audio: 'SentenceAudio',
|
|
||||||
},
|
|
||||||
media: {
|
|
||||||
generateAudio: false,
|
|
||||||
generateImage: false,
|
|
||||||
},
|
|
||||||
behavior: {},
|
|
||||||
ai: false,
|
|
||||||
}) as AnkiConnectConfig,
|
|
||||||
getAiConfig: () => ({}),
|
|
||||||
getTimingTracker: () => ({}) as never,
|
|
||||||
getMpvClient: () =>
|
|
||||||
({
|
|
||||||
currentVideoPath: '/video.mp4',
|
|
||||||
currentSubText: '字幕',
|
|
||||||
currentSubStart: 1,
|
|
||||||
currentSubEnd: 2,
|
|
||||||
currentTimePos: 1.5,
|
|
||||||
currentAudioStreamIndex: 0,
|
|
||||||
}) as never,
|
|
||||||
client: {
|
|
||||||
addNote: async () => 42,
|
|
||||||
addTags: async () => undefined,
|
|
||||||
notesInfo: async () => [],
|
|
||||||
updateNoteFields: async () => undefined,
|
|
||||||
storeMediaFile: async () => undefined,
|
|
||||||
findNotes: async () => [],
|
|
||||||
retrieveMediaFile: async () => '',
|
|
||||||
deleteNotes: async () => undefined,
|
|
||||||
},
|
|
||||||
mediaGenerator: {
|
|
||||||
generateAudio: async () => null,
|
|
||||||
generateScreenshot: async () => null,
|
|
||||||
generateAnimatedImage: async () => null,
|
|
||||||
},
|
|
||||||
showOsdNotification: () => undefined,
|
|
||||||
showUpdateResult: () => undefined,
|
|
||||||
showStatusNotification: () => undefined,
|
|
||||||
showNotification: async () => undefined,
|
|
||||||
beginUpdateProgress: () => undefined,
|
|
||||||
endUpdateProgress: () => undefined,
|
|
||||||
withUpdateProgress: async (_message, action) => action(),
|
|
||||||
resolveConfiguredFieldName: () => null,
|
|
||||||
resolveNoteFieldName: () => null,
|
|
||||||
getAnimatedImageLeadInSeconds: async () => 0,
|
|
||||||
extractFields: () => ({}),
|
|
||||||
processSentence: (sentence) => sentence,
|
|
||||||
setCardTypeFields: () => undefined,
|
|
||||||
mergeFieldValue: (_existing, newValue) => newValue,
|
|
||||||
formatMiscInfoPattern: () => '',
|
|
||||||
getEffectiveSentenceCardConfig: () => ({
|
|
||||||
model: 'Sentence',
|
|
||||||
sentenceField: 'Sentence',
|
|
||||||
audioField: 'SentenceAudio',
|
|
||||||
lapisEnabled: false,
|
|
||||||
kikuEnabled: true,
|
|
||||||
fieldGroupingMode: 'manual',
|
|
||||||
}),
|
}),
|
||||||
getFallbackDurationSeconds: () => 10,
|
);
|
||||||
appendKnownWordsFromNoteInfo: () => undefined,
|
|
||||||
removeKnownWordNote: () => undefined,
|
assert.equal(await service.createSentenceCard(c.sentence, 0, 1), true);
|
||||||
isUpdateInProgress: () => false,
|
assert.deepEqual(lookedUp, [c.sentence]);
|
||||||
setUpdateInProgress: () => undefined,
|
assert.deepEqual(trackedDuplicates, c.expected);
|
||||||
trackLastAddedNoteId: () => undefined,
|
|
||||||
findDuplicateNoteIds: async () => [],
|
|
||||||
trackLastAddedDuplicateNoteIds: (noteId, duplicateNoteIds) => {
|
|
||||||
trackedDuplicates.push({ noteId, duplicateNoteIds });
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
const created = await service.createSentenceCard('重複なし', 0, 1);
|
|
||||||
|
|
||||||
assert.equal(created, true);
|
|
||||||
assert.deepEqual(trackedDuplicates, []);
|
|
||||||
});
|
|
||||||
@@ -500,3 +500,38 @@ test('Senren merge keeps duplicate SentenceFurigana when the kept field is empty
|
|||||||
|
|
||||||
assert.equal(merged.SentenceFurigana, '<span class="group">duplicate furigana</span>');
|
assert.equal(merged.SentenceFurigana, '<span class="group">duplicate furigana</span>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('computeFieldGroupingMergedFields keeps independent groups for identical sentence, audio, and image values', async () => {
|
||||||
|
const { collaborator } = createCollaborator();
|
||||||
|
|
||||||
|
const merged = await collaborator.computeFieldGroupingMergedFields(
|
||||||
|
202,
|
||||||
|
101,
|
||||||
|
makeNote(202, {
|
||||||
|
Sentence: 'same sentence',
|
||||||
|
SentenceAudio: '[sound:same.mp3]',
|
||||||
|
Picture: '<img src="same.png">',
|
||||||
|
ExpressionAudio: '[sound:same.mp3]',
|
||||||
|
}),
|
||||||
|
makeNote(101, {
|
||||||
|
Sentence: 'same sentence',
|
||||||
|
SentenceAudio: '[sound:same.mp3]',
|
||||||
|
Picture: '<img src="same.png">',
|
||||||
|
}),
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
merged.Sentence,
|
||||||
|
'<span data-group-id="202">same sentence</span><span data-group-id="101">same sentence</span>',
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
merged.SentenceAudio,
|
||||||
|
'<span data-group-id="202">[sound:same.mp3]</span><span data-group-id="101">[sound:same.mp3]</span>',
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
merged.Picture,
|
||||||
|
'<img data-group-id="202" src="same.png"><img data-group-id="101" src="same.png">',
|
||||||
|
);
|
||||||
|
assert.equal('ExpressionAudio' in merged, false);
|
||||||
|
});
|
||||||
@@ -127,18 +127,6 @@ test('lifecycle config key is unchanged when maturity is disabled', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a cache built under the old tier rules is invalidated', () => {
|
|
||||||
const config: AnkiConnectConfig = {
|
|
||||||
knownWords: { highlightEnabled: true, maturityEnabled: true, refreshMinutes: 60 },
|
|
||||||
};
|
|
||||||
// v1 rules put lapsed cards in young because the interval queries did not
|
|
||||||
// exclude is:learn; those persisted tiers must not be served under v2.
|
|
||||||
assert.notEqual(
|
|
||||||
getKnownWordCacheLifecycleConfig(config),
|
|
||||||
'{"refreshMinutes":60,"scope":"all","fieldsWord":"","maturity":21}',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('refresh fetches tier sets and getKnownWordTier classifies notes', async () => {
|
test('refresh fetches tier sets and getKnownWordTier classifies notes', async () => {
|
||||||
const { manager, calls, clientState, cleanup } = createMaturityHarness(maturityConfig());
|
const { manager, calls, clientState, cleanup } = createMaturityHarness(maturityConfig());
|
||||||
|
|
||||||
|
|||||||
Loaded 100 of 522 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user