This is an automated email from the ASF dual-hosted git repository. github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-9435-6a19cba6373d903071bf99348da462cafd057531 in repository https://gitbox.apache.org/repos/asf/texera.git
commit 7adc72932ed1336b2ca986a890fbebb301164e57 Author: Putluru Sandeep <[email protected]> AuthorDate: Mon Nov 16 10:07:16 2026 +0000 refactor(frontend): clean up unused config and assert helpers (#9435) ### What changes were proposed in this PR? Clean up dead methods and helpers that remain unused in the latest upstream `main` and were only referenced by their own specs, as tracked in #9195: 1. **`UserConfigService.getDict()`** in `frontend/src/app/common/service/user/config/user-config.service.ts`: - Removed the unread dictionary getter. - Refactored `user-config.service.spec.ts` to preserve complete behavioral coverage across fetch, set, delete, login, and logout using observable behavior and public interfaces (verifying that `delete()` issues an HTTP DELETE request only when the target key is present in the local cache). 2. **`GuiConfigService.source()`** in `frontend/src/app/common/service/gui-config.service.ts`: - Removed uncalled `source(name: ConfigSource)` which was superseded by memoized configuration getters (`env`). - Removed corresponding unit tests in `gui-config.service.spec.ts`. 3. **`assert()`** in `frontend/src/app/common/util/assert.ts`: - Removed uncalled `assert()` function (`asType` and `isType` type guards remain). - Removed corresponding unit tests in `assert.spec.ts`. *(Note: Per maintainer confirmation on #9195, `dictionaryChangedSubject` landed earlier in #8817 and `localRemoveObject`/`sessionRemoveObject` landed earlier in #9256; those completed changes are untouched.)* ### Any related issues, documentation, discussions? Closes #9195 ### How was this PR tested? All changes were thoroughly tested locally via the repository-standard test runner: 1. **Affected Spec Files:** - `yarn ng test --watch=false --include=src/app/common/util/assert.spec.ts` (6/6 passed) - `yarn ng test --watch=false --include=src/app/common/service/gui-config.service.spec.ts` (12/12 passed) - `yarn ng test --watch=false --include=src/app/common/service/user/config/user-config.service.spec.ts` (20/20 passed) 2. **Dependent / Downstream Spec Files:** - `yarn ng test --watch=false --include=src/app/workspace/service/preset/preset.service.spec.ts` (48/48 passed) 3. **Common Suite:** - `yarn ng test --watch=false --include="src/app/common/**/*.spec.ts"` (876/876 passed across 55 test files) 4. **Code Quality, Type-Checking, and Build:** - `yarn tsc --noEmit` (Passed with 0 errors) - `yarn tsc -p src/tsconfig.app.json --noEmit && yarn tsc -p src/tsconfig.spec.json --noEmit` (Passed with 0 errors) - `yarn format:ci` (Passed cleanly) - `yarn lint` (Passed with 0 errors) - `yarn build` (Production frontend build succeeded) - `git diff --check` (Clean) ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Antigravity IDE (Gemini 3.8 Flash) --- .../app/common/service/gui-config.service.spec.ts | 38 ------------ .../src/app/common/service/gui-config.service.ts | 6 -- .../user/config/user-config.service.spec.ts | 69 ++++++++++++++++++---- .../service/user/config/user-config.service.ts | 4 -- frontend/src/app/common/util/assert.spec.ts | 27 +-------- frontend/src/app/common/util/assert.ts | 6 -- 6 files changed, 58 insertions(+), 92 deletions(-) diff --git a/frontend/src/app/common/service/gui-config.service.spec.ts b/frontend/src/app/common/service/gui-config.service.spec.ts index 9dad79e471..9af662318c 100644 --- a/frontend/src/app/common/service/gui-config.service.spec.ts +++ b/frontend/src/app/common/service/gui-config.service.spec.ts @@ -208,44 +208,6 @@ describe("GuiConfigService", () => { await expect(pending).rejects.toThrow(/pre-login configuration/); }); - // ─── source() isolation ─────────────────────────────────────────────────── - - it("source() keeps each endpoint's payload retrievable in isolation", async () => { - const preLoginPending = firstValueFrom(service.loadPreLogin()); - http.expectOne(`${API}/config/pre-login`).flush(PRE_LOGIN_PAYLOAD); - await preLoginPending; - - const postLoginPending = firstValueFrom(service.loadPostLogin()); - http.expectOne(`${API}/config/gui`).flush(GUI_PAYLOAD); - http.expectOne(`${API}/config/amber`).flush(AMBER_PAYLOAD); - http.expectOne(`${API}/config/user-system`).flush(USER_SYSTEM_PAYLOAD); - await postLoginPending; - - expect(service.source("preLogin")).toEqual(PRE_LOGIN_PAYLOAD); - expect(service.source("gui")).toEqual(GUI_PAYLOAD); - expect(service.source("amber")).toEqual(AMBER_PAYLOAD); - expect(service.source("userSystem")).toEqual(USER_SYSTEM_PAYLOAD); - }); - - it("source() does not bleed keys across sources", async () => { - // A value from one endpoint must not appear under another. - const pending = firstValueFrom(service.loadPostLogin()); - http.expectOne(`${API}/config/gui`).flush(GUI_PAYLOAD); - http.expectOne(`${API}/config/amber`).flush(AMBER_PAYLOAD); - http.expectOne(`${API}/config/user-system`).flush(USER_SYSTEM_PAYLOAD); - await pending; - - expect(service.source("amber")).toHaveProperty("defaultDataTransferBatchSize"); - expect(service.source("gui")).not.toHaveProperty("defaultDataTransferBatchSize"); - expect(service.source("gui")).not.toHaveProperty("inviteOnly"); - // env still flattens them together for the common single-flag call sites. - expect(service.env.defaultDataTransferBatchSize).toBe(400); - }); - - it("source() returns an empty object for an endpoint that has not loaded", () => { - expect(service.source("amber")).toEqual({}); - }); - // ─── env reference stability ─────────────────────────────────────────────── it("env returns a stable reference between loads so two-way bindings persist", async () => { diff --git a/frontend/src/app/common/service/gui-config.service.ts b/frontend/src/app/common/service/gui-config.service.ts index edd22c5177..fb878783d5 100644 --- a/frontend/src/app/common/service/gui-config.service.ts +++ b/frontend/src/app/common/service/gui-config.service.ts @@ -130,12 +130,6 @@ export class GuiConfigService { return this.mergedCache; } - // One endpoint's payload, in isolation. Returns a shallow copy so callers - // cannot mutate the stored source and desync it from the memoized env view. - source(name: ConfigSource): Partial<GuiConfig> { - return { ...(this.configBySource[name] ?? {}) }; - } - // Store a source payload and invalidate the merged view. private setSource(name: ConfigSource, payload: Partial<GuiConfig>): void { this.configBySource[name] = payload; diff --git a/frontend/src/app/common/service/user/config/user-config.service.spec.ts b/frontend/src/app/common/service/user/config/user-config.service.spec.ts index f43384b5ec..cd7b3101b7 100644 --- a/frontend/src/app/common/service/user/config/user-config.service.spec.ts +++ b/frontend/src/app/common/service/user/config/user-config.service.spec.ts @@ -57,11 +57,15 @@ describe("UserConfigService", () => { }); it("starts with an empty local dictionary after the initial fetch", () => { - expect(service.getDict()).toEqual({}); + service.delete("anyKey"); + httpMock.expectNone(`${endpoint}/anyKey`); }); describe("fetchAll", () => { it("issues a GET to the config endpoint and replaces the local dictionary", () => { + service.set("prior", "zero"); + httpMock.expectOne(`${endpoint}/prior`).flush(null); + const observable = service.fetchAll(); const req = httpMock.expectOne(endpoint); @@ -71,7 +75,18 @@ describe("UserConfigService", () => { req.flush(payload); observable.subscribe(value => expect(value).toEqual(payload)); - expect(service.getDict()).toEqual(payload); + + service.delete("foo"); + httpMock.expectOne(`${endpoint}/foo`).flush(null); + + service.delete("bar"); + httpMock.expectOne(`${endpoint}/bar`).flush(null); + + service.delete("prior"); + httpMock.expectNone(`${endpoint}/prior`); + + service.delete("baz"); + httpMock.expectNone(`${endpoint}/baz`); }); it("throws when the user is not logged in", () => { @@ -91,7 +106,11 @@ describe("UserConfigService", () => { req.flush("one"); observable.subscribe(value => expect(value).toEqual("one")); - expect(service.getDict()).toEqual({ alpha: "one" }); + service.delete("alpha"); + httpMock.expectOne(`${endpoint}/alpha`).flush(null); + + service.delete("beta"); + httpMock.expectNone(`${endpoint}/beta`); }); it("throws when the user is not logged in", () => { @@ -113,7 +132,11 @@ describe("UserConfigService", () => { expect(req.request.body).toEqual("one"); req.flush(null); - expect(service.getDict()).toEqual({ alpha: "one" }); + service.delete("alpha"); + httpMock.expectOne(`${endpoint}/alpha`).flush(null); + + service.delete("beta"); + httpMock.expectNone(`${endpoint}/beta`); }); it("issues a PUT and keeps the entry when setting the same value twice", () => { @@ -123,9 +146,11 @@ describe("UserConfigService", () => { service.set("alpha", "one"); const req = httpMock.expectOne(`${endpoint}/alpha`); expect(req.request.method).toEqual("PUT"); + expect(req.request.body).toEqual("one"); req.flush(null); - expect(service.getDict()).toEqual({ alpha: "one" }); + service.delete("alpha"); + httpMock.expectOne(`${endpoint}/alpha`).flush(null); }); it("throws when the user is not logged in", () => { @@ -151,7 +176,8 @@ describe("UserConfigService", () => { expect(req.request.method).toEqual("DELETE"); req.flush(null); - expect(service.getDict()).toEqual({}); + service.delete("alpha"); + httpMock.expectNone(`${endpoint}/alpha`); }); it("is a no-op (no HTTP request) when the key is not present in the local dict", () => { @@ -179,12 +205,14 @@ describe("UserConfigService", () => { expect(() => (service as any).updateEntry(" ", "v")).toThrowError(/key cannot be empty/); // The guard runs before any mutation, so nothing was written under a // trimmed or raw form of the blank key. - expect(service.getDict()).toEqual({}); + service.delete("v"); + httpMock.expectNone(`${endpoint}/v`); }); it("leaves the dictionary untouched when told to delete a key that is absent", () => { expect(() => (service as any).updateEntry("absent", undefined)).not.toThrow(); - expect(service.getDict()).toEqual({}); + service.delete("absent"); + httpMock.expectNone(`${endpoint}/absent`); }); }); @@ -196,19 +224,36 @@ describe("UserConfigService", () => { expect(req.request.method).toEqual("GET"); req.flush({ rehydrated: "yes" }); - expect(service.getDict()).toEqual({ rehydrated: "yes" }); + service.delete("rehydrated"); + httpMock.expectOne(`${endpoint}/rehydrated`).flush(null); + + service.delete("other"); + httpMock.expectNone(`${endpoint}/other`); }); it("clears the local dictionary when the user logs out", () => { service.set("alpha", "one"); httpMock.expectOne(`${endpoint}/alpha`).flush(null); - expect(service.getDict()).toEqual({ alpha: "one" }); + // User logs out: local dictionary is reset to {} stubUserService.user = undefined; stubUserService.userChangeSubject.next(undefined); - expect(service.getDict()).toEqual({}); httpMock.expectNone(endpoint); + + // Restore authentication without triggering a re-fetch so we test the post-logout cache state directly + stubUserService.user = MOCK_USER; + + // Prove that alpha was evicted on logout: delete("alpha") sends no request + service.delete("alpha"); + httpMock.expectNone(`${endpoint}/alpha`); + + // Prove that the authenticated user CAN delete an active key, showing that the absence of + // the request above was due to cache eviction, not authentication failure + service.set("beta", "two"); + httpMock.expectOne(`${endpoint}/beta`).flush(null); + service.delete("beta"); + httpMock.expectOne(`${endpoint}/beta`).flush(null); }); }); }); @@ -241,7 +286,7 @@ describe("UserConfigService (constructed while logged out)", () => { // re-checks the login state and raises Error("user not logged in") before it // issues any request, so a constructor that skipped the guard takes the whole // service down at injection time; it never reaches a point where a request - // could be observed. (getDict() is deliberately not asserted here: it is + // could be observed. (The cached dictionary is deliberately not asserted here: it is // fixed at {} by its field initialiser and would hold either way.) expect(() => TestBed.inject(UserConfigService)).not.toThrow(); diff --git a/frontend/src/app/common/service/user/config/user-config.service.ts b/frontend/src/app/common/service/user/config/user-config.service.ts index 23a025c739..3649df4480 100644 --- a/frontend/src/app/common/service/user/config/user-config.service.ts +++ b/frontend/src/app/common/service/user/config/user-config.service.ts @@ -52,10 +52,6 @@ export class UserConfigService { }); } - public getDict(): Readonly<UserConfig> { - return this.localUserDictionary; - } - /** * get a value from the backend. * keys and values must be strings. diff --git a/frontend/src/app/common/util/assert.spec.ts b/frontend/src/app/common/util/assert.spec.ts index 53b7a56619..368fb4ad11 100644 --- a/frontend/src/app/common/util/assert.spec.ts +++ b/frontend/src/app/common/util/assert.spec.ts @@ -17,32 +17,7 @@ * under the License. */ -import { assert, asType, isType } from "./assert"; - -describe("assert", () => { - it("does not throw when the condition is true", () => { - expect(() => assert(true)).not.toThrow(); - }); - - it("throws an Error when the condition is false", () => { - expect(() => assert(false)).toThrow(Error); - }); - - it("uses the supplied message on failure", () => { - expect(() => assert(false, "boom")).toThrow("boom"); - }); - - it("throws with an empty message when none is provided", () => { - let err: unknown; - try { - assert(false); - } catch (e) { - err = e; - } - expect(err).toBeInstanceOf(Error); - expect((err as Error).message).toBe(""); - }); -}); +import { asType, isType } from "./assert"; describe("isType", () => { it("matches primitive types by typeof", () => { diff --git a/frontend/src/app/common/util/assert.ts b/frontend/src/app/common/util/assert.ts index cca4e944b5..93695b61b9 100644 --- a/frontend/src/app/common/util/assert.ts +++ b/frontend/src/app/common/util/assert.ts @@ -22,12 +22,6 @@ * They are used to provide type hints to help Typescript analyze code. */ -export function assert(condition: boolean, message?: string): void { - if (!condition) { - throw new Error(message); - } -} - interface Primitives { number: number; boolean: boolean;
