Skip to content

Commit 5f7f106

Browse files
authored
Revert "chore: shell: Separate the derivation of active pattern and space root pattern, syncing state (commontoolsinc#2188)" This reverts commit 6e979d0.
1 parent 6e979d0 commit 5f7f106

16 files changed

+887
-659
lines changed

packages/charm/src/ops/charms-controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export class CharmsController<T = unknown> {
2929
return this.#manager;
3030
}
3131

32-
async create<U = T>(
32+
async create(
3333
program: RuntimeProgram | string,
3434
options: CreateCharmOptions = {},
3535
cause: string | undefined = undefined,
36-
): Promise<CharmController<U>> {
36+
): Promise<CharmController<T>> {
3737
this.disposeCheck();
3838
const recipe = await compileProgram(this.#manager, program);
39-
const charm = await this.#manager.runPersistent<U>(
39+
const charm = await this.#manager.runPersistent<T>(
4040
recipe,
4141
options.input,
4242
cause,
@@ -45,7 +45,7 @@ export class CharmsController<T = unknown> {
4545
);
4646
await this.#manager.runtime.idle();
4747
await this.#manager.synced();
48-
return new CharmController<U>(this.#manager, charm);
48+
return new CharmController<T>(this.#manager, charm);
4949
}
5050

5151
async get<S extends JSONSchema = JSONSchema>(

packages/patterns/integration/counter.test.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CharmController, CharmsController } from "@commontools/charm/ops";
33
import { ShellIntegration } from "@commontools/integration/shell-utils";
44
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
55
import { join } from "@std/path";
6-
import { assertEquals } from "@std/assert";
6+
import { assert, assertEquals } from "@std/assert";
77
import { Identity } from "@commontools/identity";
88
import { FileSystemProgramResolver } from "@commontools/js-compiler";
99

@@ -50,34 +50,32 @@ describe("counter direct operations test", () => {
5050
identity,
5151
});
5252

53-
// Verify initial value is 0
54-
await waitFor(async () => {
55-
const counterResult = await page.waitForSelector("#counter-result", {
56-
strategy: "pierce",
57-
});
58-
const initialText = await counterResult.evaluate((el: HTMLElement) =>
59-
el.textContent
60-
);
61-
return initialText?.trim() === "Counter is the 0th number";
53+
const counterResult = await page.waitForSelector("#counter-result", {
54+
strategy: "pierce",
6255
});
56+
assert(counterResult, "Should find counter-result element");
57+
58+
// Verify initial value is 0
59+
const initialText = await counterResult.evaluate((el: HTMLElement) =>
60+
el.textContent
61+
);
62+
assertEquals(initialText?.trim(), "Counter is the 0th number");
6363

6464
assertEquals(charm.result.get(["value"]), 0);
6565
});
6666

6767
it("should update counter value via direct operation (live)", async () => {
6868
const page = shell.page();
6969

70-
await page.waitForSelector("#counter-result", {
70+
// Get the counter result element
71+
const counterResult = await page.waitForSelector("#counter-result", {
7172
strategy: "pierce",
7273
});
7374

75+
console.log("Setting counter value to 42 via direct operation");
7476
await charm.result.set(42, ["value"]);
7577

7678
await waitFor(async () => {
77-
const counterResult = await page.waitForSelector("#counter-result", {
78-
strategy: "pierce",
79-
});
80-
8179
const updatedText = await counterResult.evaluate((el: HTMLElement) =>
8280
el.textContent
8381
);
@@ -107,15 +105,19 @@ describe("counter direct operations test", () => {
107105
});
108106

109107
// Get the counter result element after refresh
110-
await waitFor(async () => {
111-
const counterResult = await page.waitForSelector("#counter-result", {
112-
strategy: "pierce",
113-
});
114-
115-
const textAfterRefresh = await counterResult.evaluate((el: HTMLElement) =>
116-
el.textContent
117-
);
118-
return textAfterRefresh?.trim() === "Counter is the 42th number";
108+
const counterResult = await page.waitForSelector("#counter-result", {
109+
strategy: "pierce",
119110
});
111+
assert(counterResult, "Should find counter-result element after refresh");
112+
113+
// Check if the UI shows the updated value after refresh
114+
const textAfterRefresh = await counterResult.evaluate((el: HTMLElement) =>
115+
el.textContent
116+
);
117+
assertEquals(
118+
textAfterRefresh?.trim(),
119+
"Counter is the 42th number",
120+
"UI should show persisted value after refresh",
121+
);
120122
});
121123
});

packages/patterns/integration/ct-checkbox.test.ts

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { env, waitFor } from "@commontools/integration";
1+
import { env } from "@commontools/integration";
2+
import { sleep } from "@commontools/utils/sleep";
23
import { ShellIntegration } from "@commontools/integration/shell-utils";
34
import { afterAll, beforeAll, describe, it } from "@std/testing/bdd";
45
import { join } from "@std/path";
6+
import { assertEquals } from "@std/assert";
57
import { Identity } from "@commontools/identity";
68
import { CharmsController } from "@commontools/charm/ops";
79
import { ANYONE_USER } from "@commontools/memory/acl";
@@ -65,62 +67,49 @@ testComponents.forEach(({ name, file }) => {
6567
it("should show disabled content initially", async () => {
6668
const page = shell.page();
6769

68-
await waitFor(async () => {
69-
const featureStatus = await page.waitForSelector("#feature-status", {
70-
strategy: "pierce",
71-
});
72-
const statusText = await featureStatus.evaluate((el: HTMLElement) =>
73-
el.textContent
74-
);
75-
return statusText?.trim() === "⚠ Feature is disabled";
70+
const featureStatus = await page.waitForSelector("#feature-status", {
71+
strategy: "pierce",
7672
});
73+
const statusText = await featureStatus.evaluate((el: HTMLElement) =>
74+
el.textContent
75+
);
76+
assertEquals(statusText?.trim(), "⚠ Feature is disabled");
7777
});
7878

7979
it("should toggle to enabled content when checkbox is clicked", async () => {
8080
const page = shell.page();
8181

82-
await waitFor(async () => {
83-
const checkbox = await page.waitForSelector("ct-checkbox", {
84-
strategy: "pierce",
85-
});
86-
// This could throw due to lacking a box model to click on.
87-
// Catch in lieu of handling time sensitivity.
88-
try {
89-
await checkbox.click();
90-
} catch (_) {
91-
return false;
92-
}
93-
const featureStatus = await page.waitForSelector("#feature-status", {
94-
strategy: "pierce",
95-
});
96-
const statusText = await featureStatus.evaluate((el: HTMLElement) =>
97-
el.textContent
98-
);
99-
return statusText?.trim() === "✓ Feature is enabled!";
82+
const checkbox = await page.waitForSelector("ct-checkbox", {
83+
strategy: "pierce",
84+
});
85+
await checkbox.click();
86+
await sleep(500);
87+
88+
const featureStatus = await page.$("#feature-status", {
89+
strategy: "pierce",
10090
});
91+
const statusText = await featureStatus?.evaluate((el: HTMLElement) =>
92+
el.textContent
93+
);
94+
assertEquals(statusText?.trim(), "✓ Feature is enabled!");
10195
});
10296

10397
it("should toggle back to disabled content when checkbox is clicked again", async () => {
10498
const page = shell.page();
105-
await waitFor(async () => {
106-
const checkbox = await page.waitForSelector("ct-checkbox", {
107-
strategy: "pierce",
108-
});
109-
// This could throw due to lacking a box model to click on.
110-
// Catch in lieu of handling time sensitivity.
111-
try {
112-
await checkbox.click();
113-
} catch (_) {
114-
return false;
115-
}
116-
const featureStatus = await page.waitForSelector("#feature-status", {
117-
strategy: "pierce",
118-
});
119-
const statusText = await featureStatus.evaluate((el: HTMLElement) =>
120-
el.textContent
121-
);
122-
return statusText?.trim() === "⚠ Feature is disabled";
99+
100+
const checkbox = await page.$("ct-checkbox", {
101+
strategy: "pierce",
102+
});
103+
await checkbox?.click();
104+
await sleep(1000);
105+
106+
const featureStatus = await page.$("#feature-status", {
107+
strategy: "pierce",
123108
});
109+
const statusText = await featureStatus?.evaluate((el: HTMLElement) =>
110+
el.textContent
111+
);
112+
assertEquals(statusText?.trim(), "⚠ Feature is disabled");
124113
});
125114
});
126115
});

0 commit comments

Comments
 (0)