mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-04 02:00:10 +00:00
test(plugin-sdk): mutate API baseline sources after declaration emission
614aa3acff removed the separate getDeclarationDiagnostics pass; declaration
errors now come from the in-memory emit result. The API baseline mutation test
still spied on the removed call, so its source change never happened and the
render resolved. Hook declaration emission, the final compiler stage before
the boundary check, so a late source change is still rejected.
This commit is contained in:
parent
436edc486d
commit
2b2ae319c9
1 changed files with 9 additions and 7 deletions
|
|
@ -577,7 +577,7 @@ describe("Plugin SDK API baseline", () => {
|
|||
expect(fixtureError).not.toContain("return this.status");
|
||||
});
|
||||
|
||||
it.each(["source project creation", "declaration diagnostics"])(
|
||||
it.each(["source project creation", "declaration emission"])(
|
||||
"rejects source changes after %s while accepting linked external types",
|
||||
async (timing) => {
|
||||
const repoRoot = tempDirs.make("openclaw-plugin-sdk-api-mutation-");
|
||||
|
|
@ -639,7 +639,8 @@ describe("Plugin SDK API baseline", () => {
|
|||
.join("/");
|
||||
const createProject = nativeTypeScript.createNativeTypeScriptProject;
|
||||
const create = vi.spyOn(nativeTypeScript, "createNativeTypeScriptProject");
|
||||
const diagnose = vi.spyOn(Program.prototype, "getDeclarationDiagnostics");
|
||||
// Declaration errors come from the emit result, the last compiler stage before publication.
|
||||
const emit = vi.spyOn(Program.prototype, "emitToString");
|
||||
if (timing === "source project creation") {
|
||||
create.mockImplementationOnce(function intercept(options) {
|
||||
const native = createProject(options);
|
||||
|
|
@ -652,13 +653,14 @@ describe("Plugin SDK API baseline", () => {
|
|||
return native;
|
||||
});
|
||||
} else {
|
||||
diagnose.mockImplementationOnce(async function (this: Program, ...args) {
|
||||
diagnose.mockRestore();
|
||||
const result = await this.getDeclarationDiagnostics(...args);
|
||||
emit.mockImplementationOnce(async function (this: Program, ...args) {
|
||||
emit.mockRestore();
|
||||
const result = await this.emitToString(...args);
|
||||
expect(
|
||||
(await this.getSourceFileNames()).some((file) => path.resolve(file) === entry),
|
||||
).toBe(true);
|
||||
expect(result).toEqual([]);
|
||||
expect(result.emitSkipped).toBe(false);
|
||||
expect(result.diagnostics).toEqual([]);
|
||||
changeSource();
|
||||
return result;
|
||||
});
|
||||
|
|
@ -667,7 +669,7 @@ describe("Plugin SDK API baseline", () => {
|
|||
await expect(render()).rejects.toThrow(/Boundary .*changed during compilation/u);
|
||||
} finally {
|
||||
create.mockRestore();
|
||||
diagnose.mockRestore();
|
||||
emit.mockRestore();
|
||||
}
|
||||
expect(changed).toBe(true);
|
||||
expect(fs.readFileSync(entry, "utf8")).toBe(source("changed"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue