Skip to content

refactor(web-ui): extract session trash methods#67

Closed
awsl233777 wants to merge 1 commit intomainfrom
chore/web-ui-token-friendly-structure-v2
Closed

refactor(web-ui): extract session trash methods#67
awsl233777 wants to merge 1 commit intomainfrom
chore/web-ui-token-friendly-structure-v2

Conversation

@awsl233777
Copy link
Copy Markdown
Collaborator

@awsl233777 awsl233777 commented Apr 3, 2026

Summary

  • extract session-trash/settings-tab methods from web-ui/app.js into web-ui/modules/session-trash.methods.mjs
  • keep UI behavior unchanged while shrinking the giant app file and reducing the context future edits need to read
  • update unit tests so they validate the modularized session-trash surface instead of coupling to a single massive file

Why

This change is intentionally aimed at lowering future AI edit cost rather than doing cosmetic cleanup.

It improves that by:

  • reducing one of the largest web-ui files
  • isolating a cohesive feature slice behind a smaller module boundary
  • keeping the refactor behavior-preserving and regression-covered

Validation

  • npm test

Summary by CodeRabbit

  • Chores
    • Refactored session trash implementation into a dedicated module to improve organization; no user-facing behavior changes.
  • Tests
    • Updated unit tests to exercise the session trash methods from the new module and verify all session-trash actions (load, load more, restore, purge, clear, counts, view state) continue to work as before.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

@coderabbitai re-review
Stop making breaking changes, do a proper review!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

Session-trash method implementations were moved out of web-ui/app.js into web-ui/modules/session-trash.methods.mjs (exporting createSessionTrashMethods), and unit tests were updated to import and use the new factory instead of extracting methods from app.js. No public API signatures were changed.

Changes

Cohort / File(s) Summary
Session Trash Module (new)
web-ui/modules/session-trash.methods.mjs
Added export function createSessionTrashMethods({ api, constants = {} } = {}) returning all session-trash UI methods: loaders (count/list), per-item actions (restore/purge), clear-all, item construction, pagination/visible-count helpers, request-token handling, and view-state helpers.
App Integration
web-ui/app.js
Removed inline session-trash method implementations (~354 lines) and added import { createSessionTrashMethods } ... then injected methods via ...createSessionTrashMethods({ api, constants: { sessionTrashListLimit, sessionTrashPageSize } }); retained data fields/constants.
Tests — config tabs
tests/unit/config-tabs-ui.test.mjs
Updated assertions to reference sessionTrashMethods loaded from web-ui/modules/session-trash.methods.mjs; added checks that app.js now uses createSessionTrashMethods via spread call.
Tests — session trash state
tests/unit/session-trash-state.test.mjs
Replaced regex/extraction-based instantiation with direct dynamic import of createSessionTrashMethods and a local createSessionTrashTestMethods(api, constants) wrapper; tests now call returned methods directly and pass api + constants instead of rebinding.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant App as App (Vue)
participant Factory as createSessionTrashMethods
participant API as Backend API
participant User as User
User->>App: trigger trash action / open settings
App->>Factory: call created methods (e.g., loadSessionTrash / restore)
Factory->>API: send request (list/count/restore/purge)
API-->>Factory: response (items / status)
Factory-->>App: update sessionTrash state / totals / messages
App-->>User: render updated trash state

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • SurviveM
  • ymkiux

Poem

🐰 Hop-hop, a module sprung from the mess,

Methods packed neat, no more tangled stress,
Load, purge, restore — all in their den,
A tidy burrow for sessions again! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactoring: extracting session trash methods from app.js into a new module, which is the primary change across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/web-ui-token-friendly-structure-v2

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.42.0)
web-ui/app.js

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

@github-actions[bot], I acknowledge the feedback. I'll re-review PR #67 with strict adherence to the maintainer's constraint: no breaking changes — feedback will be limited to correctness, safety, and quality only within the existing design, without suggesting refactors or alterations to APIs, interfaces, or behavior.


✏️ Learnings added
Learnt from: github-actions[bot]
URL: https://github.com/SakuraByteCore/codexmate/pull/67

Timestamp: 2026-04-03T10:42:22.344Z
Learning: In PR `#67` for SakuraByteCore/codexmate, github-actions[bot] flagged that CodeRabbit was again introducing breaking changes. The maintainer's absolute constraint (reinforced across PRs `#55`, `#59`, `#67`) is: no breaking changes in any review suggestion; limit all feedback to correctness, safety, and quality only within the existing design, without refactoring or altering APIs, interfaces, or behavior.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: github-actions[bot]
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-03-30T04:47:15.339Z
Learning: In PR `#55` for SakuraByteCore/codexmate, github-actions[bot] repeatedly flagged that CodeRabbit was introducing breaking changes. The maintainer's absolute constraint is: no breaking changes in any review suggestion; limit all feedback to correctness, safety, and quality only within the existing design, without refactoring or altering APIs, interfaces, or behavior.

Learnt from: github-actions[bot]
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-03-31T12:37:50.988Z
Learning: In PR `#59` for SakuraByteCore/codexmate, github-actions[bot] repeatedly flagged that CodeRabbit was introducing breaking changes. The maintainer's absolute constraint is: no breaking changes in any review suggestion; limit all feedback to correctness, safety, and quality only within the existing design, without refactoring or altering APIs, interfaces, or behavior.

Learnt from: SurviveM
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-03-29T02:42:32.761Z
Learning: The repository maintainer SurviveM (GitHub: SurviveM, repo: SakuraByteCore/codexmate) prefers that CodeRabbit review suggestions do not introduce breaking changes. Reviews should focus on correctness, safety, and quality without recommending refactors or changes that would break existing APIs, interfaces, or behavior.
✅ Actions performed

Full review triggered.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/config-tabs-ui.test.mjs (1)

145-146: These assertions still verify source text, not the extracted module contract.

readProjectFile() + regex will still pass if createSessionTrashMethods stops exporting cleanly, fails to parse, or returns the wrong surface. A small smoke test that imports the factory and exercises one or two methods would give this refactor real regression coverage.

Example smoke-test direction
+import { createSessionTrashMethods } from '../../web-ui/modules/session-trash.methods.mjs';
+
+test('session trash factory exposes a usable surface', () => {
+    const methods = createSessionTrashMethods({
+        api: async () => ({ items: [], totalCount: 0 })
+    });
+
+    assert.strictEqual(methods.normalizeSettingsTab('trash'), 'trash');
+    assert.strictEqual(typeof methods.loadSessionTrash, 'function');
+    assert.strictEqual(typeof methods.restoreSessionTrash, 'function');
+});

Also applies to: 229-252

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/config-tabs-ui.test.mjs` around lines 145 - 146, The tests
currently use readProjectFile() + regex to assert source text, which doesn't
verify the actual exported contract; replace those assertions by importing the
built module and exercising the factory: dynamically import the module that
exports createSessionTrashMethods, call createSessionTrashMethods(...) to get
the methods object, assert the presence of expected method names and types, and
perform a small smoke call on one method to verify behavior and signature; apply
the same change to the other assertions that follow the same pattern (the block
that currently mirrors lines 229-252).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web-ui/modules/session-trash.methods.mjs`:
- Around line 76-81: When sessionTrashLoading is true, instead of returning
immediately after stashing sessionTrashPendingOptions, change the logic in
loadSessionTrash to merge pending options so that "stronger" refresh flags
(e.g., forceRefresh: true) win (use boolean OR for flags rather than last-write
merge), store/return a pending promise (e.g., sessionTrashPendingPromise) that
will resolve only after the queued reload completes, and have the eventual
reload clear the pending promise/options when finished; update callers that
await loadSessionTrash (restore/purge/clear) to await this promise so they
remain busy until the actual refresh runs.

---

Nitpick comments:
In `@tests/unit/config-tabs-ui.test.mjs`:
- Around line 145-146: The tests currently use readProjectFile() + regex to
assert source text, which doesn't verify the actual exported contract; replace
those assertions by importing the built module and exercising the factory:
dynamically import the module that exports createSessionTrashMethods, call
createSessionTrashMethods(...) to get the methods object, assert the presence of
expected method names and types, and perform a small smoke call on one method to
verify behavior and signature; apply the same change to the other assertions
that follow the same pattern (the block that currently mirrors lines 229-252).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1afe1872-501f-4e68-8f51-d47b6a0febc6

📥 Commits

Reviewing files that changed from the base of the PR and between 02514bd and 44a6e45.

📒 Files selected for processing (4)
  • tests/unit/config-tabs-ui.test.mjs
  • tests/unit/session-trash-state.test.mjs
  • web-ui/app.js
  • web-ui/modules/session-trash.methods.mjs
📜 Review details
🔇 Additional comments (4)
web-ui/app.js (1)

35-35: Nice extraction seam.

Spreading the factory back into methods keeps the rest of web-ui/app.js on the same this.* surface while shrinking the monolithic file.

Also applies to: 3204-3210

tests/unit/session-trash-state.test.mjs (3)

4-4: ESM module loading update looks correct.

Using pathToFileURL(...).href for dynamic import is a solid cross-platform approach here, and the module destructuring is clean.

Also applies to: 17-18


200-202: Good test-factory abstraction.

createSessionTrashTestMethods is a clean wrapper that reduces repetition and keeps the module boundary explicit in tests.


537-539: Session-trash tests are well migrated to the extracted module surface.

These updates consistently exercise createSessionTrashMethods via the helper and keep constants wiring explicit where needed, which aligns well with the behavior-preserving refactor objective.

Also applies to: 585-589, 653-654, 719-719, 748-763, 1726-1729, 1892-1898, 1969-1976

Comment on lines +76 to +81
if (this.sessionTrashLoading) {
this.sessionTrashPendingOptions = {
...(this.sessionTrashPendingOptions || {}),
...(options || {})
};
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Queued reloads shouldn’t resolve before the refresh actually runs.

When sessionTrashLoading is already true, this branch returns immediately after stashing sessionTrashPendingOptions. The callers at Lines 139, 174, and 206 await loadSessionTrash(), so restore/purge/clear can drop their busy state before the queued refresh runs. The last-write-wins merge also lets a later { forceRefresh: false } overwrite an earlier forced refresh, which can re-show stale cached trash state after a mutation.

The queued path should preserve the strongest refresh flags and return a promise that resolves only after the pending reload completes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web-ui/modules/session-trash.methods.mjs` around lines 76 - 81, When
sessionTrashLoading is true, instead of returning immediately after stashing
sessionTrashPendingOptions, change the logic in loadSessionTrash to merge
pending options so that "stronger" refresh flags (e.g., forceRefresh: true) win
(use boolean OR for flags rather than last-write merge), store/return a pending
promise (e.g., sessionTrashPendingPromise) that will resolve only after the
queued reload completes, and have the eventual reload clear the pending
promise/options when finished; update callers that await loadSessionTrash
(restore/purge/clear) to await this promise so they remain busy until the actual
refresh runs.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
web-ui/modules/session-trash.methods.mjs (1)

75-81: ⚠️ Potential issue | 🟠 Major

Queued trash reload returns before the queued refresh actually finishes.

When loadSessionTrash() is called during an in-flight load, Lines 76-81 only stash sessionTrashPendingOptions and return. The mutation handlers at Lines 139, 174, and 206 all await this method, so their busy state is cleared before the forced refresh actually runs. The plain spread merge also lets a later { forceRefresh: false } overwrite an earlier forced refresh, which can leave stale trash data visible after restore/purge/clear. Please preserve the strongest queued flags and return a promise that resolves only after the queued reload kicked off from Lines 117-120 completes.

Also applies to: 117-120

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web-ui/modules/session-trash.methods.mjs` around lines 75 - 81, The
loadSessionTrash function is returning early when a load is in-flight, which
only stashes sessionTrashPendingOptions and lets callers proceed before the
queued reload finishes; fix by making the queue preserve the strongest flags
(e.g., merge forceRefresh with OR so true wins) and return a promise that
resolves when the queued reload actually completes. Concretely: in
loadSessionTrash, instead of a plain spread merge into
sessionTrashPendingOptions, merge options so boolean flags like forceRefresh use
logical OR (forceRefresh = (existing.forceRefresh || new.forceRefresh)), store a
sessionTrashPendingPromise when enqueuing the pending load, and return that
promise; when the in-flight load finishes and the code re-invokes
loadSessionTrash with sessionTrashPendingOptions (the existing queued-reload
kickoff block), resolve sessionTrashPendingPromise only after that reload
completes and clear sessionTrashPendingOptions/sessionTrashPendingPromise.
Ensure you reference and update the existing symbols: loadSessionTrash,
sessionTrashLoading, sessionTrashPendingOptions and add/use
sessionTrashPendingPromise so awaiting callers only proceed after the actual
queued reload finishes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@web-ui/modules/session-trash.methods.mjs`:
- Around line 75-81: The loadSessionTrash function is returning early when a
load is in-flight, which only stashes sessionTrashPendingOptions and lets
callers proceed before the queued reload finishes; fix by making the queue
preserve the strongest flags (e.g., merge forceRefresh with OR so true wins) and
return a promise that resolves when the queued reload actually completes.
Concretely: in loadSessionTrash, instead of a plain spread merge into
sessionTrashPendingOptions, merge options so boolean flags like forceRefresh use
logical OR (forceRefresh = (existing.forceRefresh || new.forceRefresh)), store a
sessionTrashPendingPromise when enqueuing the pending load, and return that
promise; when the in-flight load finishes and the code re-invokes
loadSessionTrash with sessionTrashPendingOptions (the existing queued-reload
kickoff block), resolve sessionTrashPendingPromise only after that reload
completes and clear sessionTrashPendingOptions/sessionTrashPendingPromise.
Ensure you reference and update the existing symbols: loadSessionTrash,
sessionTrashLoading, sessionTrashPendingOptions and add/use
sessionTrashPendingPromise so awaiting callers only proceed after the actual
queued reload finishes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3b9a9d8c-7521-46b4-a940-125424365d34

📥 Commits

Reviewing files that changed from the base of the PR and between 02514bd and 44a6e45.

📒 Files selected for processing (4)
  • tests/unit/config-tabs-ui.test.mjs
  • tests/unit/session-trash-state.test.mjs
  • web-ui/app.js
  • web-ui/modules/session-trash.methods.mjs
📜 Review details
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: github-actions[bot]
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-04-03T10:42:22.344Z
Learning: In PR `#67` for SakuraByteCore/codexmate, github-actions[bot] flagged that CodeRabbit was again introducing breaking changes. The maintainer's absolute constraint (reinforced across PRs `#55`, `#59`, `#67`) is: no breaking changes in any review suggestion; limit all feedback to correctness, safety, and quality only within the existing design, without refactoring or altering APIs, interfaces, or behavior.
Learnt from: github-actions[bot]
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-03-31T12:37:50.988Z
Learning: In PR `#59` for SakuraByteCore/codexmate, github-actions[bot] repeatedly flagged that CodeRabbit was introducing breaking changes. The maintainer's absolute constraint is: no breaking changes in any review suggestion; limit all feedback to correctness, safety, and quality only within the existing design, without refactoring or altering APIs, interfaces, or behavior.
Learnt from: github-actions[bot]
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-03-30T04:47:15.339Z
Learning: In PR `#55` for SakuraByteCore/codexmate, github-actions[bot] repeatedly flagged that CodeRabbit was introducing breaking changes. The maintainer's absolute constraint is: no breaking changes in any review suggestion; limit all feedback to correctness, safety, and quality only within the existing design, without refactoring or altering APIs, interfaces, or behavior.
Learnt from: SurviveM
Repo: SakuraByteCore/codexmate PR: 0
File: :0-0
Timestamp: 2026-03-29T02:42:32.761Z
Learning: The repository maintainer SurviveM (GitHub: SurviveM, repo: SakuraByteCore/codexmate) prefers that CodeRabbit review suggestions do not introduce breaking changes. Reviews should focus on correctness, safety, and quality without recommending refactors or changes that would break existing APIs, interfaces, or behavior.
🔇 Additional comments (4)
tests/unit/config-tabs-ui.test.mjs (1)

146-252: LGTM!

The test correctly validates the refactored module structure:

  • Confirms app.js now defines and spreads createSessionTrashMethods
  • Verifies the session-trash method signatures exist in the new session-trash.methods.mjs module

The pattern assertions appropriately track where each piece of functionality now resides.

tests/unit/session-trash-state.test.mjs (3)

4-4: LGTM!

The dynamic import pattern correctly uses pathToFileURL to convert the file path to a URL, which is the proper approach for ESM dynamic imports in Node.js. The top-level await is valid given the .mjs extension.

Also applies to: 17-18


200-202: LGTM!

Clean helper function that provides a consistent interface for tests to obtain session-trash methods from the new module factory.


537-539: LGTM!

The test updates consistently use createSessionTrashTestMethods() to obtain methods from the new module instead of extracting them from app.js source strings. The test logic and assertions remain unchanged, ensuring behavior-preserving coverage of the refactored code.

Also applies to: 584-589, 653-654, 718-719, 746-763, 892-898, 969-976, 1726-1729

@ymkiux ymkiux closed this Apr 4, 2026
@ymkiux ymkiux deleted the chore/web-ui-token-friendly-structure-v2 branch April 5, 2026 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants