Implements Phases 1-8 of the TFTSR implementation plan. Rust backend (Tauri 2.x, src-tauri/): - Multi-provider AI: OpenAI-compatible, Anthropic, Gemini, Mistral, Ollama - PII detection engine: 11 regex patterns with overlap resolution - SQLCipher AES-256 encrypted database with 10 versioned migrations - 28 Tauri IPC commands for triage, analysis, document, and system ops - Ollama: hardware probe, model recommendations, pull/delete with events - RCA and blameless post-mortem Markdown document generators - PDF export via printpdf - Audit log: SHA-256 hash of every external data send - Integration stubs for Confluence, ServiceNow, Azure DevOps (v0.2) Frontend (React 18 + TypeScript + Vite, src/): - 9 pages: full triage workflow NewIssue→LogUpload→Triage→Resolution→RCA→Postmortem→History+Settings - 7 components: ChatWindow, TriageProgress, PiiDiffViewer, DocEditor, HardwareReport, ModelSelector, UI primitives - 3 Zustand stores: session, settings (persisted), history - Type-safe tauriCommands.ts matching Rust backend types exactly - 8 IT domain system prompts (Linux, Windows, Network, K8s, DB, Virt, HW, Obs) DevOps: - .woodpecker/test.yml: rustfmt, clippy, cargo test, tsc, vitest on every push - .woodpecker/release.yml: linux/amd64 + linux/arm64 builds, Gogs release upload Verified: - cargo check: zero errors - tsc --noEmit: zero errors - vitest run: 13/13 unit tests passing Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
159 lines
5.3 KiB
JavaScript
159 lines
5.3 KiB
JavaScript
export { A as AutomockedModule, b as AutospiedModule, a as ManualMockedModule, M as MockerRegistry, R as RedirectedModule } from './chunk-registry.js';
|
|
|
|
function mockObject(options, object, mockExports = {}) {
|
|
const finalizers = new Array();
|
|
const refs = new RefTracker();
|
|
const define = (container, key, value) => {
|
|
try {
|
|
container[key] = value;
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
const mockPropertiesOf = (container, newContainer) => {
|
|
const containerType = getType(container);
|
|
const isModule = containerType === "Module" || !!container.__esModule;
|
|
for (const { key: property, descriptor } of getAllMockableProperties(
|
|
container,
|
|
isModule,
|
|
options.globalConstructors
|
|
)) {
|
|
if (!isModule && descriptor.get) {
|
|
try {
|
|
Object.defineProperty(newContainer, property, descriptor);
|
|
} catch {
|
|
}
|
|
continue;
|
|
}
|
|
if (isSpecialProp(property, containerType)) {
|
|
continue;
|
|
}
|
|
const value = container[property];
|
|
const refId = refs.getId(value);
|
|
if (refId !== void 0) {
|
|
finalizers.push(
|
|
() => define(newContainer, property, refs.getMockedValue(refId))
|
|
);
|
|
continue;
|
|
}
|
|
const type = getType(value);
|
|
if (Array.isArray(value)) {
|
|
define(newContainer, property, []);
|
|
continue;
|
|
}
|
|
const isFunction = type.includes("Function") && typeof value === "function";
|
|
if ((!isFunction || value.__isMockFunction) && type !== "Object" && type !== "Module") {
|
|
define(newContainer, property, value);
|
|
continue;
|
|
}
|
|
if (!define(newContainer, property, isFunction ? value : {})) {
|
|
continue;
|
|
}
|
|
if (isFunction) {
|
|
let mockFunction2 = function() {
|
|
if (this instanceof newContainer[property]) {
|
|
for (const { key, descriptor: descriptor2 } of getAllMockableProperties(
|
|
this,
|
|
false,
|
|
options.globalConstructors
|
|
)) {
|
|
if (descriptor2.get) {
|
|
continue;
|
|
}
|
|
const value2 = this[key];
|
|
const type2 = getType(value2);
|
|
const isFunction2 = type2.includes("Function") && typeof value2 === "function";
|
|
if (isFunction2) {
|
|
const original = this[key];
|
|
const mock2 = spyOn(this, key).mockImplementation(original);
|
|
mock2.mockRestore = () => {
|
|
mock2.mockReset();
|
|
mock2.mockImplementation(original);
|
|
return mock2;
|
|
};
|
|
}
|
|
}
|
|
}
|
|
};
|
|
if (!options.spyOn) {
|
|
throw new Error(
|
|
"[@vitest/mocker] `spyOn` is not defined. This is a Vitest error. Please open a new issue with reproduction."
|
|
);
|
|
}
|
|
const spyOn = options.spyOn;
|
|
const mock = spyOn(newContainer, property);
|
|
if (options.type === "automock") {
|
|
mock.mockImplementation(mockFunction2);
|
|
mock.mockRestore = () => {
|
|
mock.mockReset();
|
|
mock.mockImplementation(mockFunction2);
|
|
return mock;
|
|
};
|
|
}
|
|
Object.defineProperty(newContainer[property], "length", { value: 0 });
|
|
}
|
|
refs.track(value, newContainer[property]);
|
|
mockPropertiesOf(value, newContainer[property]);
|
|
}
|
|
};
|
|
const mockedObject = mockExports;
|
|
mockPropertiesOf(object, mockedObject);
|
|
for (const finalizer of finalizers) {
|
|
finalizer();
|
|
}
|
|
return mockedObject;
|
|
}
|
|
class RefTracker {
|
|
idMap = /* @__PURE__ */ new Map();
|
|
mockedValueMap = /* @__PURE__ */ new Map();
|
|
getId(value) {
|
|
return this.idMap.get(value);
|
|
}
|
|
getMockedValue(id) {
|
|
return this.mockedValueMap.get(id);
|
|
}
|
|
track(originalValue, mockedValue) {
|
|
const newId = this.idMap.size;
|
|
this.idMap.set(originalValue, newId);
|
|
this.mockedValueMap.set(newId, mockedValue);
|
|
return newId;
|
|
}
|
|
}
|
|
function getType(value) {
|
|
return Object.prototype.toString.apply(value).slice(8, -1);
|
|
}
|
|
function isSpecialProp(prop, parentType) {
|
|
return parentType.includes("Function") && typeof prop === "string" && ["arguments", "callee", "caller", "length", "name"].includes(prop);
|
|
}
|
|
function getAllMockableProperties(obj, isModule, constructors) {
|
|
const { Map: Map2, Object: Object2, Function, RegExp, Array: Array2 } = constructors;
|
|
const allProps = new Map2();
|
|
let curr = obj;
|
|
do {
|
|
if (curr === Object2.prototype || curr === Function.prototype || curr === RegExp.prototype) {
|
|
break;
|
|
}
|
|
collectOwnProperties(curr, (key) => {
|
|
const descriptor = Object2.getOwnPropertyDescriptor(curr, key);
|
|
if (descriptor) {
|
|
allProps.set(key, { key, descriptor });
|
|
}
|
|
});
|
|
} while (curr = Object2.getPrototypeOf(curr));
|
|
if (isModule && !allProps.has("default") && "default" in obj) {
|
|
const descriptor = Object2.getOwnPropertyDescriptor(obj, "default");
|
|
if (descriptor) {
|
|
allProps.set("default", { key: "default", descriptor });
|
|
}
|
|
}
|
|
return Array2.from(allProps.values());
|
|
}
|
|
function collectOwnProperties(obj, collector) {
|
|
const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
|
|
Object.getOwnPropertyNames(obj).forEach(collect);
|
|
Object.getOwnPropertySymbols(obj).forEach(collect);
|
|
}
|
|
|
|
export { mockObject };
|