Files
sousa-gecko/toolkit/components/ml/tests/xpcshell/test_ml_engine_security.js
T
Randy Concepcion 3bb4ee6757 Bug 1997986 - Add ML security layer initially as a pass-through component for LLM calls and tool dispatch. r=tarek,ai-ondevice-reviewers
- Moved JSActor pattern from security-specific JSActor back to parent
  MLEngine JSActor
- Move validation logic for both request/response from child to parent
  to avoid IPC round trip (improve performance)

Differential Revision: https://phabricator.services.mozilla.com/D271495
2025-11-19 16:17:07 +00:00

44 lines
1.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { MLEngine } = ChromeUtils.importESModule(
"resource://gre/actors/MLEngineParent.sys.mjs"
);
/**
* Test that MLEngine properly manages request lifecycle.
* This ensures security layer integration doesn't break request tracking.
*/
add_task(async function test_request_lifecycle_management() {
info("Testing request lifecycle management");
const engine = new MLEngine({
mlEngineParent: {},
pipelineOptions: { engineId: "test-request-lifecycle" },
notificationsCallback: null,
});
// Verify engine starts with no pending requests
// The #requests map is private, but we can test behavior
// Without a port, run() should throw before creating a request
let errorThrown = false;
try {
await engine.run({ args: ["test"] });
} catch (error) {
errorThrown = true;
Assert.ok(
error.message.includes("Port does not exist"),
"Should fail on port check"
);
}
Assert.ok(errorThrown, "run() without port should throw");
await MLEngine.removeInstance("test-request-lifecycle", false, false);
info("Request lifecycle management works correctly");
});