From 5058746828e94e9b3d432ea3c736c886dd694784 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 7 Oct 2025 12:33:15 -0400 Subject: [PATCH 1/3] visibility: correctly apply name template in recursive update -> createorupdate --- packages/compiler/src/lib/visibility.ts | 4 ++- packages/compiler/test/visibility.test.ts | 42 +++++++++++++---------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/compiler/src/lib/visibility.ts b/packages/compiler/src/lib/visibility.ts index b746dd3b4e2..a66222530bb 100644 --- a/packages/compiler/src/lib/visibility.ts +++ b/packages/compiler/src/lib/visibility.ts @@ -480,7 +480,9 @@ export const $withLifecycleUpdate: WithLifecycleUpdateDecorator = ( any: new Set([lifecycle.members.get("Create")!, lifecycle.members.get("Update")!]), }; - const createOrUpdateMutator = createVisibilityFilterMutator(lifecycleCreateOrUpdate); + const createOrUpdateMutator = createVisibilityFilterMutator(lifecycleCreateOrUpdate, { + nameTemplate, + }); mutator = createVisibilityFilterMutator(lifecycleUpdate, { recur: createOrUpdateMutator, diff --git a/packages/compiler/test/visibility.test.ts b/packages/compiler/test/visibility.test.ts index 82a2d892dfd..4fb16920619 100644 --- a/packages/compiler/test/visibility.test.ts +++ b/packages/compiler/test/visibility.test.ts @@ -737,31 +737,33 @@ describe("compiler: visibility core", () => { @invisible(Lifecycle) invisible: string; - nested: { - @visibility(${Lifecycle.Read}) - r: string; + nested: Nested; + } - cru: string; + model Nested { + @visibility(${Lifecycle.Read}) + r: string; - @visibility(${Lifecycle.Create}, ${Lifecycle.Read}) - cr: string; + cru: string; - @visibility(${Lifecycle.Create}, ${Lifecycle.Update}) - cu: string; + @visibility(${Lifecycle.Create}, ${Lifecycle.Read}) + cr: string; + + @visibility(${Lifecycle.Create}, ${Lifecycle.Update}) + cu: string; - @visibility(${Lifecycle.Create}) - c: string; + @visibility(${Lifecycle.Create}) + c: string; - @visibility(${Lifecycle.Update}, ${Lifecycle.Read}) - ru: string; + @visibility(${Lifecycle.Update}, ${Lifecycle.Read}) + ru: string; - @visibility(${Lifecycle.Update}) - u: string; + @visibility(${Lifecycle.Update}) + u: string; - @invisible(Lifecycle) - invisible: string; - }; - } + @invisible(Lifecycle) + invisible: string; + }; // This ensures the transforms are non-side-effecting. model ReadExample is Read; @@ -1280,6 +1282,7 @@ function validateCreateOrUpdateTransform( ok(nested); ok(nested.type.kind === "Model"); + ok(nested.type.name === "CreateOrUpdateNested"); const nestedProps = getProperties(nested.type); @@ -1333,6 +1336,7 @@ function validateUpdateTransform( ok(nested); ok(nested.type.kind === "Model"); + ok(nested.type.name === "UpdateNested"); // Nested properties work differently in Lifecycle Update transforms, requiring nested create-only properties to // additionally be visible @@ -1388,6 +1392,7 @@ function validateCreateTransform( ok(nested); ok(nested.type.kind === "Model"); + ok(nested.type.name === "CreateNested"); const nestedProps = getProperties(nested.type); @@ -1442,6 +1447,7 @@ function validateReadTransform( ok(nested); ok(nested.type.kind === "Model"); + ok(nested.type.name === "ReadNested"); const nestedProps = getProperties(nested.type); From 505395145450488ea805397cb51a12e278edf378 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 7 Oct 2025 12:34:13 -0400 Subject: [PATCH 2/3] chronus --- .chronus/changes/main-2025-9-7-12-33-46.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/main-2025-9-7-12-33-46.md diff --git a/.chronus/changes/main-2025-9-7-12-33-46.md b/.chronus/changes/main-2025-9-7-12-33-46.md new file mode 100644 index 00000000000..17f8c080270 --- /dev/null +++ b/.chronus/changes/main-2025-9-7-12-33-46.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/compiler" +--- + +Addressed an issue where applying the `Update` visibility transform would not correctly rename nested models. \ No newline at end of file From 0a80afb4036c8659786ab7ff925bf890f04a47ed Mon Sep 17 00:00:00 2001 From: Will Temple Date: Tue, 28 Oct 2025 11:10:52 -0400 Subject: [PATCH 3/3] ok -> strictEqual --- packages/compiler/test/visibility.test.ts | 62 +++++++++++------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/compiler/test/visibility.test.ts b/packages/compiler/test/visibility.test.ts index 4fb16920619..0f39db5576f 100644 --- a/packages/compiler/test/visibility.test.ts +++ b/packages/compiler/test/visibility.test.ts @@ -204,7 +204,7 @@ describe("compiler: visibility core", () => { removeVisibilityModifiers(runner.program, x, [Create]); clearVisibilityModifiersForClass(runner.program, x, Lifecycle); - ok(runner.program.diagnostics.length === 3); + strictEqual(runner.program.diagnostics.length, 3); expectDiagnostics(runner.program.diagnostics, [ { @@ -890,7 +890,7 @@ describe("compiler: visibility core", () => { const A = ref.type; - ok(A.kind === "Model"); + strictEqual(A.kind, "Model"); const a = A.properties.get("a"); const b = A.properties.get("b"); @@ -1013,14 +1013,14 @@ describe("compiler: visibility core", () => { const dataA = DataA.properties.get("data_a")!; const dataB = DataB.properties.get("data_b")!; - ok(dataA.type.kind === "Model"); - ok(dataB.type.kind === "Model"); + strictEqual(dataA.type.kind, "Model"); + strictEqual(dataB.type.kind, "Model"); const FooA = dataA.type as Model; const FooB = dataB.type as Model; - ok(FooA.name === "FooA"); - ok(FooB.name === "FooB"); + strictEqual(FooA.name, "FooA"); + strictEqual(FooB.name, "FooB"); ok(FooA.properties.has("foo_a")); ok(!FooA.properties.has("foo_b")); @@ -1072,8 +1072,8 @@ describe("compiler: visibility core", () => { ok(a); ok(b); - ok(a.type.kind === "Model"); - ok(b.type.kind === "Model"); + strictEqual(a.type.kind, "Model"); + strictEqual(b.type.kind, "Model"); const A = a.type as Model; const B = b.type as Model; @@ -1093,20 +1093,20 @@ describe("compiler: visibility core", () => { ok(aC); ok(bC); - ok(aC.type === bC.type); + strictEqual(aC.type, bC.type); let C = aC.type as Model; - ok(C.kind === "Model"); - ok(C.name === "ReadC"); + strictEqual(C.kind, "Model"); + strictEqual(C.name, "ReadC"); ok(!C.properties.has("invisible")); ok(C.properties.has("c")); C = bC.type as Model; - ok(C.kind === "Model"); - ok(C.name === "ReadC"); + strictEqual(C.kind, "Model"); + strictEqual(C.name, "ReadC"); ok(!C.properties.has("invisible")); ok(C.properties.has("c")); @@ -1137,7 +1137,7 @@ describe("compiler: visibility core", () => { strictEqual(aB.kind, "Model"); - ok(aB === B); + strictEqual(aB, B); }); it("correctly transforms arrays and records", async () => { @@ -1168,8 +1168,8 @@ describe("compiler: visibility core", () => { const arrayType = array.type; const recordType = record.type; - ok(arrayType.kind === "Model"); - ok(recordType.kind === "Model"); + strictEqual(arrayType.kind, "Model"); + strictEqual(recordType.kind, "Model"); ok($(runner.program).array.is(arrayType)); ok($(runner.program).record.is(recordType)); @@ -1177,13 +1177,13 @@ describe("compiler: visibility core", () => { const arrayA = (arrayType as Model).indexer!.value as Model; const recordA = (recordType as Model).indexer!.value as Model; - ok(arrayA.kind === "Model"); - ok(recordA.kind === "Model"); + strictEqual(arrayA.kind, "Model"); + strictEqual(recordA.kind, "Model"); - ok(arrayA.name === "ATransform"); - ok(recordA.name === "ATransform"); + strictEqual(arrayA.name, "ATransform"); + strictEqual(recordA.name, "ATransform"); - ok(arrayA === recordA); + strictEqual(arrayA, recordA); ok(arrayA.properties.has("a")); ok(!arrayA.properties.has("invisible")); @@ -1221,8 +1221,8 @@ describe("compiler: visibility core", () => { const arrType = arr.type; const recType = rec.type; - ok(arrType.kind === "Model"); - ok(recType.kind === "Model"); + strictEqual(arrType.kind, "Model"); + strictEqual(recType.kind, "Model"); ok($(runner.program).array.is(arrType)); ok($(runner.program).record.is(recType)); @@ -1281,8 +1281,8 @@ function validateCreateOrUpdateTransform( const nested = Result.properties.get("nested"); ok(nested); - ok(nested.type.kind === "Model"); - ok(nested.type.name === "CreateOrUpdateNested"); + strictEqual(nested.type.kind, "Model"); + strictEqual(nested.type.name, "CreateOrUpdateNested"); const nestedProps = getProperties(nested.type); @@ -1335,8 +1335,8 @@ function validateUpdateTransform( const nested = Result.properties.get("nested"); ok(nested); - ok(nested.type.kind === "Model"); - ok(nested.type.name === "UpdateNested"); + strictEqual(nested.type.kind, "Model"); + strictEqual(nested.type.name, "UpdateNested"); // Nested properties work differently in Lifecycle Update transforms, requiring nested create-only properties to // additionally be visible @@ -1391,8 +1391,8 @@ function validateCreateTransform( const nested = Result.properties.get("nested"); ok(nested); - ok(nested.type.kind === "Model"); - ok(nested.type.name === "CreateNested"); + strictEqual(nested.type.kind, "Model"); + strictEqual(nested.type.name, "CreateNested"); const nestedProps = getProperties(nested.type); @@ -1446,8 +1446,8 @@ function validateReadTransform( const nested = Result.properties.get("nested"); ok(nested); - ok(nested.type.kind === "Model"); - ok(nested.type.name === "ReadNested"); + strictEqual(nested.type.kind, "Model"); + strictEqual(nested.type.name, "ReadNested"); const nestedProps = getProperties(nested.type);