@efffrida/vitest-pool 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- export {};
1
+ import "@efffrida/polyfills";
2
2
  //# sourceMappingURL=agent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../frida/agent.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../frida/agent.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC"}
@@ -1,17 +1,233 @@
1
- import { init, runBaseTests } from "vitest/worker";
2
- init({
3
- post: rpcResponse => {
4
- send(rpcResponse);
5
- },
6
- on: rpcListener => {
7
- rpc.exports["onMessage"] = message => {
8
- rpcListener(message);
1
+ import "@efffrida/polyfills";
2
+ import { collectTests, startTests } from "@vitest/runner";
3
+ import { serializeError } from "@vitest/utils/error";
4
+ import { createStackString, parseStacktrace } from "@vitest/utils/source-map";
5
+ import { createBirpc } from "birpc";
6
+ import { stringify as flattedStringify } from "flatted";
7
+ import { EvaluatedModules } from "vitest";
8
+ const testFiles = {};
9
+ // There should only ever be one test running at a time in a worker and these
10
+ // need to be shared across multiple rpc calls anyways so they will live up here
11
+ // in the module scope.
12
+ let runPromise;
13
+ let setupContext;
14
+ // How to post messages to the parent process - use flatted to handle circular references
15
+ const postMessage = message => send(flattedStringify(message, (_key, value) => {
16
+ /** @see https://github.com/vitest-dev/vitest/blob/372e86fdef381038a2c4999fc9007dd7292a0628/packages/vitest/src/node/ast-collect.ts#L216-L236 */
17
+ if (value !== null && typeof value === "object" && "name" in value && "message" in value && "stack" in value && typeof value.stack !== "string") {
18
+ return {
19
+ ...value,
20
+ stack: value.stack === undefined ? undefined : JSON.stringify(value.stack)
9
21
  };
10
- },
11
- off: _callback => {
12
- delete rpc.exports["onMessage"];
13
- },
14
- runTests: state => runBaseTests("run", state),
15
- collectTests: state => runBaseTests("collect", state)
22
+ } else {
23
+ return value;
24
+ }
25
+ }));
26
+ const postWorkerResponse = response => postMessage({
27
+ ...response,
28
+ __vitest_worker_response__: true
16
29
  });
30
+ // Collections of listeners
31
+ const cleanupListeners = /*#__PURE__*/new Set();
32
+ const cancelListeners = /*#__PURE__*/new Set();
33
+ const messageListeners = /*#__PURE__*/new Set();
34
+ const birpc = /*#__PURE__*/createBirpc({
35
+ async onCancel(reason) {
36
+ await Promise.allSettled([...cancelListeners.values()].map(listener => listener(reason)));
37
+ }
38
+ }, {
39
+ // How to serialize and deserialize messages.
40
+ serialize: data => data,
41
+ deserialize: data => data,
42
+ // How to send and receive messages.
43
+ post: postMessage,
44
+ on: rpcListener => messageListeners.add(rpcListener),
45
+ off: rpcListener => messageListeners.delete(rpcListener),
46
+ // Names of remote functions that do not need response.
47
+ // These are fire-and-forget messages to the vitest pool coordinator.
48
+ eventNames: ["onUserConsoleLog", "onCollected", "onCancel"],
49
+ // Maximum timeout for waiting for response, in milliseconds.
50
+ timeout: -1
51
+ });
52
+ /** @see https://github.com/vitest-dev/vitest/blob/8508296e9adcd2d9859e8073ac76c0bcb7d78f50/packages/vitest/src/runtime/utils.ts#L23-L32 */
53
+ function provideWorkerState(context, state) {
54
+ const NAME_WORKER_STATE = "__vitest_worker__";
55
+ Object.defineProperty(context, NAME_WORKER_STATE, {
56
+ value: state,
57
+ configurable: true,
58
+ writable: true,
59
+ enumerable: false
60
+ });
61
+ return state;
62
+ }
63
+ /** @see https://github.com/vitest-dev/vitest/blob/9ca74cfb2060d8bc1c7a319ba3cba1578517adb0/packages/vitest/src/runtime/runners/index.ts#L65-L139 */
64
+ function patchTestRunner(testRunner) {
65
+ const originalOnTaskUpdate = testRunner.onTaskUpdate;
66
+ testRunner.onTaskUpdate = async (task, events) => {
67
+ await birpc.onTaskUpdate(task, events);
68
+ await originalOnTaskUpdate?.call(testRunner, task, events);
69
+ };
70
+ const originalOnCollectStart = testRunner.onCollectStart;
71
+ testRunner.onCollectStart = async file => {
72
+ await birpc.onQueued(file);
73
+ await originalOnCollectStart?.call(testRunner, file);
74
+ };
75
+ const originalOnCollected = testRunner.onCollected;
76
+ testRunner.onCollected = async files => {
77
+ await birpc.onCollected(files);
78
+ await originalOnCollected?.call(testRunner, files);
79
+ };
80
+ return testRunner;
81
+ }
82
+ /** @see https://github.com/vitest-dev/vitest/blob/4f58c77147796d48bf70579222a577df977300f8/packages/vitest/src/runtime/workers/init.ts#L20-L235 */
83
+ rpc.exports["onMessage"] = async message => {
84
+ // Predicate to check if a message is a worker request
85
+ const isWorkerRequest = u => typeof u === "object" && u !== null && "__vitest_worker_request__" in u && u.__vitest_worker_request__ === true;
86
+ // Handle non-worker messages
87
+ if (!isWorkerRequest(message)) {
88
+ return messageListeners.forEach(listener => {
89
+ listener(message);
90
+ });
91
+ }
92
+ // Handle worker messages
93
+ switch (message.type) {
94
+ case "start":
95
+ {
96
+ process.env.VITEST_POOL_ID = String(message.poolId);
97
+ process.env.VITEST_WORKER_ID = String(message.workerId);
98
+ const {
99
+ config,
100
+ environment,
101
+ pool
102
+ } = message.context;
103
+ setupContext = {
104
+ environment,
105
+ config,
106
+ pool,
107
+ rpc: birpc,
108
+ projectName: config.name ?? ""
109
+ };
110
+ return postWorkerResponse({
111
+ type: "started"
112
+ });
113
+ }
114
+ case "stop":
115
+ {
116
+ if (runPromise !== undefined) await runPromise;
117
+ await Promise.allSettled(setupContext.rpc.$rejectPendingCalls(({
118
+ method,
119
+ reject
120
+ }) => {
121
+ reject(`Closing rpc while ${method} was pending`);
122
+ }));
123
+ await Promise.allSettled([...cleanupListeners.values()].map(listener => listener()));
124
+ cancelListeners.clear();
125
+ cleanupListeners.clear();
126
+ return postWorkerResponse({
127
+ type: "stopped"
128
+ });
129
+ }
130
+ case "run":
131
+ case "collect":
132
+ {
133
+ if (runPromise !== undefined) {
134
+ return postWorkerResponse({
135
+ type: "testfileFinished",
136
+ error: serializeError("Worker is already running tests")
137
+ });
138
+ }
139
+ /** @see https://github.com/vitest-dev/vitest/blob/4f58c77147796d48bf70579222a577df977300f8/packages/vitest/src/runtime/worker.ts#L28-L49 */
140
+ provideWorkerState(globalThis, {
141
+ rpc: birpc,
142
+ environment: null,
143
+ config: setupContext.config,
144
+ durations: {
145
+ environment: 0,
146
+ prepare: 0
147
+ },
148
+ ctx: {
149
+ ...setupContext,
150
+ ...message.context
151
+ },
152
+ providedContext: message.context.providedContext,
153
+ metaEnv: process.env,
154
+ resolvingModules: new Set(),
155
+ // TODO: share this between runs? https://github.com/vitest-dev/vitest/blob/8508296e9adcd2d9859e8073ac76c0bcb7d78f50/packages/vitest/src/runtime/worker.ts#L9
156
+ moduleExecutionInfo: new Map(),
157
+ // TODO: share this between runs? https://github.com/vitest-dev/vitest/blob/4f58c77147796d48bf70579222a577df977300f8/packages/vitest/src/runtime/workers/base.ts#L18-L19
158
+ evaluatedModules: new EvaluatedModules(),
159
+ // TODO: share this between runs? https://github.com/vitest-dev/vitest/blob/4f58c77147796d48bf70579222a577df977300f8/packages/vitest/src/runtime/workers/base.ts#L18-L19
160
+ onCancel: listener => cancelListeners.add(listener),
161
+ onCleanup: listener => cleanupListeners.add(listener),
162
+ onFilterStackTrace: stack => createStackString(parseStacktrace(stack))
163
+ });
164
+ // Create a minimal runner without snapshot support
165
+ const entrypoint = message.type === "run" ? startTests : collectTests;
166
+ const testRunner = {
167
+ config: setupContext.config,
168
+ importFile: async file => {
169
+ const nodeAssert = await import("node:assert");
170
+ const nodeBuffer = await import("node:buffer");
171
+ const nodeCrypto = await import("node:crypto");
172
+ const diagnosticsChannel = await import("node:diagnostics_channel");
173
+ const nodeEvents = await import("node:events");
174
+ const nodeFs = await import("node:fs");
175
+ const nodeNet = await import("node:net");
176
+ const nodeOs = await import("node:os");
177
+ const nodePath = await import("node:path");
178
+ const nodeProcess = await import("node:process");
179
+ const nodeStream = await import("node:stream");
180
+ const nodeTimers = await import("node:timers");
181
+ const nodeTty = await import("node:tty");
182
+ const nodeUrl = await import("node:url");
183
+ const nodeUtil = await import("node:util");
184
+ const nodeVm = await import("node:vm");
185
+ const vitestModule = await import("vitest");
186
+ const vitestRunnerModule = await import("@vitest/runner");
187
+ globalThis.__node_assert = nodeAssert;
188
+ globalThis.__node_buffer = nodeBuffer;
189
+ globalThis.__node_crypto = nodeCrypto;
190
+ globalThis.__node_diagnosticsChannel = diagnosticsChannel;
191
+ globalThis.__node_events = nodeEvents;
192
+ globalThis.__node_fs = nodeFs;
193
+ globalThis.__node_net = nodeNet;
194
+ globalThis.__node_os = nodeOs;
195
+ globalThis.__node_path = nodePath;
196
+ globalThis.__node_process = nodeProcess;
197
+ globalThis.__node_stream = nodeStream;
198
+ globalThis.__node_timers = nodeTimers;
199
+ globalThis.__node_tty = nodeTty;
200
+ globalThis.__node_url = nodeUrl;
201
+ globalThis.__node_util = nodeUtil;
202
+ globalThis.__node_vm = nodeVm;
203
+ globalThis.__vitest = vitestModule;
204
+ globalThis.__vitest_runner = vitestRunnerModule;
205
+ // TODO: warning if file not found
206
+ const source64 = testFiles[file];
207
+ if (source64 === undefined) {
208
+ return;
209
+ }
210
+ const source = Buffer.from(source64, "base64").toString("utf-8");
211
+ await Script.load(file, source);
212
+ }
213
+ };
214
+ try {
215
+ for (const file of message.context.files) {
216
+ runPromise = entrypoint([file], patchTestRunner(testRunner));
217
+ await runPromise;
218
+ }
219
+ postWorkerResponse({
220
+ type: "testfileFinished"
221
+ });
222
+ } catch (error) {
223
+ postWorkerResponse({
224
+ type: "testfileFinished",
225
+ error: serializeError(error)
226
+ });
227
+ } finally {
228
+ runPromise = undefined;
229
+ }
230
+ }
231
+ }
232
+ };
17
233
  //# sourceMappingURL=agent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","names":["init","runBaseTests","post","rpcResponse","send","on","rpcListener","rpc","exports","message","off","_callback","runTests","state","collectTests"],"sources":["../../frida/agent.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,IAAI,EAAEC,YAAY,QAAQ,eAAe;AAElDD,IAAI,CAAC;EACDE,IAAI,EAAGC,WAAW,IAAI;IAClBC,IAAI,CAACD,WAAW,CAAC;EACrB,CAAC;EACDE,EAAE,EAAGC,WAAW,IAAI;IAChBC,GAAG,CAACC,OAAO,CAAC,WAAW,CAAC,GAAIC,OAAgB,IAAI;MAC5CH,WAAW,CAACG,OAAO,CAAC;IACxB,CAAC;EACL,CAAC;EACDC,GAAG,EAAGC,SAAS,IAAI;IACf,OAAOJ,GAAG,CAACC,OAAO,CAAC,WAAW,CAAC;EACnC,CAAC;EACDI,QAAQ,EAAGC,KAAK,IAAKZ,YAAY,CAAC,KAAK,EAAEY,KAAK,CAAC;EAC/CC,YAAY,EAAGD,KAAK,IAAKZ,YAAY,CAAC,SAAS,EAAEY,KAAK;CACzD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"agent.js","names":["collectTests","startTests","serializeError","createStackString","parseStacktrace","createBirpc","stringify","flattedStringify","EvaluatedModules","testFiles","runPromise","setupContext","postMessage","message","send","_key","value","stack","undefined","JSON","postWorkerResponse","response","__vitest_worker_response__","cleanupListeners","Set","cancelListeners","messageListeners","birpc","onCancel","reason","Promise","allSettled","values","map","listener","serialize","data","deserialize","post","on","rpcListener","add","off","delete","eventNames","timeout","provideWorkerState","context","state","NAME_WORKER_STATE","Object","defineProperty","configurable","writable","enumerable","patchTestRunner","testRunner","originalOnTaskUpdate","onTaskUpdate","task","events","call","originalOnCollectStart","onCollectStart","file","onQueued","originalOnCollected","onCollected","files","rpc","exports","isWorkerRequest","u","__vitest_worker_request__","forEach","type","process","env","VITEST_POOL_ID","String","poolId","VITEST_WORKER_ID","workerId","config","environment","pool","projectName","name","$rejectPendingCalls","method","reject","clear","error","globalThis","durations","prepare","ctx","providedContext","metaEnv","resolvingModules","moduleExecutionInfo","Map","evaluatedModules","onCleanup","onFilterStackTrace","entrypoint","importFile","nodeAssert","nodeBuffer","nodeCrypto","diagnosticsChannel","nodeEvents","nodeFs","nodeNet","nodeOs","nodePath","nodeProcess","nodeStream","nodeTimers","nodeTty","nodeUrl","nodeUtil","nodeVm","vitestModule","vitestRunnerModule","__node_assert","__node_buffer","__node_crypto","__node_diagnosticsChannel","__node_events","__node_fs","__node_net","__node_os","__node_path","__node_process","__node_stream","__node_timers","__node_tty","__node_url","__node_util","__node_vm","__vitest","__vitest_runner","source64","source","Buffer","from","toString","Script","load"],"sources":["../../frida/agent.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,qBAAqB;AAM5B,SAASA,YAAY,EAAEC,UAAU,QAAQ,gBAAgB;AACzD,SAASC,cAAc,QAAQ,qBAAqB;AACpD,SAASC,iBAAiB,EAAEC,eAAe,QAAQ,0BAA0B;AAC7E,SAASC,WAAW,QAAQ,OAAO;AACnC,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,SAAS;AACvD,SAASC,gBAAgB,QAAQ,QAAQ;AAEzC,MAAMC,SAAS,GAA2B,EAAE;AAE5C;AACA;AACA;AACA,IAAIC,UAAwC;AAC5C,IAAIC,YAAyF;AAE7F;AACA,MAAMC,WAAW,GAAIC,OAAgB,IACjCC,IAAI,CACAP,gBAAgB,CAACM,OAAO,EAAE,CAACE,IAAY,EAAEC,KAAc,KAAa;EAChE;EACA,IACIA,KAAK,KAAK,IAAI,IACd,OAAOA,KAAK,KAAK,QAAQ,IACzB,MAAM,IAAIA,KAAK,IACf,SAAS,IAAIA,KAAK,IAClB,OAAO,IAAIA,KAAK,IAChB,OAAOA,KAAK,CAACC,KAAK,KAAK,QAAQ,EACjC;IACE,OAAO;MACH,GAAGD,KAAK;MACRC,KAAK,EAAED,KAAK,CAACC,KAAK,KAAKC,SAAS,GAAGA,SAAS,GAAGC,IAAI,CAACb,SAAS,CAACU,KAAK,CAACC,KAAK;KAC5E;EACL,CAAC,MAAM;IACH,OAAOD,KAAK;EAChB;AACJ,CAAC,CAAC,CACL;AACL,MAAMI,kBAAkB,GAAIC,QAA4D,IACpFT,WAAW,CAAC;EAAE,GAAGS,QAAQ;EAAEC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C4C,UAAU,GAAGlB,OAAO;YACvC1B,UAAkB,CAAC6C,UAAU,GAAGlB,OAAO;YACvC3B,UAAkB,CAAC8C,WAAW,GAAGlB,QAAQ;YACzC5B,UAAkB,CAAC+C,SAAS,GAAGlB,MAAM;YACrC7B,UAAkB,CAACgD,QAAQ,GAAGlB,YAAY;YAC1C9B,UAAkB,CAACiD,eAAe,GAAGlB,kBAAkB;YAExD;YACA,MAAMmB,QAAQ,GAAGtI,SAAS,CAACuD,IAAI,CAAC;YAChC,IAAI+E,QAAQ,KAAK7H,SAAS,EAAE;cACxB;YACJ;YAEA,MAAM8H,MAAM,GAAGC,MAAM,CAACC,IAAI,CAACH,QAAQ,EAAE,QAAQ,CAAC,CAACI,QAAQ,CAAC,OAAO,CAAC;YAChE,MAAMC,MAAM,CAACC,IAAI,CAACrF,IAAI,EAAEgF,MAAM,CAAC;UACnC;SACH;QAED,IAAI;UACA,KAAK,MAAMhF,IAAI,IAAInD,OAAO,CAACkC,OAAO,CAACqB,KAAK,EAAE;YACtC1D,UAAU,GAAG+F,UAAU,CAAC,CAACzC,IAAI,CAAC,EAAET,eAAe,CAACC,UAAU,CAAC,CAAC;YAC5D,MAAM9C,UAAU;UACpB;UACAU,kBAAkB,CAAC;YAAEuD,IAAI,EAAE;UAAkB,CAAE,CAAC;QACpD,CAAC,CAAC,OAAOiB,KAAc,EAAE;UACrBxE,kBAAkB,CAAC;YAAEuD,IAAI,EAAE,kBAAkB;YAAEiB,KAAK,EAAE1F,cAAc,CAAC0F,KAAK;UAAC,CAAE,CAAC;QAClF,CAAC,SAAS;UACNlF,UAAU,GAAGQ,SAAS;QAC1B;MACJ;EACJ;AACJ,CAAC","ignoreList":[]}
@@ -1,5 +1,4 @@
1
1
  import type * as VitestNode from "vitest/node";
2
- import type { PoolWorker, WorkerRequest } from "vitest/node";
3
2
  import * as Schema from "effect/Schema";
4
3
  declare const DeviceSchema_base: Schema.Union<[Schema.Struct<{
5
4
  device: Schema.Literal<["local"]>;
@@ -54,7 +53,10 @@ declare const AttachSchema_base: Schema.Union<[Schema.Struct<{
54
53
  declare class AttachSchema extends AttachSchema_base {
55
54
  }
56
55
  declare const ConfigSchema_base: Schema.extend<Schema.extend<Schema.Struct<{
57
- isolated: Schema.optionalWith<typeof Schema.Boolean, {
56
+ runtime: Schema.optionalWith<Schema.Literal<["default", "qjs", "v8"]>, {
57
+ nullable: true;
58
+ }>;
59
+ platform: Schema.optionalWith<Schema.Literal<["gum", "browser", "neutral"]>, {
58
60
  nullable: true;
59
61
  }>;
60
62
  }>, typeof DeviceSchema>, typeof AttachSchema>;
@@ -64,23 +66,27 @@ declare class ConfigSchema extends ConfigSchema_base {
64
66
  * @since 1.0.0
65
67
  * @category Tests
66
68
  */
67
- export declare class FridaPoolWorker implements PoolWorker {
69
+ export declare class FridaPoolWorker implements VitestNode.PoolWorker {
68
70
  readonly name = "frida-pool";
71
+ readonly agentTemplatePath: URL;
72
+ private readonly poolOptions;
69
73
  private readonly customOptions;
70
- private readonly managedRuntime;
71
74
  private readonly cancelables;
72
- constructor(_poolOptions: VitestNode.PoolOptions, customOptions: Schema.Schema.Type<typeof ConfigSchema>);
75
+ private modifiedAgentScope;
76
+ private managedRuntime;
77
+ constructor(poolOptions: VitestNode.PoolOptions, customOptions: Schema.Schema.Type<ConfigSchema>);
73
78
  start(): Promise<void>;
74
79
  stop(): Promise<void>;
75
- send(message: WorkerRequest): Promise<void>;
80
+ send(message: VitestNode.WorkerRequest): Promise<void>;
76
81
  on(event: string, callback: (arg: any) => void): void;
77
82
  off(_event: string, callback: (arg: any) => void): void;
78
- deserialize(data: unknown): unknown;
83
+ deserialize(data: unknown): any;
84
+ serialize(data: unknown): unknown;
79
85
  }
80
86
  /**
81
87
  * @since 1.0.0
82
88
  * @category Tests
83
89
  */
84
- export declare const createFridaPool: (customOptions: Schema.Schema.Encoded<typeof ConfigSchema>) => VitestNode.PoolRunnerInitializer;
90
+ export declare const createFridaPool: (customOptions: Schema.Schema.Encoded<ConfigS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AAE,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAQvD,WAAW,CAAC,IAAI,EAAE,OAAO;IAKzB,SAAS,CAAC,IAAI,EAAE,OAAO;CAG1B;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,GACxB,eAAe,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KACnD,UAAU,CAAC,qBAMb,CAAC"}
package/dist/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import * as NodeContext from "@effect/platform-node/NodeContext";
2
2
  import * as Command from "@effect/platform/Command";
3
3
  import * as CommandExecutor from "@effect/platform/CommandExecutor";
4
+ import * as FileSystem from "@effect/platform/FileSystem";
5
+ import * as Path from "@effect/platform/Path";
4
6
  import * as FridaDevice from "@efffrida/frida-tools/FridaDevice";
5
7
  import * as FridaScript from "@efffrida/frida-tools/FridaScript";
6
8
  import * as FridaSession from "@efffrida/frida-tools/FridaSession";
@@ -13,7 +15,12 @@ import * as Layer from "effect/Layer";
13
15
  import * as ManagedRuntime from "effect/ManagedRuntime";
14
16
  import * as Match from "effect/Match";
15
17
  import * as Schema from "effect/Schema";
18
+ import * as Scope from "effect/Scope";
19
+ import * as Sink from "effect/Sink";
16
20
  import * as Stream from "effect/Stream";
21
+ import * as Esbuild from "esbuild";
22
+ import * as Flatted from "flatted";
23
+ import * as Frida from "frida";
17
24
  // First, pick your device
18
25
  class DeviceSchema extends /*#__PURE__*/Schema.Union(/*#__PURE__*/Schema.Struct({
19
26
  device: /*#__PURE__*/Schema.Literal("local")
@@ -64,8 +71,12 @@ class AttachSchema extends /*#__PURE__*/Schema.Union(/*#__PURE__*/Schema.Struct(
64
71
  nullable: true
65
72
  })
66
73
  })) {}
74
+ // Third, pick your runtime and platform
67
75
  class ConfigSchema extends /*#__PURE__*/Schema.Struct({
68
- isolated: Schema.optionalWith(Schema.Boolean, {
76
+ runtime: Schema.optionalWith(Schema.Literal("default", "qjs", "v8"), {
77
+ nullable: true
78
+ }),
79
+ platform: Schema.optionalWith(Schema.Literal("gum", "browser", "neutral"), {
69
80
  nullable: true
70
81
  })
71
82
  }).pipe(Schema.extend(DeviceSchema)).pipe(/*#__PURE__*/Schema.extend(AttachSchema)) {}
@@ -75,12 +86,23 @@ class ConfigSchema extends /*#__PURE__*/Schema.Struct({
75
86
  */
76
87
  export class FridaPoolWorker {
77
88
  name = "frida-pool";
89
+ agentTemplatePath = /*#__PURE__*/new URL("../frida/agent.ts", import.meta.url);
90
+ poolOptions;
78
91
  customOptions;
79
- managedRuntime;
80
92
  cancelables;
81
- constructor(_poolOptions, customOptions) {
93
+ modifiedAgentScope;
94
+ managedRuntime;
95
+ constructor(poolOptions, customOptions) {
96
+ this.poolOptions = poolOptions;
82
97
  this.customOptions = customOptions;
83
98
  this.cancelables = new Map();
99
+ this.managedRuntime = undefined;
100
+ this.modifiedAgentScope = Effect.runSync(Scope.make());
101
+ }
102
+ async start() {
103
+ const tempAgentUrl = await compileTestFiles(this.agentTemplatePath, this.poolOptions).pipe(Scope.extend(this.modifiedAgentScope)).pipe(Effect.provide(NodeContext.layer)).pipe(Effect.runPromise);
104
+ const FridaRuntime = Match.value(this.customOptions.runtime).pipe(Match.when(undefined, () => undefined), Match.when("v8", () => Frida.ScriptRuntime.V8), Match.when("qjs", () => Frida.ScriptRuntime.QJS), Match.when("default", () => Frida.ScriptRuntime.Default), Match.exhaustive);
105
+ const FridaPlatform = Match.value(this.customOptions.platform).pipe(Match.when(undefined, () => undefined), Match.when("gum", () => Frida.JsPlatform.Gum), Match.when("browser", () => Frida.JsPlatform.Browser), Match.when("neutral", () => Frida.JsPlatform.Neutral), Match.exhaustive);
84
106
  const DeviceLive = Match.value(this.customOptions).pipe(Match.when({
85
107
  device: "local"
86
108
  }, () => FridaDevice.layerLocalDevice), Match.when({
@@ -137,31 +159,39 @@ export class FridaPoolWorker {
137
159
  spawn
138
160
  }) => FridaSession.layer(spawn)));
139
161
  const FridaLive = Layer.provide(SessionLive, DeviceLive).pipe(Layer.provide(NodeContext.layer));
140
- const ScriptLive = FridaScript.layer(new URL("../frida/agent.ts", import.meta.url), {
141
- externals: ["jsdom", "happy-dom", "@edge-runtime/vm"]
142
- }).pipe(Layer.provide(FridaLive)).pipe(Layer.fresh);
162
+ const ScriptLive = FridaScript.layer(tempAgentUrl, {
163
+ externals: ["jsdom", "happy-dom", "@edge-runtime/vm"],
164
+ ...(FridaRuntime !== undefined ? {
165
+ runtime: FridaRuntime
166
+ } : {}),
167
+ ...(FridaPlatform !== undefined ? {
168
+ platform: FridaPlatform
169
+ } : {})
170
+ }).pipe(Layer.provide(FridaLive));
143
171
  this.managedRuntime = ManagedRuntime.make(ScriptLive);
144
- }
145
- async start() {
146
172
  const exit = await this.managedRuntime.runPromiseExit(Effect.void);
147
173
  if (Exit.isSuccess(exit)) return;
148
- throw Cause.pretty(exit.cause, {
149
- renderErrorCause: true
150
- });
174
+ const prettyError = Cause.prettyErrors(exit.cause);
175
+ throw prettyError[0];
151
176
  }
152
177
  async stop() {
153
- return this.managedRuntime.dispose();
178
+ await this.managedRuntime.dispose();
179
+ await Effect.runPromise(Scope.close(this.modifiedAgentScope, Exit.void));
154
180
  }
155
181
  async send(message) {
156
- await this.managedRuntime.runPromise(Effect.flatMap(FridaScript.FridaScript, fridaScript => fridaScript.callExport("onMessage", Schema.Void)(message)));
182
+ const exit = await this.managedRuntime.runPromiseExit(Effect.flatMap(FridaScript.FridaScript, fridaScript => fridaScript.callExport("onMessage", Schema.Void)(message)));
183
+ if (Exit.isSuccess(exit)) return;
184
+ const prettyError = Cause.prettyErrors(exit.cause);
185
+ throw prettyError[0];
157
186
  }
158
187
  on(event, callback) {
159
188
  let cancelable;
189
+ const sink = Sink.forEach(input => Effect.sync(() => {
190
+ callback(input.message);
191
+ }));
160
192
  switch (event) {
161
193
  case "message":
162
- cancelable = this.managedRuntime.runCallback(Effect.flatMap(FridaScript.FridaScript, fridaScript => fridaScript.stream.pipe(Stream.runForEach(({
163
- message
164
- }) => Effect.sync(() => callback(message))))));
194
+ cancelable = this.managedRuntime.runCallback(Effect.flatMap(FridaScript.FridaScript, fridaScript => Stream.run(fridaScript.stream, sink)));
165
195
  break;
166
196
  case "error":
167
197
  cancelable = this.managedRuntime.runCallback(Effect.flatMap(FridaScript.FridaScript, fridaScript => Deferred.await(fridaScript.scriptError)), {
@@ -186,6 +216,9 @@ export class FridaPoolWorker {
186
216
  }
187
217
  }
188
218
  deserialize(data) {
219
+ if (typeof data !== "string") return data;else return Flatted.parse(data);
220
+ }
221
+ serialize(data) {
189
222
  return data;
190
223
  }
191
224
  }
@@ -200,4 +233,186 @@ export const createFridaPool = customOptions => {
200
233
  createPoolWorker: options => new FridaPoolWorker(options, decoded)
201
234
  };
202
235
  };
236
+ /** @internal */
237
+ const vitestGlobalsPlugin = {
238
+ name: "vitest-globals",
239
+ setup(build) {
240
+ // Handle vitest and @vitest/* imports
241
+ build.onResolve({
242
+ filter: /^(vitest|@vitest\/.*)$/
243
+ }, args => ({
244
+ path: args.path,
245
+ namespace: "vitest-globals"
246
+ }));
247
+ build.onLoad({
248
+ filter: /.*/,
249
+ namespace: "vitest-globals"
250
+ }, args => {
251
+ if (args.path === "vitest") {
252
+ return {
253
+ loader: "js",
254
+ contents: "export * from 'VITEST_GLOBAL';\nexport { default } from 'VITEST_GLOBAL';"
255
+ };
256
+ }
257
+ if (args.path === "@vitest/runner") {
258
+ return {
259
+ loader: "js",
260
+ contents: "export * from 'VITEST_RUNNER_GLOBAL';\nexport { default } from 'VITEST_RUNNER_GLOBAL';"
261
+ };
262
+ }
263
+ return {
264
+ loader: "js",
265
+ contents: "export * from 'VITEST_GLOBAL';\nexport { default } from 'VITEST_GLOBAL';"
266
+ };
267
+ });
268
+ build.onResolve({
269
+ filter: /^VITEST_(GLOBAL|RUNNER_GLOBAL)$/
270
+ }, args => ({
271
+ path: args.path,
272
+ namespace: "vitest-synthetic"
273
+ }));
274
+ build.onLoad({
275
+ filter: /.*/,
276
+ namespace: "vitest-synthetic"
277
+ }, args => {
278
+ const globalName = args.path === "VITEST_GLOBAL" ? "__vitest" : "__vitest_runner";
279
+ return {
280
+ loader: "js",
281
+ contents: `
282
+ const g = globalThis.${globalName};
283
+ export default g;
284
+ export const {
285
+ describe, it, test, expect, vi, beforeAll, afterAll,
286
+ beforeEach, afterEach, suite, bench, assert
287
+ } = g;
288
+ `
289
+ };
290
+ });
291
+ // Handle Node.js built-in modules - redirect to globals set up by the agent
292
+ // The agent imports these from frida-compile's shims and exposes them as globals
293
+ const nodeModuleMap = {
294
+ "node:assert": "__node_assert",
295
+ "node:buffer": "__node_buffer",
296
+ "node:crypto": "__node_crypto",
297
+ "node:diagnostics_channel": "__node_diagnosticsChannel",
298
+ "node:events": "__node_events",
299
+ "node:fs": "__node_fs",
300
+ "node:net": "__node_net",
301
+ "node:os": "__node_os",
302
+ "node:path": "__node_path",
303
+ "node:process": "__node_process",
304
+ "node:stream": "__node_stream",
305
+ "node:timers": "__node_timers",
306
+ "node:tty": "__node_tty",
307
+ "node:url": "__node_url",
308
+ "node:util": "__node_util",
309
+ "node:vm": "__node_vm",
310
+ assert: "__node_assert",
311
+ buffer: "__node_buffer",
312
+ crypto: "__node_crypto",
313
+ diagnostics_channel: "__node_diagnosticsChannel",
314
+ events: "__node_events",
315
+ fs: "__node_fs",
316
+ net: "__node_net",
317
+ os: "__node_os",
318
+ path: "__node_path",
319
+ process: "__node_process",
320
+ stream: "__node_stream",
321
+ timers: "__node_timers",
322
+ tty: "__node_tty",
323
+ url: "__node_url",
324
+ util: "__node_util",
325
+ vm: "__node_vm"
326
+ };
327
+ build.onResolve({
328
+ filter: /^(node:)?(assert|buffer|crypto|diagnostics_channel|events|fs|net|os|path|process|stream|timers|tty|url|util|vm)$/
329
+ }, args => ({
330
+ path: args.path,
331
+ namespace: "node-globals"
332
+ }));
333
+ build.onLoad({
334
+ filter: /.*/,
335
+ namespace: "node-globals"
336
+ }, args => {
337
+ const globalName = nodeModuleMap[args.path];
338
+ if (!globalName) {
339
+ return {
340
+ loader: "js",
341
+ contents: "export default {};"
342
+ };
343
+ }
344
+ return {
345
+ loader: "js",
346
+ contents: `
347
+ const m = globalThis.${globalName};
348
+ export default m;
349
+ export const { Buffer } = m.Buffer ? m : { Buffer: m.default?.Buffer };
350
+ export * from 'NODE_MODULE_REEXPORT_${globalName}';
351
+ `
352
+ };
353
+ });
354
+ // Handle re-exports from node modules
355
+ build.onResolve({
356
+ filter: /^NODE_MODULE_REEXPORT_/
357
+ }, args => ({
358
+ path: args.path,
359
+ namespace: "node-reexport"
360
+ }));
361
+ build.onLoad({
362
+ filter: /.*/,
363
+ namespace: "node-reexport"
364
+ }, args => {
365
+ const globalName = args.path.replace("NODE_MODULE_REEXPORT_", "");
366
+ return {
367
+ loader: "js",
368
+ contents: `
369
+ const m = globalThis.${globalName};
370
+ const mod = m.default || m;
371
+ for (const key in mod) {
372
+ if (key !== 'default') {
373
+ Object.defineProperty(exports, key, {
374
+ enumerable: true,
375
+ get: () => mod[key]
376
+ });
377
+ }
378
+ }
379
+ `
380
+ };
381
+ });
382
+ }
383
+ };
384
+ /** @internal */
385
+ const compileTestFiles = /*#__PURE__*/Effect.fnUntraced(function* (agentTemplatePath, poolOptions, customOptions) {
386
+ const path = yield* Path.Path;
387
+ const fs = yield* FileSystem.FileSystem;
388
+ const url = yield* path.fromFileUrl(agentTemplatePath);
389
+ const testFiles = poolOptions.project.testFilesList ?? [];
390
+ const testFilesMap = {};
391
+ const esbuildPlatform = Match.value(customOptions?.platform).pipe(Match.when("browser", () => "browser"), Match.when("neutral", () => "neutral"), Match.whenOr("gum", undefined, () => "node"), Match.orElseAbsurd);
392
+ for (const testFile of testFiles) {
393
+ const result = yield* Effect.promise(() => Esbuild.build({
394
+ bundle: true,
395
+ write: false,
396
+ format: "esm",
397
+ platform: esbuildPlatform,
398
+ target: "es2020",
399
+ entryPoints: [testFile],
400
+ plugins: [vitestGlobalsPlugin]
401
+ }));
402
+ if (!result.outputFiles || result.outputFiles.length === 0) {
403
+ throw new Error(`esbuild produced no output for ${testFile}`);
404
+ } else {
405
+ testFilesMap[testFile] = Buffer.from(result.outputFiles[0].text).toString("base64");
406
+ }
407
+ }
408
+ const agentTemplateContents = yield* fs.readFileString(url);
409
+ const modifiedAgentContents = agentTemplateContents.replace(/^const testFiles: Record<string, string> = \{\};$/m, `const testFiles: Record<string, string> = ${JSON.stringify(testFilesMap, null, 4)};`);
410
+ const tempAgentPath = yield* fs.makeTempFileScoped({
411
+ suffix: ".ts",
412
+ prefix: ".agent-",
413
+ directory: path.dirname(url)
414
+ });
415
+ yield* fs.writeFileString(tempAgentPath, modifiedAgentContents);
416
+ return yield* path.toFileUrl(tempAgentPath);
417
+ });
203
418
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["NodeContext","Command","CommandExecutor","FridaDevice","FridaScript","FridaSession","Cause","Deferred","Duration","Effect","Exit","Layer","ManagedRuntime","Match","Schema","Stream","DeviceSchema","Union","Struct","device","Literal","timeout","optionalWith","DurationFromMillis","nullable","address","String","token","origin","keepaliveInterval","emulatorName","hidden","Boolean","adbExecutable","fridaExecutable","emulatorExecutable","AttachSchema","attach","Number","pipe","brand","spawn","NonEmptyArrayEnsure","preSpawn","attachFrontmost","frontmostScope","ConfigSchema","isolated","extend","FridaPoolWorker","name","customOptions","managedRuntime","cancelables","constructor","_poolOptions","Map","DeviceLive","value","when","layerLocalDevice","layerUsbDevice","toMillis","undefined","layerRemoteDevice","toSeconds","layerAndroidEmulatorDevice","exhaustive","SessionLive","number","layer","layerFrontmost","scope","unwrapScoped","gen","executor","command","make","process","start","pid","orElse","FridaLive","provide","ScriptLive","URL","import","meta","url","externals","fresh","exit","runPromiseExit","void","isSuccess","pretty","cause","renderErrorCause","stop","dispose","send","message","runPromise","flatMap","fridaScript","callExport","Void","on","event","callback","cancelable","runCallback","stream","runForEach","sync","await","scriptError","onExit","destroyed","Error","set","off","_event","get","delete","deserialize","data","createFridaPool","decoded","decodeUnknownSync","createPoolWorker","options"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAQA,OAAO,KAAKA,WAAW,MAAM,mCAAmC;AAChE,OAAO,KAAKC,OAAO,MAAM,0BAA0B;AACnD,OAAO,KAAKC,eAAe,MAAM,kCAAkC;AACnE,OAAO,KAAKC,WAAW,MAAM,mCAAmC;AAChE,OAAO,KAAKC,WAAW,MAAM,mCAAmC;AAChE,OAAO,KAAKC,YAAY,MAAM,oCAAoC;AAClE,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,IAAI,MAAM,aAAa;AACnC,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,cAAc,MAAM,uBAAuB;AACvD,OAAO,KAAKC,KAAK,MAAM,cAAc;AACrC,OAAO,KAAKC,MAAM,MAAM,eAAe;AACvC,OAAO,KAAKC,MAAM,MAAM,eAAe;AAEvC;AACA,MAAMC,YAAa,sBAAQF,MAAM,CAACG,KAAK,cACnCH,MAAM,CAACI,MAAM,CAAC;EACVC,MAAM,eAAEL,MAAM,CAACM,OAAO,CAAC,OAAO;CACjC,CAAC,eACFN,MAAM,CAACI,MAAM,CAAC;EACVC,MAAM,eAAEL,MAAM,CAACM,OAAO,CAAC,KAAK,CAAC;EAC7BC,OAAO,eAAEP,MAAM,CAACQ,YAAY,CAACR,MAAM,CAACS,kBAAkB,EAAE;IAAEC,QAAQ,EAAE;EAAI,CAAE;CAC7E,CAAC,eACFV,MAAM,CAACI,MAAM,CAAC;EACVO,OAAO,EAAEX,MAAM,CAACY,MAAM;EACtBP,MAAM,eAAEL,MAAM,CAACM,OAAO,CAAC,QAAQ,CAAC;EAChCO,KAAK,eAAEb,MAAM,CAACQ,YAAY,CAACR,MAAM,CAACY,MAAM,E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,CAAC1D,cAAc,CAAC2D,WAAW,CACxCtG,MAAM,CAAC8F,OAAO,CAACnG,WAAW,CAACA,WAAW,EAAGoG,WAAW,IAAKjG,QAAQ,CAAC4G,KAAK,CAACX,WAAW,CAACc,SAAS,CAAC,CAAC,EAC/F;UAAED,MAAM,EAAEA,CAAA,KAAMR,QAAQ,CAAC9C,SAAS;QAAC,CAAE,CACxC;QACD;MAEJ;QACI,MAAM,IAAIwD,KAAK,CAAC,SAASX,KAAK,mCAAmC,CAAC;IAC1E;IAEA,IAAI,CAACvD,WAAW,CAACmE,GAAG,CAACX,QAAQ,EAAEC,UAAU,CAAC;EAC9C;EAEAW,GAAGA,CAACC,MAAc,EAAEb,QAA4B;IAC5C,MAAMC,UAAU,GAAG,IAAI,CAACzD,WAAW,CAACsE,GAAG,CAACd,QAAQ,CAAC;IACjD,IAAIC,UAAU,KAAK/C,SAAS,EAAE;MAC1B,IAAI,CAACV,WAAW,CAACuE,MAAM,CAACf,QAAQ,CAAC;MACjCC,UAAU,EAAE;IAChB;EACJ;EAEAe,WAAWA,CAACC,IAAa;IACrB,OAAOA,IAAI;EACf;;AAGJ;;;;AAIA,OAAO,MAAMC,eAAe,GACxB5E,aAAyD,IACvB;EAClC,MAAM6E,OAAO,GAAGlH,MAAM,CAACmH,iBAAiB,CAACnF,YAAY,CAAC,CAACK,aAAa,CAAC;EACrE,OAAO;IACHD,IAAI,EAAE,YAAY;IAClBgF,gBAAgB,EAAGC,OAA+B,IAAK,IAAIlF,eAAe,CAACkF,OAAO,EAAEH,OAAO;GAC9F;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["NodeContext","Command","CommandExecutor","FileSystem","Path","FridaDevice","FridaScript","FridaSession","Cause","Deferred","Duration","Effect","Exit","Layer","ManagedRuntime","Match","Schema","Scope","Sink","Stream","Esbuild","Flatted","Frida","DeviceSchema","Union","Struct","device","Literal","timeout","optionalWith","DurationFromMillis","nullable","address","String","token","origin","keepaliveInterval","emulatorName","hidden","Boolean","adbExecutable","fridaExecutable","emulatorExecutable","AttachSchema","attach","Number","pipe","brand","spawn","NonEmptyArrayEnsure","preSpawn","attachFrontmost","frontmostScope","ConfigSchema","runtime","platform","extend","FridaPoolWorker","name","agentTemplatePath","URL","import","meta","url","poolOptions","customOptions","cancelables","modifiedAgentScope","managedRuntime","constructor","Map","undefined","runSync","make","start","tempAgentUrl","compileTestFiles","provide","layer","runPromise","FridaRuntime","value","when","ScriptRuntime","V8","QJS","Default","exhaustive","FridaPlatform","JsPlatform","Gum","Browser","Neutral","DeviceLive","layerLocalDevice","layerUsbDevice","toMillis","layerRemoteDevice","toSeconds","layerAndroidEmulatorDevice","SessionLive","number","layerFrontmost","scope","unwrapScoped","gen","executor","command","process","pid","orElse","FridaLive","ScriptLive","externals","exit","runPromiseExit","void","isSuccess","prettyError","prettyErrors","cause","stop","dispose","close","send","message","flatMap","fridaScript","callExport","Void","on","event","callback","cancelable","sink","forEach","input","sync","runCallback","run","stream","await","scriptError","onExit","destroyed","Error","set","off","_event","get","delete","deserialize","data","parse","serialize","createFridaPool","decoded","decodeUnknownSync","createPoolWorker","options","vitestGlobalsPlugin","setup","build","onResolve","filter","args","path","namespace","onLoad","loader","contents","globalName","nodeModuleMap","assert","buffer","crypto","diagnostics_channel","events","fs","net","os","timers","tty","util","vm","replace","fnUntraced","fromFileUrl","testFiles","project","testFilesList","testFilesMap","esbuildPlatform","whenOr","orElseAbsurd","testFile","result","promise","bundle","write","format","target","entryPoints","plugins","outputFiles","length","Buffer","from","text","toString","agentTemplateContents","readFileString","modifiedAgentContents","JSON","stringify","tempAgentPath","makeTempFileScoped","suffix","prefix","directory","dirname","writeFileString","toFileUrl"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAOA,OAAO,KAAKA,WAAW,MAAM,mCAAmC;AAChE,OAAO,KAAKC,OAAO,MAAM,0BAA0B;AACnD,OAAO,KAAKC,eAAe,MAAM,kCAAkC;AACnE,OAAO,KAAKC,UAAU,MAA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,QAAQ;MAChBC,WAAW,EAAE,CAACP,QAAQ,CAAC;MACvBQ,OAAO,EAAE,CAAC3C,mBAAmB;KAChC,CAAC,CACL;IAED,IAAI,CAACoC,MAAM,CAACQ,WAAW,IAAIR,MAAM,CAACQ,WAAW,CAACC,MAAM,KAAK,CAAC,EAAE;MACxD,MAAM,IAAI5D,KAAK,CAAC,kCAAkCkD,QAAQ,EAAE,CAAC;IACjE,CAAC,MAAM;MACHJ,YAAY,CAACI,QAAQ,CAAC,GAAGW,MAAM,CAACC,IAAI,CAACX,MAAM,CAACQ,WAAW,CAAC,CAAC,CAAC,CAACI,IAAI,CAAC,CAACC,QAAQ,CAAC,QAAQ,CAAC;IACvF;EACJ;EAEA,MAAMC,qBAAqB,GAAG,OAAOhC,EAAE,CAACiC,cAAc,CAACpJ,GAAG,CAAC;EAC3D,MAAMqJ,qBAAqB,GAAGF,qBAAqB,CAACzB,OAAO,CACvD,oDAAoD,EACpD,6CAA6C4B,IAAI,CAACC,SAAS,CAACvB,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CACxF;EAED,MAAMwB,aAAa,GAAG,OAAOrC,EAAE,CAACsC,kBAAkB,CAAC;IAC/CC,MAAM,EAAE,KAAK;IACbC,MAAM,EAAE,SAAS;IACjBC,SAAS,EAAErD,IAAI,CAACsD,OAAO,CAAC7J,GAAG;GAC9B,CAAC;EAEF,OAAOmH,EAAE,CAAC2C,eAAe,CAACN,aAAa,EAAEH,qBAAqB,CAAC;EAC/D,OAAO,OAAO9C,IAAI,CAACwD,SAAS,CAACP,aAAa,CAAC;AAC/C,CAAC,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@efffrida/vitest-pool",
3
- "version": "0.0.1",
4
- "description": "effect vitest-pool",
3
+ "version": "0.0.3",
4
+ "description": "effect frida vitest-pool",
5
5
  "keywords": [
6
6
  "frida.re",
7
7
  "reverse engineering",
@@ -19,8 +19,8 @@
19
19
  "type": "module",
20
20
  "exports": {
21
21
  "./package.json": "./package.json",
22
- ".": "./dist/src/index.ts",
23
- "./*": "./dist/src/*.ts",
22
+ ".": "./dist/src/index.js",
23
+ "./*": "./dist/src/*.js",
24
24
  "./internal/*": null
25
25
  },
26
26
  "files": [
@@ -31,27 +31,34 @@
31
31
  "dist/**/*.d.ts.map"
32
32
  ],
33
33
  "dependencies": {
34
- "@efffrida/frida-tools": "0.0.15"
34
+ "@vitest/runner": "4.0.16",
35
+ "@vitest/utils": "4.0.16",
36
+ "birpc": "4.0.0",
37
+ "esbuild": "0.27.2",
38
+ "flatted": "3.3.3",
39
+ "@efffrida/frida-tools": "0.0.17",
40
+ "@efffrida/polyfills": "0.0.2"
35
41
  },
36
42
  "devDependencies": {
37
- "@effect/cluster": "0.52.1",
38
- "@effect/experimental": "0.57.0",
39
- "@effect/platform": "0.93.0",
40
- "@effect/platform-node": "0.100.0",
41
- "@effect/rpc": "0.72.1",
42
- "@effect/sql": "0.48.0",
43
- "@effect/workflow": "0.12.1",
43
+ "@effect/cluster": "0.56.0",
44
+ "@effect/experimental": "0.58.0",
45
+ "@effect/platform": "0.94.0",
46
+ "@effect/platform-node": "0.104.0",
47
+ "@effect/rpc": "0.73.0",
48
+ "@effect/sql": "0.49.0",
49
+ "@effect/workflow": "0.16.0",
44
50
  "@types/frida-gum": "19.0.1",
45
- "@types/node": "24.10.0",
46
- "core-js": "3.46.0",
47
- "effect": "3.19.0",
51
+ "@types/node": "25.0.3",
52
+ "effect": "3.19.13",
48
53
  "frida": "17.5.1",
49
- "vitest": "4.0.7"
54
+ "vitest": "4.0.16"
50
55
  },
51
56
  "peerDependencies": {
52
- "@effect/platform": "0.93.0",
53
- "effect": "3.19.0",
54
- "vitest": "4.0.7"
57
+ "@effect/platform": "0.94.0",
58
+ "@vitest/runner": "4.0.16",
59
+ "@vitest/utils": "4.0.16",
60
+ "effect": "3.19.13",
61
+ "vitest": "4.0.16"
55
62
  },
56
63
  "publishConfig": {
57
64
  "access": "public"
package/src/index.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  import type * as PlatformError from "@effect/platform/Error";
2
2
  import type * as FridaDeviceAcquisitionError from "@efffrida/frida-tools/FridaDeviceAcquisitionError";
3
3
  import type * as FridaSessionError from "@efffrida/frida-tools/FridaSessionError";
4
+ import type * as Option from "effect/Option";
5
+ import type * as ParseResult from "effect/ParseResult";
4
6
  import type * as Runtime from "effect/Runtime";
5
- import type * as Frida from "frida";
6
7
  import type * as VitestNode from "vitest/node";
7
- import type { PoolWorker, WorkerRequest } from "vitest/node";
8
8
 
9
9
  import * as NodeContext from "@effect/platform-node/NodeContext";
10
10
  import * as Command from "@effect/platform/Command";
11
11
  import * as CommandExecutor from "@effect/platform/CommandExecutor";
12
+ import * as FileSystem from "@effect/platform/FileSystem";
13
+ import * as Path from "@effect/platform/Path";
12
14
  import * as FridaDevice from "@efffrida/frida-tools/FridaDevice";
13
15
  import * as FridaScript from "@efffrida/frida-tools/FridaScript";
14
16
  import * as FridaSession from "@efffrida/frida-tools/FridaSession";
@@ -21,7 +23,12 @@ import * as Layer from "effect/Layer";
21
23
  import * as ManagedRuntime from "effect/ManagedRuntime";
22
24
  import * as Match from "effect/Match";
23
25
  import * as Schema from "effect/Schema";
26
+ import * as Scope from "effect/Scope";
27
+ import * as Sink from "effect/Sink";
24
28
  import * as Stream from "effect/Stream";
29
+ import * as Esbuild from "esbuild";
30
+ import * as Flatted from "flatted";
31
+ import * as Frida from "frida";
25
32
 
26
33
  // First, pick your device
27
34
  class DeviceSchema extends Schema.Union(
@@ -64,8 +71,10 @@ class AttachSchema extends Schema.Union(
64
71
  })
65
72
  ) {}
66
73
 
74
+ // Third, pick your runtime and platform
67
75
  class ConfigSchema extends Schema.Struct({
68
- isolated: Schema.optionalWith(Schema.Boolean, { nullable: true }),
76
+ runtime: Schema.optionalWith(Schema.Literal("default", "qjs", "v8"), { nullable: true }),
77
+ platform: Schema.optionalWith(Schema.Literal("gum", "browser", "neutral"), { nullable: true }),
69
78
  })
70
79
  .pipe(Schema.extend(DeviceSchema))
71
80
  .pipe(Schema.extend(AttachSchema)) {}
@@ -74,16 +83,12 @@ class ConfigSchema extends Schema.Struct({
74
83
  * @since 1.0.0
75
84
  * @category Tests
76
85
  */
77
- export class FridaPoolWorker implements PoolWorker {
86
+ export class FridaPoolWorker implements VitestNode.PoolWorker {
78
87
  readonly name = "frida-pool";
88
+ readonly agentTemplatePath = new URL("../frida/agent.ts", import.meta.url);
79
89
 
80
- private readonly customOptions: Schema.Schema.Type<typeof ConfigSchema>;
81
- private readonly managedRuntime: ManagedRuntime.ManagedRuntime<
82
- FridaScript.FridaScript,
83
- | FridaDeviceAcquisitionError.FridaDeviceAcquisitionError
84
- | PlatformError.PlatformError
85
- | FridaSessionError.FridaSessionError
86
- >;
90
+ private readonly poolOptions: VitestNode.PoolOptions;
91
+ private readonly customOptions: Schema.Schema.Type<ConfigSchema>;
87
92
 
88
93
  private readonly cancelables: Map<
89
94
  (arg: any) => void,
@@ -95,9 +100,56 @@ export class FridaPoolWorker implements PoolWorker {
95
100
  >
96
101
  >;
97
102
 
98
- constructor(_poolOptions: VitestNode.PoolOptions, customOptions: Schema.Schema.Type<typeof ConfigSchema>) {
103
+ private modifiedAgentScope: Scope.CloseableScope;
104
+ private managedRuntime:
105
+ | ManagedRuntime.ManagedRuntime<
106
+ FridaScript.FridaScript,
107
+ | FridaDeviceAcquisitionError.FridaDeviceAcquisitionError
108
+ | PlatformError.PlatformError
109
+ | FridaSessionError.FridaSessionError
110
+ >
111
+ | undefined;
112
+ private sends: Array<
113
+ Promise<
114
+ Exit.Exit<
115
+ void,
116
+ | FridaDeviceAcquisitionError.FridaDeviceAcquisitionError
117
+ | PlatformError.PlatformError
118
+ | FridaSessionError.FridaSessionError
119
+ | ParseResult.ParseError
120
+ >
121
+ >
122
+ > = [];
123
+
124
+ constructor(poolOptions: VitestNode.PoolOptions, customOptions: Schema.Schema.Type<ConfigSchema>) {
125
+ this.poolOptions = poolOptions;
99
126
  this.customOptions = customOptions;
100
127
  this.cancelables = new Map();
128
+ this.managedRuntime = undefined;
129
+ this.modifiedAgentScope = Effect.runSync(Scope.make());
130
+ }
131
+
132
+ async start(): Promise<void> {
133
+ const tempAgentUrl = await compileTestFiles(this.agentTemplatePath, this.poolOptions)
134
+ .pipe(Scope.extend(this.modifiedAgentScope))
135
+ .pipe(Effect.provide(NodeContext.layer))
136
+ .pipe(Effect.runPromise);
137
+
138
+ const FridaRuntime = Match.value(this.customOptions.runtime).pipe(
139
+ Match.when(undefined, () => undefined),
140
+ Match.when("v8", () => Frida.ScriptRuntime.V8),
141
+ Match.when("qjs", () => Frida.ScriptRuntime.QJS),
142
+ Match.when("default", () => Frida.ScriptRuntime.Default),
143
+ Match.exhaustive
144
+ );
145
+
146
+ const FridaPlatform = Match.value(this.customOptions.platform).pipe(
147
+ Match.when(undefined, () => undefined),
148
+ Match.when("gum", () => Frida.JsPlatform.Gum),
149
+ Match.when("browser", () => Frida.JsPlatform.Browser),
150
+ Match.when("neutral", () => Frida.JsPlatform.Neutral),
151
+ Match.exhaustive
152
+ );
101
153
 
102
154
  const DeviceLive = Match.value(this.customOptions).pipe(
103
155
  Match.when({ device: "local" }, () => FridaDevice.layerLocalDevice),
@@ -145,31 +197,39 @@ export class FridaPoolWorker implements PoolWorker {
145
197
  );
146
198
 
147
199
  const FridaLive = Layer.provide(SessionLive, DeviceLive).pipe(Layer.provide(NodeContext.layer));
148
- const ScriptLive = FridaScript.layer(new URL("../frida/agent.ts", import.meta.url), {
200
+ const ScriptLive = FridaScript.layer(tempAgentUrl, {
149
201
  externals: ["jsdom", "happy-dom", "@edge-runtime/vm"],
150
- })
151
- .pipe(Layer.provide(FridaLive))
152
- .pipe(Layer.fresh);
202
+ ...(FridaRuntime !== undefined ? { runtime: FridaRuntime } : {}),
203
+ ...(FridaPlatform !== undefined ? { platform: FridaPlatform } : {}),
204
+ }).pipe(Layer.provide(FridaLive));
153
205
 
154
206
  this.managedRuntime = ManagedRuntime.make(ScriptLive);
155
- }
156
207
 
157
- async start(): Promise<void> {
158
208
  const exit = await this.managedRuntime.runPromiseExit(Effect.void);
159
209
  if (Exit.isSuccess(exit)) return;
160
- throw Cause.pretty(exit.cause, { renderErrorCause: true });
210
+ const prettyError = Cause.prettyErrors(exit.cause);
211
+ throw prettyError[0];
161
212
  }
162
213
 
163
214
  async stop(): Promise<void> {
164
- return this.managedRuntime.dispose();
215
+ await Promise.allSettled(this.sends);
216
+ await this.managedRuntime!.dispose();
217
+ await Effect.runPromise(Scope.close(this.modifiedAgentScope, Exit.void));
165
218
  }
166
219
 
167
- async send(message: WorkerRequest): Promise<void> {
168
- await this.managedRuntime.runPromise(
220
+ async send(message: VitestNode.WorkerRequest): Promise<void> {
221
+ const sendPromise = this.managedRuntime!.runPromiseExit(
169
222
  Effect.flatMap(FridaScript.FridaScript, (fridaScript) =>
170
223
  fridaScript.callExport("onMessage", Schema.Void)(message)
171
224
  )
172
225
  );
226
+
227
+ this.sends.push(sendPromise);
228
+ const exit = await sendPromise;
229
+ this.sends = this.sends.filter((p) => p !== sendPromise);
230
+ if (Exit.isSuccess(exit)) return;
231
+ const prettyError = Cause.prettyErrors(exit.cause);
232
+ throw prettyError[0];
173
233
  }
174
234
 
175
235
  on(event: string, callback: (arg: any) => void): void {
@@ -180,28 +240,38 @@ export class FridaPoolWorker implements PoolWorker {
180
240
  | FridaSessionError.FridaSessionError
181
241
  >;
182
242
 
243
+ const sink = Sink.forEach<
244
+ {
245
+ message: unknown;
246
+ data: Option.Option<Buffer<ArrayBufferLike>>;
247
+ },
248
+ void,
249
+ never,
250
+ never
251
+ >((input) =>
252
+ Effect.sync(() => {
253
+ callback(input.message);
254
+ })
255
+ );
256
+
183
257
  switch (event) {
184
258
  case "message":
185
- cancelable = this.managedRuntime.runCallback(
186
- Effect.flatMap(FridaScript.FridaScript, (fridaScript) =>
187
- fridaScript.stream.pipe(
188
- Stream.runForEach(({ message }) => Effect.sync(() => callback(message)))
189
- )
190
- )
259
+ cancelable = this.managedRuntime!.runCallback(
260
+ Effect.flatMap(FridaScript.FridaScript, (fridaScript) => Stream.run(fridaScript.stream, sink))
191
261
  );
192
262
  break;
193
263
 
194
264
  case "error":
195
- cancelable = this.managedRuntime.runCallback(
265
+ cancelable = this.managedRuntime!.runCallback(
196
266
  Effect.flatMap(FridaScript.FridaScript, (fridaScript) => Deferred.await(fridaScript.scriptError)),
197
267
  { onExit: (exit) => (Exit.isSuccess(exit) ? callback(exit.value) : callback(exit.cause)) }
198
268
  );
199
269
  break;
200
270
 
201
271
  case "exit":
202
- cancelable = this.managedRuntime.runCallback(
272
+ cancelable = this.managedRuntime!.runCallback(
203
273
  Effect.flatMap(FridaScript.FridaScript, (fridaScript) => Deferred.await(fridaScript.destroyed)),
204
- { onExit: () => callback(undefined) }
274
+ { onExit: () => callback(void 0) }
205
275
  );
206
276
  break;
207
277
 
@@ -221,6 +291,11 @@ export class FridaPoolWorker implements PoolWorker {
221
291
  }
222
292
 
223
293
  deserialize(data: unknown) {
294
+ if (typeof data !== "string") return data;
295
+ else return Flatted.parse(data);
296
+ }
297
+
298
+ serialize(data: unknown) {
224
299
  return data;
225
300
  }
226
301
  }
@@ -230,7 +305,7 @@ export class FridaPoolWorker implements PoolWorker {
230
305
  * @category Tests
231
306
  */
232
307
  export const createFridaPool = (
233
- customOptions: Schema.Schema.Encoded<typeof ConfigSchema>
308
+ customOptions: Schema.Schema.Encoded<ConfigSchema>
234
309
  ): VitestNode.PoolRunnerInitializer => {
235
310
  const decoded = Schema.decodeUnknownSync(ConfigSchema)(customOptions);
236
311
  return {
@@ -238,3 +313,198 @@ export const createFridaPool = (
238
313
  createPoolWorker: (options: VitestNode.PoolOptions) => new FridaPoolWorker(options, decoded),
239
314
  };
240
315
  };
316
+
317
+ /** @internal */
318
+ const vitestGlobalsPlugin: Esbuild.Plugin = {
319
+ name: "vitest-globals",
320
+ setup(build) {
321
+ // Handle vitest and @vitest/* imports
322
+ build.onResolve({ filter: /^(vitest|@vitest\/.*)$/ }, (args) => ({
323
+ path: args.path,
324
+ namespace: "vitest-globals",
325
+ }));
326
+
327
+ build.onLoad({ filter: /.*/, namespace: "vitest-globals" }, (args) => {
328
+ if (args.path === "vitest") {
329
+ return {
330
+ loader: "js",
331
+ contents: "export * from 'VITEST_GLOBAL';\nexport { default } from 'VITEST_GLOBAL';",
332
+ };
333
+ }
334
+ if (args.path === "@vitest/runner") {
335
+ return {
336
+ loader: "js",
337
+ contents: "export * from 'VITEST_RUNNER_GLOBAL';\nexport { default } from 'VITEST_RUNNER_GLOBAL';",
338
+ };
339
+ }
340
+ return {
341
+ loader: "js",
342
+ contents: "export * from 'VITEST_GLOBAL';\nexport { default } from 'VITEST_GLOBAL';",
343
+ };
344
+ });
345
+
346
+ build.onResolve({ filter: /^VITEST_(GLOBAL|RUNNER_GLOBAL)$/ }, (args) => ({
347
+ path: args.path,
348
+ namespace: "vitest-synthetic",
349
+ }));
350
+
351
+ build.onLoad({ filter: /.*/, namespace: "vitest-synthetic" }, (args) => {
352
+ const globalName = args.path === "VITEST_GLOBAL" ? "__vitest" : "__vitest_runner";
353
+ return {
354
+ loader: "js",
355
+ contents: `
356
+ const g = globalThis.${globalName};
357
+ export default g;
358
+ export const {
359
+ describe, it, test, expect, vi, beforeAll, afterAll,
360
+ beforeEach, afterEach, suite, bench, assert
361
+ } = g;
362
+ `,
363
+ };
364
+ });
365
+
366
+ // Handle Node.js built-in modules - redirect to globals set up by the agent
367
+ // The agent imports these from frida-compile's shims and exposes them as globals
368
+ const nodeModuleMap: Record<string, string> = {
369
+ "node:assert": "__node_assert",
370
+ "node:buffer": "__node_buffer",
371
+ "node:crypto": "__node_crypto",
372
+ "node:diagnostics_channel": "__node_diagnosticsChannel",
373
+ "node:events": "__node_events",
374
+ "node:fs": "__node_fs",
375
+ "node:net": "__node_net",
376
+ "node:os": "__node_os",
377
+ "node:path": "__node_path",
378
+ "node:process": "__node_process",
379
+ "node:stream": "__node_stream",
380
+ "node:timers": "__node_timers",
381
+ "node:tty": "__node_tty",
382
+ "node:url": "__node_url",
383
+ "node:util": "__node_util",
384
+ "node:vm": "__node_vm",
385
+ assert: "__node_assert",
386
+ buffer: "__node_buffer",
387
+ crypto: "__node_crypto",
388
+ diagnostics_channel: "__node_diagnosticsChannel",
389
+ events: "__node_events",
390
+ fs: "__node_fs",
391
+ net: "__node_net",
392
+ os: "__node_os",
393
+ path: "__node_path",
394
+ process: "__node_process",
395
+ stream: "__node_stream",
396
+ timers: "__node_timers",
397
+ tty: "__node_tty",
398
+ url: "__node_url",
399
+ util: "__node_util",
400
+ vm: "__node_vm",
401
+ };
402
+
403
+ build.onResolve(
404
+ {
405
+ filter: /^(node:)?(assert|buffer|crypto|diagnostics_channel|events|fs|net|os|path|process|stream|timers|tty|url|util|vm)$/,
406
+ },
407
+ (args) => ({
408
+ path: args.path,
409
+ namespace: "node-globals",
410
+ })
411
+ );
412
+
413
+ build.onLoad({ filter: /.*/, namespace: "node-globals" }, (args) => {
414
+ const globalName = nodeModuleMap[args.path];
415
+ if (!globalName) {
416
+ return { loader: "js", contents: "export default {};" };
417
+ }
418
+ return {
419
+ loader: "js",
420
+ contents: `
421
+ const m = globalThis.${globalName};
422
+ export default m;
423
+ export const { Buffer } = m.Buffer ? m : { Buffer: m.default?.Buffer };
424
+ export * from 'NODE_MODULE_REEXPORT_${globalName}';
425
+ `,
426
+ };
427
+ });
428
+
429
+ // Handle re-exports from node modules
430
+ build.onResolve({ filter: /^NODE_MODULE_REEXPORT_/ }, (args) => ({
431
+ path: args.path,
432
+ namespace: "node-reexport",
433
+ }));
434
+
435
+ build.onLoad({ filter: /.*/, namespace: "node-reexport" }, (args) => {
436
+ const globalName = args.path.replace("NODE_MODULE_REEXPORT_", "");
437
+ return {
438
+ loader: "js",
439
+ contents: `
440
+ const m = globalThis.${globalName};
441
+ const mod = m.default || m;
442
+ for (const key in mod) {
443
+ if (key !== 'default') {
444
+ Object.defineProperty(exports, key, {
445
+ enumerable: true,
446
+ get: () => mod[key]
447
+ });
448
+ }
449
+ }
450
+ `,
451
+ };
452
+ });
453
+ },
454
+ };
455
+
456
+ /** @internal */
457
+ const compileTestFiles = Effect.fnUntraced(function* (
458
+ agentTemplatePath: URL,
459
+ poolOptions: VitestNode.PoolOptions,
460
+ customOptions?: Schema.Schema.Type<ConfigSchema> | undefined
461
+ ): Effect.fn.Return<URL, PlatformError.PlatformError, Path.Path | FileSystem.FileSystem | Scope.Scope> {
462
+ const path = yield* Path.Path;
463
+ const fs = yield* FileSystem.FileSystem;
464
+ const url = yield* path.fromFileUrl(agentTemplatePath);
465
+
466
+ const testFiles = poolOptions.project.testFilesList ?? [];
467
+ const testFilesMap: Record<string, string> = {};
468
+
469
+ const esbuildPlatform = Match.value(customOptions?.platform).pipe(
470
+ Match.when("browser", () => "browser" as const),
471
+ Match.when("neutral", () => "neutral" as const),
472
+ Match.whenOr("gum", undefined, () => "node" as const),
473
+ Match.orElseAbsurd
474
+ );
475
+
476
+ for (const testFile of testFiles) {
477
+ const result = yield* Effect.promise(() =>
478
+ Esbuild.build({
479
+ bundle: true,
480
+ write: false,
481
+ format: "esm",
482
+ platform: esbuildPlatform,
483
+ target: "es2020",
484
+ entryPoints: [testFile],
485
+ plugins: [vitestGlobalsPlugin],
486
+ })
487
+ );
488
+
489
+ if (!result.outputFiles || result.outputFiles.length === 0) {
490
+ throw new Error(`esbuild produced no output for ${testFile}`);
491
+ } else {
492
+ testFilesMap[testFile] = Buffer.from(result.outputFiles[0].text).toString("base64");
493
+ }
494
+ }
495
+
496
+ const agentTemplateContents = yield* fs.readFileString(url);
497
+ const modifiedAgentContents = agentTemplateContents.replace(
498
+ /^const testFiles: Record<string, string> = \{\};$/m,
499
+ `const testFiles: Record<string, string> = ${JSON.stringify(testFilesMap, null, 4)};`
500
+ );
501
+
502
+ const tempAgentPath = yield* fs.makeTempFileScoped({
503
+ suffix: ".ts",
504
+ prefix: ".agent-",
505
+ directory: path.dirname(url),
506
+ });
507
+
508
+ yield* fs.writeFileString(tempAgentPath, modifiedAgentContents);
509
+ return yield* path.toFileUrl(tempAgentPath);
510
+ });