Skip to content

test(core): update Dim.func tests to verify dependency tracking#2329

Open
suhaniiz wants to merge 1 commit into
Karanjot786:mainfrom
suhaniiz:fix/dim-func-dependencies
Open

test(core): update Dim.func tests to verify dependency tracking#2329
suhaniiz wants to merge 1 commit into
Karanjot786:mainfrom
suhaniiz:fix/dim-func-dependencies

Conversation

@suhaniiz

@suhaniiz suhaniiz commented Jul 10, 2026

Copy link
Copy Markdown

Description

This PR fixes a bug where Dim.func() did not track layout dependency flags. It updates the method to accept an optional dependencies array parameter so that the terminal UI layout engine can accurately flag and schedule conditional recalculations when contextual sizes shift.

Related Issue

Closes #2326

Which package(s)?

@termuijs/core

Type of Change

  • 🐛 Bug fix (type:bug)
  • ✨ Feature (type:feature)
  • 📝 Docs (type:docs)
  • 🧪 Tests (type:testing)
  • ♻️ Refactor (type:refactor)
  • 🎨 Design / UX (type:design)
  • ♿ Accessibility (type:accessibility)
  • ⚡ Performance (type:performance)
  • 🔧 DevOps / CI (type:devops)
  • 🔒 Security (type:security)

Checklist

  • ⭐ You starred the repo. The needs-star check blocks your merge otherwise.
  • Tests pass locally: bun vitest run
  • Build passes: bun run build
  • Typecheck passes: bun run typecheck
  • You read CONTRIBUTING.md.
  • Your PR title follows type: short description.
  • Widget state mutators call markDirty() (if your change affects rendering).
  • No new any types without an inline comment explaining why.
  • No unrelated refactors bundled into this PR.

GSSoC 2026 Participation

  • You are a GSSoC 2026 contributor.
  • Your GSSoC profile: https://gssoc.girlscript.org/profile/suhaniiz

Screenshots / Recordings (UI changes)

Notes for the Reviewer

The fix updates the Dim.func(fn, deps = []) signature to properly capture dependency values rather than defaulting internally to an empty tracking collection. Corresponding test coverage has been added to dim.test.ts to assert that dependencies are properly tracked through the evaluation lifecycle.

Summary by CodeRabbit

  • Tests
    • Updated layout calculation tests to verify dependency metadata.
    • Continued validating that the dimension evaluation returns the expected result.

@suhaniiz suhaniiz requested a review from Karanjot786 as a code owner July 10, 2026 14:32
@github-actions github-actions Bot added the needs-star PR author has not starred the repo. label Jul 10, 2026
@github-actions

Copy link
Copy Markdown

Hi @suhaniiz 👋

Star this repo before your PR merges.

Why? GSSoC 2026 contributors who star get priority review and points credit. After you star, push any commit (or re-run this check). The needs-star label lifts automatically.

Thanks for your contribution to TermUI.

@github-actions github-actions Bot added type:testing +10 pts. Tests. area:core @termuijs/core and removed needs-star PR author has not starred the repo. labels Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Dim.func() unit test now passes an explicit parentSize dependency, verifies dependency reporting, and continues asserting evaluation returns 50.

Changes

Dim.func dependency validation

Layer / File(s) Summary
Validate dependency metadata and evaluation
packages/core/src/layout/dim.test.ts
The test supplies parentSize, asserts it appears in dependencies(), and retains the expected evaluation result.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related issues

  • #2327 — Concerns Dim.func() dependency metadata and may be addressed by the validated dependency behavior in this change.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Issue #2326 requires Dim.func() dependency tracking, but this PR only updates tests and does not implement the behavior. Update the Dim.func() implementation to accept and expose dependency arrays, then keep the test asserting .dependencies() includes parentSize.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, follows the required type: summary style, and matches the Dim.func dependency-tracking test update.
Description check ✅ Passed The PR description follows the template with description, related issue, package, type, checklist, and reviewer notes.
Out of Scope Changes check ✅ Passed The change set stays focused on Dim.func dependency tracking tests and does not introduce unrelated refactors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎉 Thanks for your first PR to TermUI, @suhaniiz.

Before your PR merges:

  1. Star the repo. Required. The star-check job blocks your merge otherwise.
  2. ✅ All checks green: build, test, typecheck.
  3. 🏷 PR title follows type: short description. Example: fix: handle empty list.
  4. 🔗 Link your closing issue in the description.

GSSoC 2026 points come from labels after merge:

  • gssoc:approved. +50 base points.
  • level:beginner / intermediate / advanced / critical. +20 / +35 / +55 / +80.
  • quality:clean / exceptional. x 1.2 / x 1.5.
  • type:*. Stackable bonus.

Your reviewer responds within 48 hours. Ping @Karanjot786 on Discord for urgent help.

🚀 Welcome to the cohort.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/layout/dim.test.ts`:
- Around line 36-38: Update Dim.func to accept an optional dependency list and
pass it into the created DimFunc; update DimFunc.dependencies() to return the
supplied dependencies instead of always returning an empty array. Ensure
existing calls without dependencies remain supported and the Dim.func dependency
test passes.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d2186e05-45d6-42b9-bac4-665387f1fdce

📥 Commits

Reviewing files that changed from the base of the PR and between 65d1f7e and 2b09d89.

📒 Files selected for processing (1)
  • packages/core/src/layout/dim.test.ts

Comment on lines +36 to +38
it('Dim.func() uses custom lambda and tracks dependencies', () => {
const func = Dim.func(ctx => ctx.parentWidth / 2, ['parentSize']);
expect(func.dependencies()).toContain('parentSize');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether Dim.func has been updated to accept a dependencies array
ast-grep outline packages/core/src/layout/dim.ts --match 'func' --view expanded

# Check the current DimFunc class implementation
ast-grep run --pattern 'static func($_): Dim {
  $$$
}' --lang typescript packages/core/src/layout/dim.ts

# Check DimFunc.dependencies implementation
ast-grep run --pattern 'class DimFunc extends Dim {
  $$$
  dependencies() {
    $$$
  }
  $$$
}' --lang typescript packages/core/src/layout/dim.ts

Repository: Karanjot786/TermUI

Length of output: 1218


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== dim.test.ts ==\n'
sed -n '1,120p' packages/core/src/layout/dim.test.ts | cat -n

printf '\n== dim.ts ==\n'
sed -n '1,140p' packages/core/src/layout/dim.ts | cat -n

Repository: Karanjot786/TermUI

Length of output: 3774


Dim.func still needs dependency support
Dim.func(ctx => ctx.parentWidth / 2, ['parentSize']) passes a second argument that Dim.func() does not accept, and DimFunc.dependencies() still returns []. This test will fail until the implementation matches the new API.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/layout/dim.test.ts` around lines 36 - 38, Update Dim.func
to accept an optional dependency list and pass it into the created DimFunc;
update DimFunc.dependencies() to return the supplied dependencies instead of
always returning an empty array. Ensure existing calls without dependencies
remain supported and the Dim.func dependency test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core @termuijs/core type:testing +10 pts. Tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] : Dim.func() lacks layout dependency tracking

1 participant