tftsr-devops_investigation/node_modules/@vitest/spy/dist/index.js

146 lines
4.1 KiB
JavaScript
Raw Normal View History

feat: initial implementation of TFTSR IT Triage & RCA application 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>
2026-03-15 03:36:25 +00:00
import * as tinyspy from 'tinyspy';
const mocks = /* @__PURE__ */ new Set();
function isMockFunction(fn2) {
return typeof fn2 === "function" && "_isMockFunction" in fn2 && fn2._isMockFunction;
}
function spyOn(obj, method, accessType) {
const dictionary = {
get: "getter",
set: "setter"
};
const objMethod = accessType ? { [dictionary[accessType]]: method } : method;
const stub = tinyspy.internalSpyOn(obj, objMethod);
return enhanceSpy(stub);
}
let callOrder = 0;
function enhanceSpy(spy) {
const stub = spy;
let implementation;
let instances = [];
let contexts = [];
let invocations = [];
const state = tinyspy.getInternalState(spy);
const mockContext = {
get calls() {
return state.calls;
},
get contexts() {
return contexts;
},
get instances() {
return instances;
},
get invocationCallOrder() {
return invocations;
},
get results() {
return state.results.map(([callType, value]) => {
const type = callType === "error" ? "throw" : "return";
return { type, value };
});
},
get settledResults() {
return state.resolves.map(([callType, value]) => {
const type = callType === "error" ? "rejected" : "fulfilled";
return { type, value };
});
},
get lastCall() {
return state.calls[state.calls.length - 1];
}
};
let onceImplementations = [];
let implementationChangedTemporarily = false;
function mockCall(...args) {
instances.push(this);
contexts.push(this);
invocations.push(++callOrder);
const impl = implementationChangedTemporarily ? implementation : onceImplementations.shift() || implementation || state.getOriginal() || (() => {
});
return impl.apply(this, args);
}
let name = stub.name;
stub.getMockName = () => name || "vi.fn()";
stub.mockName = (n) => {
name = n;
return stub;
};
stub.mockClear = () => {
state.reset();
instances = [];
contexts = [];
invocations = [];
return stub;
};
stub.mockReset = () => {
stub.mockClear();
implementation = () => void 0;
onceImplementations = [];
return stub;
};
stub.mockRestore = () => {
stub.mockReset();
state.restore();
implementation = void 0;
return stub;
};
stub.getMockImplementation = () => implementation;
stub.mockImplementation = (fn2) => {
implementation = fn2;
state.willCall(mockCall);
return stub;
};
stub.mockImplementationOnce = (fn2) => {
onceImplementations.push(fn2);
return stub;
};
function withImplementation(fn2, cb) {
const originalImplementation = implementation;
implementation = fn2;
state.willCall(mockCall);
implementationChangedTemporarily = true;
const reset = () => {
implementation = originalImplementation;
implementationChangedTemporarily = false;
};
const result = cb();
if (result instanceof Promise) {
return result.then(() => {
reset();
return stub;
});
}
reset();
return stub;
}
stub.withImplementation = withImplementation;
stub.mockReturnThis = () => stub.mockImplementation(function() {
return this;
});
stub.mockReturnValue = (val) => stub.mockImplementation(() => val);
stub.mockReturnValueOnce = (val) => stub.mockImplementationOnce(() => val);
stub.mockResolvedValue = (val) => stub.mockImplementation(() => Promise.resolve(val));
stub.mockResolvedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.resolve(val));
stub.mockRejectedValue = (val) => stub.mockImplementation(() => Promise.reject(val));
stub.mockRejectedValueOnce = (val) => stub.mockImplementationOnce(() => Promise.reject(val));
Object.defineProperty(stub, "mock", {
get: () => mockContext
});
state.willCall(mockCall);
mocks.add(stub);
return stub;
}
function fn(implementation) {
const enhancedSpy = enhanceSpy(tinyspy.internalSpyOn({
spy: implementation || function() {
}
}, "spy"));
if (implementation) {
enhancedSpy.mockImplementation(implementation);
}
return enhancedSpy;
}
export { fn, isMockFunction, mocks, spyOn };