fix(passport-photo): require the face-detection bundle, not just background-removal (#329)

* fix(passport-photo): require the face-detection bundle, not just background-removal

Passport Photo runs face-landmark detection (face_landmarks.py, gated to the
face-detection bundle) before background removal (background-removal bundle),
but it was only declared under and guarded against background-removal. A user
who installed only Background Removal passed every JS-side check, then hit a
late "feature_not_installed" from the Python dispatcher gate when the analyze
step ran face landmarks, and the UI never told them Face Detection was needed.

- shared: add TOOL_EXTRA_BUNDLES + getRequiredBundlesForTool so a tool can
  declare more than one required bundle (passport-photo needs background-removal
  and face-detection). enablesTools is untouched, so the one-tool-per-bundle
  invariant still holds.
- api: isToolInstalled() now checks every required bundle; add
  getFirstMissingBundleForTool() so the analyze and base routes, pipeline (both
  guards) and batch report the bundle the user actually still needs.
- web: the proactive install prompt (tool-page) and features-store treat a tool
  as installed only when all required bundles are present, and point the prompt
  at the first missing one (sequential install, no new UI).

Refs #327

* test(passport-photo): deterministic integration coverage for the two-bundle guard

Boots the real API with an isolated DATA_DIR and controls installed.json to
prove the HTTP route behavior end-to-end:
- nothing installed -> 501 naming background-removal
- only background-removal installed -> 501 naming face-detection (issue #327)
- both installed -> guard passes (not 501)
- base route reports face-detection too

Refs #327
This commit is contained in:
SnapOtter
2026-06-22 23:31:18 +08:00
committed by GitHub
parent 8952e9ba47
commit 32c1192d63
11 changed files with 346 additions and 43 deletions
@@ -309,6 +309,39 @@ describe("Feature status queries", () => {
mod.markUninstalled("face-detection");
expect(mod.isToolInstalled("blur-faces")).toBe(false);
});
// passport-photo needs TWO bundles: background-removal (its primary) and
// face-detection (for face-landmark detection). Installing only one must not
// report the tool as ready. This is the bug behind issue #327.
it("isToolInstalled is false for passport-photo when only background-removal is installed", () => {
mod.markInstalled("background-removal", "1.0.0", []);
expect(mod.isToolInstalled("passport-photo")).toBe(false);
});
it("isToolInstalled is true for passport-photo only when both bundles are installed", () => {
mod.markInstalled("background-removal", "1.0.0", []);
mod.markInstalled("face-detection", "1.0.0", []);
expect(mod.isToolInstalled("passport-photo")).toBe(true);
});
it("getFirstMissingBundleForTool names face-detection when only background-removal is installed", () => {
mod.markInstalled("background-removal", "1.0.0", []);
expect(mod.getFirstMissingBundleForTool("passport-photo")).toBe("face-detection");
});
it("getFirstMissingBundleForTool returns the primary bundle first when nothing is installed", () => {
expect(mod.getFirstMissingBundleForTool("passport-photo")).toBe("background-removal");
});
it("getFirstMissingBundleForTool returns null when all required bundles are installed", () => {
mod.markInstalled("background-removal", "1.0.0", []);
mod.markInstalled("face-detection", "1.0.0", []);
expect(mod.getFirstMissingBundleForTool("passport-photo")).toBeNull();
});
it("getFirstMissingBundleForTool returns null for non-AI tools", () => {
expect(mod.getFirstMissingBundleForTool("resize")).toBeNull();
});
});
describe("Model verification via getFeatureStates", () => {