Skip to content

fix: write skills-state.json updated_at in local timezone#1777

Open
zhangheng023 wants to merge 2 commits into
mainfrom
fix/skill-state-local-time
Open

fix: write skills-state.json updated_at in local timezone#1777
zhangheng023 wants to merge 2 commits into
mainfrom
fix/skill-state-local-time

Conversation

@zhangheng023

@zhangheng023 zhangheng023 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

lark-cli update writes updated_at into the local skill-sync state file (skills-state.json) using a fixed UTC timestamp regardless of the host's timezone. This PR switches it to the local timezone so the timestamp is meaningful to a human reading the file.

Changes

  • internal/skillscheck/sync.go: drop .UTC() on both UpdatedAt assignments (incremental-sync path and fallback-install path) so opts.Now().Format(time.RFC3339) reflects the local timezone
  • internal/skillscheck/sync_test.go: add two tests asserting a non-UTC injected clock is written verbatim (e.g. +08:00, not Z)
  • internal/qualitygate/{diff,publiccontent,rules}: retry TempDir cleanup for test-created git repos, fixing an unrelated pre-existing flaky "directory not empty" failure caused by a local git hook racing with test cleanup

Test Plan

  • go test ./internal/skillscheck/... -v passed
  • go build ./... passed
  • validate passed (build, vet, unit tests, integration tests)
  • acceptance-reviewer passed (3/3 cases): verified both the incremental-sync and fallback-install code paths under a real (non-UTC) system clock, plus the UTC-local-timezone backward-compat case

Related Issues

N/A

Summary by CodeRabbit

  • Bug Fixes

    • Improved Git test cleanup to avoid intermittent failures caused by lingering repository writes during temporary-directory removal.
    • Timestamp values are now saved with the local timezone instead of always converting to UTC.
  • Tests

    • Updated existing Git-related test setups to use the new cleanup-safe repository helper.
    • Added coverage to verify timestamps are written in local time for both normal and fallback sync flows.

Local git tooling that hooks trace2 (e.g. a global trace2.eventtarget
socket listener) can asynchronously write into a repo's .git/ shortly
after a git command runs. This races with t.TempDir's automatic
RemoveAll cleanup and intermittently fails tests with "directory not
empty", unrelated to the code under test.
@zhangheng023 zhangheng023 requested a review from liangshuo-1 as a code owner July 7, 2026 06:19
@zhangheng023 zhangheng023 added the bugfix Bug fixes label Jul 7, 2026
@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Jul 7, 2026
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Test files in qualitygate (diff, publiccontent, rules) add a newGitTestRepo(t) helper that retries directory removal to avoid races with asynchronous git tooling, replacing t.TempDir() calls. Separately, internal/skillscheck/sync.go changes SkillsState.UpdatedAt to format using local time rather than UTC, with corresponding new tests.

Changes

Git test repo cleanup helper

Layer / File(s) Summary
Diff test cleanup helper
internal/qualitygate/diff/diff_test.go
Adds time import, a newGitTestRepo(t) helper with retrying os.RemoveAll cleanup, and switches two tests to use it.
Publiccontent test cleanup helper
internal/qualitygate/publiccontent/collect_test.go
Adds time import and newGitTestRepo(t) helper; updates newGitRepo and multiple Collect tests to use it instead of t.TempDir().
Rules test cleanup helper
internal/qualitygate/rules/run_test.go
Adds time import and newGitTestRepo(t) helper; updates multiple Run*/manifest-loading tests to use it instead of t.TempDir().

Estimated code review effort: 2 (Simple) | ~10 minutes

SkillsState UpdatedAt Timezone Fix

Layer / File(s) Summary
Local timezone formatting and tests
internal/skillscheck/sync.go, internal/skillscheck/sync_test.go
SyncSkills and fallbackFullInstall now format UpdatedAt with opts.Now().Format(time.RFC3339) instead of converting to UTC first; new tests assert the local offset (e.g. +08:00) appears in the persisted state.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • larksuite/cli#1042: Both PRs modify internal/skillscheck/sync.go's persisted SkillsState.UpdatedAt RFC3339 timestamp handling.

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: writing skills-state updated_at in the local timezone.
Description check ✅ Passed The description matches the template and includes Summary, Changes, Test Plan, and Related Issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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 fix/skill-state-local-time

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.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.46%. Comparing base (869a259) to head (e011322).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1777      +/-   ##
==========================================
+ Coverage   74.43%   74.46%   +0.03%     
==========================================
  Files         854      855       +1     
  Lines       88490    88568      +78     
==========================================
+ Hits        65867    65954      +87     
+ Misses      17554    17543      -11     
- Partials     5069     5071       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@e01132227dfcbb6216cdeeb40212daba7d35499e

🧩 Skill update

npx skills add larksuite/cli#fix/skill-state-local-time -y -g

@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.

🧹 Nitpick comments (1)
internal/qualitygate/diff/diff_test.go (1)

143-161: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting newGitTestRepo into a shared test helper.

This exact helper (comment, retry loop, and cleanup logic) is duplicated verbatim in internal/qualitygate/publiccontent/collect_test.go and internal/qualitygate/rules/run_test.go. Consolidating into a shared internal test-support package under internal/qualitygate would avoid triple maintenance if the retry strategy ever needs tuning.

The retry/cleanup logic itself is correct: t.Cleanup registered after t.TempDir()'s own cleanup runs first (LIFO), so the retry loop removes the tree before t.TempDir's cleanup runs, making it a no-op.

🤖 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 `@internal/qualitygate/diff/diff_test.go` around lines 143 - 161, The
`newGitTestRepo` helper is duplicated verbatim across multiple test files, so
extract it into a shared internal test-support helper under
`internal/qualitygate` and update the callers to use that shared function. Keep
the existing `t.TempDir`, `t.Cleanup`, retry loop, and
`os.RemoveAll`/`time.Sleep` behavior intact in the shared helper so
`diff_test.go`, `collect_test.go`, and `run_test.go` all rely on one
implementation.
🤖 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.

Nitpick comments:
In `@internal/qualitygate/diff/diff_test.go`:
- Around line 143-161: The `newGitTestRepo` helper is duplicated verbatim across
multiple test files, so extract it into a shared internal test-support helper
under `internal/qualitygate` and update the callers to use that shared function.
Keep the existing `t.TempDir`, `t.Cleanup`, retry loop, and
`os.RemoveAll`/`time.Sleep` behavior intact in the shared helper so
`diff_test.go`, `collect_test.go`, and `run_test.go` all rely on one
implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 595f1c26-2443-462e-b9c2-050a6309adff

📥 Commits

Reviewing files that changed from the base of the PR and between f0b6f35 and e011322.

📒 Files selected for processing (5)
  • internal/qualitygate/diff/diff_test.go
  • internal/qualitygate/publiccontent/collect_test.go
  • internal/qualitygate/rules/run_test.go
  • internal/skillscheck/sync.go
  • internal/skillscheck/sync_test.go

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

Labels

bugfix Bug fixes size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant