Skip to content

improve e2e resource cleanup#949

Merged
liangshuo-1 merged 1 commit into
larksuite:mainfrom
yxzhaao:fix/cleanup-created-resources
May 18, 2026
Merged

improve e2e resource cleanup#949
liangshuo-1 merged 1 commit into
larksuite:mainfrom
yxzhaao:fix/cleanup-created-resources

Conversation

@yxzhaao
Copy link
Copy Markdown
Contributor

@yxzhaao yxzhaao commented May 18, 2026

Change-Id: I3e04a82f622853549f11ac49cbd6fefa194c7c56

Summary

Changes

  • Change 1
  • Change 2

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark xxx command works as expected

Related Issues

  • None

Summary by CodeRabbit

  • Tests
    • Improved cleanup reliability across CLI e2E suites with verified deletion, polling and retry logic for drive, docs, sheets, and wiki resources.
    • Enhanced wiki workflows: recursive cleanup, better host selection, handling of layer-limit cases, and more robust copy/create assertions.
    • Consolidated identity handling (bot/user) to remove hard-coded values and standardized helper/import usage and retry behavior.

Review Change Stack

@github-actions github-actions Bot added the size/S Low-risk docs, CI, test, or chore only changes label May 18, 2026
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


zhao.yuxuan seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c369b919-dccf-462d-8f40-b525b2cf097a

📥 Commits

Reviewing files that changed from the base of the PR and between a0563d5 and 4557482.

📒 Files selected for processing (10)
  • tests/cli_e2e/base/helpers_test.go
  • tests/cli_e2e/docs/docs_create_fetch_test.go
  • tests/cli_e2e/docs/docs_update_test.go
  • tests/cli_e2e/docs/helpers_test.go
  • tests/cli_e2e/drive/helpers.go
  • tests/cli_e2e/sheets/helpers_test.go
  • tests/cli_e2e/sheets/sheets_crud_workflow_test.go
  • tests/cli_e2e/wiki/helpers_test.go
  • tests/cli_e2e/wiki/wiki_shortcut_workflow_test.go
  • tests/cli_e2e/wiki/wiki_workflow_test.go
✅ Files skipped from review due to trivial changes (1)
  • tests/cli_e2e/docs/helpers_test.go
🚧 Files skipped from review as they are similar to previous changes (9)
  • tests/cli_e2e/sheets/helpers_test.go
  • tests/cli_e2e/wiki/wiki_workflow_test.go
  • tests/cli_e2e/docs/docs_create_fetch_test.go
  • tests/cli_e2e/base/helpers_test.go
  • tests/cli_e2e/wiki/helpers_test.go
  • tests/cli_e2e/drive/helpers.go
  • tests/cli_e2e/docs/docs_update_test.go
  • tests/cli_e2e/wiki/wiki_shortcut_workflow_test.go
  • tests/cli_e2e/sheets/sheets_crud_workflow_test.go

📝 Walkthrough

Walkthrough

Centralizes Drive deletion verification, standardizes per-test DefaultAs values, updates cleanup to use new Drive helpers across base/docs/sheets, and implements recursive, poll-based wiki node deletion with corresponding test wiring changes.

Changes

E2E Test Cleanup Standardization

Layer / File(s) Summary
Drive deletion verification helpers
tests/cli_e2e/drive/helpers.go
Adds DeleteDriveResourceAndVerify, WaitDriveResourceDeleted, and IsDriveResourceDeleted to run retried delete commands and poll Drive metas until deletion is confirmed (treating 404/cleared metas as deleted).
Base, Docs, Sheets cleanup standardization
tests/cli_e2e/base/helpers_test.go, tests/cli_e2e/docs/docs_create_fetch_test.go, tests/cli_e2e/docs/docs_update_test.go, tests/cli_e2e/docs/helpers_test.go, tests/cli_e2e/sheets/helpers_test.go, tests/cli_e2e/sheets/sheets_crud_workflow_test.go
Replaces inline DefaultAs literals with local defaultAs variables and switches cleanup from clie2e.RunCmd drive +delete calls to drive.DeleteDriveResourceAndVerify with cleanup contexts.
Wiki node deletion and verification helpers
tests/cli_e2e/wiki/helpers_test.go
Adds deleteWikiNodeAndVerify, listWikiNodeChildren, waitWikiNodeDeleted, isWikiNodeDeleted, and extends findWikiNodeByToken to accept optional parent-node tokens; implements recursive child deletion and polling-based verification.
Wiki test workflow updates
tests/cli_e2e/wiki/wiki_shortcut_workflow_test.go, tests/cli_e2e/wiki/wiki_workflow_test.go
Updates tests to use createWikiNodeUnderAnyHost, capture hostNodeToken/shared tokens, use RunCmdWithRetry for copy operations, and call deleteWikiNodeAndVerify for cleanup.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • larksuite/cli#528: Introduced clie2e.CleanupContext() and clie2e.ReportCleanupFailure(...) wiring used by the updated cleanup flows.
  • larksuite/cli#401: Related docs E2E workflow changes that these test updates extend.

Suggested reviewers

  • liangshuo-1
  • fangshuyu-768

"🐰 I hopped through tests today,
Reused defaults, chased deletes away,
Polling quiet till gone,
Wiki branches pruned at dawn,
Cleanup done — I munch carrot crumbs."

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is a template placeholder with no actual content. Required sections (Summary, Changes, Test Plan, Related Issues) are unfilled stub text. Complete the description by filling in actual Summary, Changes, Test Plan details, and Related Issues information instead of template placeholders.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: improving e2e resource cleanup, which aligns with the addition of new cleanup helper functions and updates across multiple test files.
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.

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

✨ 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 and usage tips.

@yxzhaao yxzhaao force-pushed the fix/cleanup-created-resources branch from 8169174 to d66f206 Compare May 18, 2026 12:36
Copy link
Copy Markdown

@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: 2

🧹 Nitpick comments (1)
tests/cli_e2e/docs/docs_create_fetch_test.go (1)

29-35: ⚡ Quick win

Use defaultAs in bot fetch request as well.

At Line 29, principal was centralized, but the bot fetch subtest still relies on implicit defaults. Making fetch explicit avoids environment-dependent flakiness.

Suggested fix
 		result, err := clie2e.RunCmd(ctx, clie2e.Request{
 			Args: []string{
 				"docs", "+fetch",
 				"--doc", docToken,
 			},
+			DefaultAs: defaultAs,
 		})
🤖 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 `@tests/cli_e2e/docs/docs_create_fetch_test.go` around lines 29 - 35, The bot
fetch subtest is still relying on implicit principal defaults; update the fetch
call in the bot fetch subtest to explicitly pass the principal variable
defaultAs (the same one used when creating the folder/doc) and the created
docToken so the fetch request uses defaultAs rather than an environment default
(ensure the fetch invocation in the "fetch" t.Run uses defaultAs and docToken,
mirroring createDocWithRetry’s principal usage).
🤖 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 `@tests/cli_e2e/drive/helpers.go`:
- Around line 133-143: In IsDriveResourceDeleted, don’t assume ExitCode==0 means
success: parse the JSON envelope in result.Stdout (e.g., using gjson.Get on
fields like "ok" and "code") before treating an empty data.metas as proof of
deletion; if the envelope indicates failure (ok != true or code != 0) return an
error with the stdout/stderr instead of returning true, otherwise proceed to
inspect gjson.Get(result.Stdout, "data.metas").Array() as you do now.

In `@tests/cli_e2e/wiki/helpers_test.go`:
- Around line 232-234: When handling the pre-delete get_node result, don't treat
any non-zero exit as an unrecoverable failure; inspect getResult (specifically
getResult.ExitCode and getResult.Stderr/stdout) for "not found" / "already
deleted" semantics and treat those cases as success before returning. Update the
branch that currently does "if getResult.ExitCode != 0 { return getResult, nil
}" to check for those phrases (or use a small helper like isNotFound(getResult))
and only return a failure for other errors, otherwise proceed as a successful
cleanup.

---

Nitpick comments:
In `@tests/cli_e2e/docs/docs_create_fetch_test.go`:
- Around line 29-35: The bot fetch subtest is still relying on implicit
principal defaults; update the fetch call in the bot fetch subtest to explicitly
pass the principal variable defaultAs (the same one used when creating the
folder/doc) and the created docToken so the fetch request uses defaultAs rather
than an environment default (ensure the fetch invocation in the "fetch" t.Run
uses defaultAs and docToken, mirroring createDocWithRetry’s principal usage).
🪄 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

Run ID: dfa99463-c1aa-41be-b0c6-22cca156f496

📥 Commits

Reviewing files that changed from the base of the PR and between 7af616b and 8169174.

📒 Files selected for processing (10)
  • tests/cli_e2e/base/helpers_test.go
  • tests/cli_e2e/docs/docs_create_fetch_test.go
  • tests/cli_e2e/docs/docs_update_test.go
  • tests/cli_e2e/docs/helpers_test.go
  • tests/cli_e2e/drive/helpers.go
  • tests/cli_e2e/sheets/helpers_test.go
  • tests/cli_e2e/sheets/sheets_crud_workflow_test.go
  • tests/cli_e2e/wiki/helpers_test.go
  • tests/cli_e2e/wiki/wiki_shortcut_workflow_test.go
  • tests/cli_e2e/wiki/wiki_workflow_test.go

Comment thread tests/cli_e2e/drive/helpers.go
Comment thread tests/cli_e2e/wiki/helpers_test.go Outdated
@yxzhaao yxzhaao force-pushed the fix/cleanup-created-resources branch from d66f206 to a0563d5 Compare May 18, 2026 12:44
Copy link
Copy Markdown

@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

♻️ Duplicate comments (1)
tests/cli_e2e/wiki/helpers_test.go (1)

222-224: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Handle pre-delete get_node "already gone" separately from real lookup failures.

This still returns (getResult, nil) for every failed pre-delete lookup. That reports already-deleted nodes as cleanup failures and also drops the root cause for unexpected get_node errors.

Suggested fix
 	if getResult.ExitCode != 0 {
-		return getResult, nil
+		if isWikiNodeDeletedResult(getResult) {
+			getResult.ExitCode = 0
+			return getResult, nil
+		}
+		return getResult, fmt.Errorf("get wiki node %s before delete failed: exit=%d stdout=%s stderr=%s", nodeToken, getResult.ExitCode, getResult.Stdout, getResult.Stderr)
 	}
🤖 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 `@tests/cli_e2e/wiki/helpers_test.go` around lines 222 - 224, The pre-delete
lookup currently treats any non-zero getResult.ExitCode as a generic failure;
change the logic after the `if getResult.ExitCode != 0` check to inspect the
`getResult.Stdout`/`getResult.Stderr` (or combined output) for the sentinel
"already gone" message emitted by `get_node` and treat that case as a non-error
(return nil for cleanup), while for all other non-zero exits return the original
getResult and a non-nil error (preserving the root cause). Locate the code that
calls `get_node` and uses `getResult` and implement a conditional: if exit != 0
&& output contains "already gone" then continue (or return nil), else return the
getResult and an error.
🤖 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 `@tests/cli_e2e/wiki/helpers_test.go`:
- Around line 238-240: The helper is only checking result.ExitCode but must also
validate the API status carried in the JSON envelope on stdout before treating
responses as success; update the code paths that call listWikiNodeChildren and
waitWikiNodeDeleted (and the related blocks at the other ranges) to reuse the
same stdout-status check pattern used by other helpers in this file: parse
childListResult.Stdout (the JSON envelope), assert the envelope indicates
success (API status/errno == 0 or equivalent) before accessing data.* or
deciding the node still exists, and return an error/result when the stdout
envelope shows an API error even if ExitCode == 0.

---

Duplicate comments:
In `@tests/cli_e2e/wiki/helpers_test.go`:
- Around line 222-224: The pre-delete lookup currently treats any non-zero
getResult.ExitCode as a generic failure; change the logic after the `if
getResult.ExitCode != 0` check to inspect the
`getResult.Stdout`/`getResult.Stderr` (or combined output) for the sentinel
"already gone" message emitted by `get_node` and treat that case as a non-error
(return nil for cleanup), while for all other non-zero exits return the original
getResult and a non-nil error (preserving the root cause). Locate the code that
calls `get_node` and uses `getResult` and implement a conditional: if exit != 0
&& output contains "already gone" then continue (or return nil), else return the
getResult and an error.
🪄 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

Run ID: 5ede533b-fab7-4b92-8bd6-b011a8cdac59

📥 Commits

Reviewing files that changed from the base of the PR and between 8169174 and d66f206.

📒 Files selected for processing (10)
  • tests/cli_e2e/base/helpers_test.go
  • tests/cli_e2e/docs/docs_create_fetch_test.go
  • tests/cli_e2e/docs/docs_update_test.go
  • tests/cli_e2e/docs/helpers_test.go
  • tests/cli_e2e/drive/helpers.go
  • tests/cli_e2e/sheets/helpers_test.go
  • tests/cli_e2e/sheets/sheets_crud_workflow_test.go
  • tests/cli_e2e/wiki/helpers_test.go
  • tests/cli_e2e/wiki/wiki_shortcut_workflow_test.go
  • tests/cli_e2e/wiki/wiki_workflow_test.go
🚧 Files skipped from review as they are similar to previous changes (9)
  • tests/cli_e2e/docs/helpers_test.go
  • tests/cli_e2e/base/helpers_test.go
  • tests/cli_e2e/docs/docs_update_test.go
  • tests/cli_e2e/sheets/sheets_crud_workflow_test.go
  • tests/cli_e2e/sheets/helpers_test.go
  • tests/cli_e2e/wiki/wiki_shortcut_workflow_test.go
  • tests/cli_e2e/docs/docs_create_fetch_test.go
  • tests/cli_e2e/wiki/wiki_workflow_test.go
  • tests/cli_e2e/drive/helpers.go

Comment thread tests/cli_e2e/wiki/helpers_test.go
Change-Id: I3e04a82f622853549f11ac49cbd6fefa194c7c56
@yxzhaao yxzhaao force-pushed the fix/cleanup-created-resources branch from a0563d5 to 4557482 Compare May 18, 2026 14:16
@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add yxzhaao/cli#fix/cleanup-created-resources -y -g

@liangshuo-1 liangshuo-1 merged commit 315e0ab into larksuite:main May 18, 2026
15 of 16 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.79%. Comparing base (33c292c) to head (4557482).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #949      +/-   ##
==========================================
+ Coverage   66.40%   66.79%   +0.39%     
==========================================
  Files         560      564       +4     
  Lines       51548    52441     +893     
==========================================
+ Hits        34230    35030     +800     
- Misses      14455    14511      +56     
- Partials     2863     2900      +37     

☔ View full report in Codecov by Sentry.
📢 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.

@liangshuo-1 liangshuo-1 mentioned this pull request May 19, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Low-risk docs, CI, test, or chore only changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants