From 836e08483a37ac40639148de2b47e4907ef056fe Mon Sep 17 00:00:00 2001 From: iletai Date: Mon, 2 Nov 2026 21:36:10 +0700 Subject: [PATCH] chore: adopt Git Flow release process and open source community files - CONTRIBUTING (branch model, release steps), CODE_OF_CONDUCT (Contributor Covenant 2.1), SECURITY - release workflow: tag must be on main, notes taken from CHANGELOG section, prerelease for -suffix tags - CI runs on release/** and hotfix/** branches; checkout@v7 everywhere - .spi.yml for Swift Package Index docs; issue template config, drop empty custom template - remove internal docs/superpowers planning notes; CHANGELOG uses [Unreleased] --- .github/ISSUE_TEMPLATE/config.yml | 8 + .github/ISSUE_TEMPLATE/custom.md | 10 - .github/workflows/ci.yml | 8 +- .github/workflows/release.yml | 28 +- .spi.yml | 4 + CHANGELOG.md | 5 +- CODE_OF_CONDUCT.md | 85 ++++++ CONTRIBUTING.md | 47 +++ README.md | 15 +- SECURITY.md | 14 + .../2026-10-19-base-navigation-stack-2.0.md | 284 ------------------ ...19-navigation-container-and-performance.md | 136 --------- ...gation-container-and-performance-design.md | 54 ---- 13 files changed, 198 insertions(+), 500 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/config.yml delete mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .spi.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 SECURITY.md delete mode 100644 docs/superpowers/plans/2026-10-19-base-navigation-stack-2.0.md delete mode 100644 docs/superpowers/plans/2026-10-19-navigation-container-and-performance.md delete mode 100644 docs/superpowers/specs/2026-10-19-navigation-container-and-performance-design.md diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..7386051 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: Question or idea + url: https://github.com/iletai/BaseNavigationStack/discussions + about: Ask questions and discuss ideas in GitHub Discussions. + - name: Security vulnerability + url: https://github.com/iletai/BaseNavigationStack/security/advisories/new + about: Report security issues privately. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md deleted file mode 100644 index 48d5f81..0000000 --- a/.github/ISSUE_TEMPLATE/custom.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -name: Custom issue template -about: Describe this issue template's purpose here. -title: '' -labels: '' -assignees: '' - ---- - - diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 823dd8a..4839e07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [main, develop] + branches: [main, develop, 'release/**', 'hotfix/**'] pull_request: - branches: [main, develop] + branches: [main, develop, 'release/**', 'hotfix/**'] concurrency: group: ci-${{ github.ref }} @@ -79,7 +79,7 @@ jobs: platform: [tvOS, watchOS, visionOS] steps: - name: Checkout Repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Select Xcode uses: maxim-lobanov/setup-xcode@v1 @@ -98,7 +98,7 @@ jobs: runs-on: macos-26 steps: - name: Checkout Repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Select Xcode uses: maxim-lobanov/setup-xcode@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b93cc94..e0a7e97 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,6 +16,31 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Verify Tag Is On main + run: | + git fetch origin main + if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then + echo "::error::Tag ${GITHUB_REF_NAME} is not on main. Release from main only (see CONTRIBUTING.md)." + exit 1 + fi + + - name: Extract Release Notes From CHANGELOG + run: | + VERSION="${GITHUB_REF_NAME#v}" + awk -v ver="$VERSION" ' + index($0, "## [" ver "]") == 1 { found = 1; next } + found && /^## \[/ { exit } + found && /^\[[^]]+\]: / { exit } + found { print } + ' CHANGELOG.md > "$RUNNER_TEMP/notes.md" + if [ ! -s "$RUNNER_TEMP/notes.md" ]; then + echo "::error::No '## [$VERSION]' section in CHANGELOG.md" + exit 1 + fi + cat "$RUNNER_TEMP/notes.md" - name: Select Xcode uses: maxim-lobanov/setup-xcode@v1 @@ -31,6 +56,7 @@ jobs: - name: Create Release uses: softprops/action-gh-release@v3 with: - generate_release_notes: true + body_path: ${{ runner.temp }}/notes.md + prerelease: ${{ contains(github.ref_name, '-') }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.spi.yml b/.spi.yml new file mode 100644 index 0000000..85e03b8 --- /dev/null +++ b/.spi.yml @@ -0,0 +1,4 @@ +version: 1 +builder: + configs: + - documentation_targets: [BaseNavigationStack] diff --git a/CHANGELOG.md b/CHANGELOG.md index 254623d..1a43855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project are documented here. Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow [SemVer](https://semver.org). -## [2.0.0] - Unreleased +## [Unreleased] ### Added - `NavigationRouter`: one `@MainActor @Observable` router for stack, sheet, and cover. @@ -29,3 +29,6 @@ All notable changes to this project are documented here. Format follows [Keep a ## [1.0.3] - 2023-12-24 Last 1.x release (`BaseNavigationStack` + `BaseViewProtocol`). + +[Unreleased]: https://github.com/iletai/BaseNavigationStack/compare/1.0.3...develop +[1.0.3]: https://github.com/iletai/BaseNavigationStack/releases/tag/1.0.3 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..3e1a68b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,85 @@ + +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement by contacting the maintainer [@iletai](https://github.com/iletai) through a [private GitHub security advisory](https://github.com/iletai/BaseNavigationStack/security/advisories/new) or direct message. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c4eed53 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,47 @@ +# Contributing + +Thanks for helping improve BaseNavigationStack. Please read the [Code of Conduct](CODE_OF_CONDUCT.md) first. + +## Branches + +The project uses Git Flow: + +| Branch | Purpose | +| --- | --- | +| `develop` | Integration branch and default branch. All pull requests target `develop`. | +| `release/x.y.z` | Short-lived branch that freezes a version: CHANGELOG date and docs only, no new features. | +| `main` | Stable branch. Only receives merges from `release/*` (or `hotfix/*`). Every commit on `main` is a released version. | +| `feature/*`, `fix/*`, `docs/*`, `chore/*` | Work branches, created from `develop`. | +| `hotfix/x.y.z` | Urgent fix created from `main`, merged into `main` and back into `develop`. | + +## Pull requests + +1. Branch from `develop`. +2. Use [Conventional Commits](https://www.conventionalcommits.org) (`feat:`, `fix:`, `docs:`, `chore:`, `ci:`, `refactor:`, `test:`). +3. Add or update tests, and add an entry under `## [Unreleased]` in [CHANGELOG.md](CHANGELOG.md) for user-visible changes. +4. Before pushing: + ```bash + swift test + swiftlint --strict + ``` +5. CI must pass (macOS, iOS Simulator, tvOS, watchOS, visionOS, example app, SwiftLint). + +## Versioning + +[Semantic Versioning](https://semver.org). Tags have no `v` prefix (`2.0.0`, `2.0.1`). Removing or changing public API requires a major version. + +## Release process (maintainers) + +1. From an up-to-date `develop`, create `release/x.y.z`. +2. In `CHANGELOG.md`, rename `## [Unreleased]` to `## [x.y.z] - YYYY-MM-DD` and add a fresh empty `## [Unreleased]` above it. +3. Open a pull request `release/x.y.z` → `main`. After CI passes, merge with a **merge commit**. +4. Tag the merge commit on `main` and push the tag: + ```bash + git checkout main && git pull + git tag -a x.y.z -m "x.y.z" + git push origin x.y.z + ``` + The `Release` workflow checks that the tag is on `main` and listed in `CHANGELOG.md`, runs the tests, and publishes a GitHub Release with that CHANGELOG section as notes. +5. Merge `main` back into `develop` (pull request `main` → `develop`) so the CHANGELOG date reaches `develop`. + +Never move or delete a published tag: Swift Package Manager caches resolved versions. diff --git a/README.md b/README.md index 2db3d43..7747637 100644 --- a/README.md +++ b/README.md @@ -358,23 +358,18 @@ xcodebuild test -scheme BaseNavigationStack -destination "id=$SIM_ID" CODE_SIGNI ## Docs & Wiki -- **Design Specs:** [`docs/superpowers/specs/`](docs/superpowers/specs/) — Container, async ergonomics, performance goals. -- **Implementation Plans:** [`docs/superpowers/plans/`](docs/superpowers/plans/) — Step-by-step rollout notes. - **GitHub Wiki:** [BaseNavigationStack Wiki](https://github.com/iletai/BaseNavigationStack/wiki) — Extended guides, migration notes, and FAQs (if enabled). - **Issues:** [Report bugs / request features](https://github.com/iletai/BaseNavigationStack/issues) - **Discussions:** [Community Q&A](https://github.com/iletai/BaseNavigationStack/discussions) ## Contributing -Contributions are welcome! +Contributions are welcome. Pull requests target `develop`; releases are cut from `release/x.y.z` branches into `main` and tagged there. -1. **Fork** the repo and create a feature branch off `develop`. -2. **Follow style** — Match existing Swift style; CI runs `swiftlint --strict`. -3. **Test** — Add/update tests for behavior changes. Run `swift test` locally. -4. **Commit** — Use clear, conventional commits (`feat:`, `fix:`, `refactor:`, `test:`, `docs:`). -5. **Open a PR** — Target `develop` with a concise description and test notes. - -See [`.github/PULL_REQUEST_TEMPLATE.md`](.github/PULL_REQUEST_TEMPLATE.md) and [`.github/ISSUE_TEMPLATE/`](.github/ISSUE_TEMPLATE/) for details. +- [CONTRIBUTING.md](CONTRIBUTING.md) — branch model, commit style, local checks, release process. +- [CHANGELOG.md](CHANGELOG.md) — version history. +- [SECURITY.md](SECURITY.md) — report vulnerabilities privately. +- [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) ## License diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..444b53c --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,14 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +| ------- | --------- | +| 2.x | Yes | +| 1.x | No | + +## Reporting a Vulnerability + +Please do **not** open a public issue for security problems. + +Report privately through [GitHub Security Advisories](https://github.com/iletai/BaseNavigationStack/security/advisories/new). You should get a first response within 7 days. Once a fix is released, the advisory is published with credit to the reporter unless you prefer otherwise. diff --git a/docs/superpowers/plans/2026-10-19-base-navigation-stack-2.0.md b/docs/superpowers/plans/2026-10-19-base-navigation-stack-2.0.md deleted file mode 100644 index e4302a4..0000000 --- a/docs/superpowers/plans/2026-10-19-base-navigation-stack-2.0.md +++ /dev/null @@ -1,284 +0,0 @@ -# BaseNavigationStack 2.0 Implementation Plan - -> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. - -**Goal:** Nâng cấp toàn diện thư viện `BaseNavigationStack` lên phiên bản 2.0: Swift 6 Strict Concurrency, hợp nhất quản lý Stack/Sheet/Cover theo chuẩn `@Observable`, bảo vệ chống lỗi race condition/thao tác người dùng, bao phủ 100% test case lồng nhau (nested navigation) và thiết lập CI/CD GitHub Actions chuẩn Open-Source. - -**Architecture:** Sử dụng Clean Architecture và mô hình Router hướng dữ liệu (Data-Driven Navigation) thuần SwiftUI không phụ thuộc UIKit hay bên thứ ba. Lớp router trung tâm `@MainActor @Observable public final class NavigationRouter` quản lý state ba chiều (`path`, `sheet`, `cover`) độc lập, cung cấp các View modifier declarative giúp tích hợp O(1) vào bất kỳ SwiftUI View tree nào. - -**Tech Stack:** Swift 6.0+, macOS 14+, iOS 17+, SwiftUI, Observation framework, Swift Testing / XCTest, GitHub Actions, SwiftLint. - -**Spec:** Kế hoạch này hiện thực hóa toàn bộ các cải tiến từ quá trình audit codebase 2023, khắc phục bug logic `dismiss()`, loại bỏ ràng buộc đa associated type trong `BaseViewProtocol`, và thiết lập pipeline tự động hóa CI/CD cho Swift Package. - -## Global Constraints - -- **Dependency Limit:** Tuyệt đối 0 external dependencies (chỉ dùng standard library, Foundation, SwiftUI, Observation). -- **Platform Floors:** iOS 17.0+, macOS 14.0+. -- **Language Mode:** Swift 6 mode (`SWIFT_STRICT_CONCURRENCY = complete`, không để lọt bất kỳ warning hay error nào về actor isolation/Sendable). -- **Thread Safety:** Toàn bộ Router state mutations phải được cô lập trên `@MainActor`. -- **Backward Compatibility:** Cung cấp typealias và deprecation warnings thích hợp nếu cần hỗ trợ dự án cũ nâng cấp mượt mà. - -## Review Focus - -1. **Bug Dismiss khi path chỉ có 1 phần tử:** `dismiss()` phải pop được phần tử duy nhất trong `path` thay vì trigger dismiss root container. -2. **State Inconsistency khi Replace Path:** Khi thay thế `path`, toàn bộ modal active (`sheet`, `cover`) phải được tự động dọn dẹp để tránh modal đè lên flow mới. -3. **Double-Push / Rapid Tapping Race Condition:** Ngăn chặn việc append cùng một route liên tiếp trong cùng một chu kỳ runloop/animation khi người dùng tap nhanh nhiều lần. -4. **Nested Navigation Flow Lifecycle:** Khi một màn hình mở Sheet, và bên trong Sheet lại chứa một `NavigationRouter` con có stack riêng, việc dismiss từ bên trong hay bên ngoài phải giữ state cô lập và không rò rỉ bộ nhớ. -5. **Observation Direct Binding:** Không bọc thủ công `Binding(get:set:)`, tận dụng tối đa macro `@Bindable` của SwiftUI trên `@Observable`. - ---- - -### Task 1: Nâng cấp Toolchain và Package Manifest (P0) - -**Files:** -- Modify: `Package.swift` -- Modify: `Sources/BaseNavigationStack/Utils/Collection+Extension.swift` - -**Interfaces:** -- Consumes: Standard Swift Package Manager manifest format -- Produces: Package hỗ trợ `.macOS(.v14)`, `.iOS(.v17)` với `swift-tools-version: 6.0` - -- [ ] **Step 1: Viết test kiểm tra build trên môi trường macOS 14+** - -Chạy: `swift build` trên repo gốc -Expected: FAIL do macOS 13 không tương thích `@Observable`. - -- [ ] **Step 2: Cập nhật Package.swift lên Swift 6.0 và dọn dẹp extension thừa** - -Cập nhật `Package.swift`: -```swift -// swift-tools-version: 6.0 -import PackageDescription - -let package = Package( - name: "BaseNavigationStack", - platforms: [ - .macOS(.v14), .iOS(.v17) - ], - products: [ - .library( - name: "BaseNavigationStack", - targets: ["BaseNavigationStack"] - ), - ], - targets: [ - .target( - name: "BaseNavigationStack", - swiftSettings: [ - .enableUpcomingFeature("StrictConcurrency") - ] - ), - .testTarget( - name: "BaseNavigationStackTests", - dependencies: ["BaseNavigationStack"] - ), - ] -) -``` - -Xóa helper thừa `removeAllSafe()` trong `Sources/BaseNavigationStack/Utils/Collection+Extension.swift` (vì `Array.removeAll()` vốn đã an toàn). - -- [ ] **Step 3: Chạy swift build để xác nhận lỗi platform được giải quyết** - -Run: `cd /Users/lequangtrongtai/orca/BaseNavigationStack && swift build` -Expected: Build thành công hoặc chỉ còn warnings về code v1 cũ. - -- [ ] **Step 4: Commit thay đổi task 1** - -```bash -git add Package.swift Sources/BaseNavigationStack/Utils/Collection+Extension.swift -git commit -m "build: upgrade package manifest to swift 6.0 and macos 14" -``` - ---- - -### Task 2: Core NavigationRouter 2.0 (Swift 6 & Observation) (P0) - -**Files:** -- Modify: `Sources/BaseNavigationStack/BaseNavigationStack.swift` -- Modify: `Sources/BaseNavigationStack/Interface/BaseViewProtocol.swift` -- Modify: `Sources/BaseNavigationStack/StackObject/BaseNavigationStack+ViewObject.swift` - -**Interfaces:** -- Consumes: `Observation`, `SwiftUI` -- Produces: - ```swift - @MainActor @Observable public final class NavigationRouter - ``` - Hỗ trợ các method: `push(_:)`, `pop()`, `popToRoot()`, `present(sheet:)`, `present(cover:)`, `dismiss()`, `replacePath(_:)`. - -- [ ] **Step 1: Viết failing unit tests cho Router state & dismiss logic** - -Tạo file `Tests/BaseNavigationStackTests/NavigationRouterTests.swift` kiểm tra: -1. `push` và `pop` phần tử đúng thứ tự. -2. `dismiss` khi có đúng 1 phần tử trong path thì pop về mảng rỗng (Fix bug v1). -3. `dismiss` khi đang mở sheet thì đóng sheet, giữ nguyên stack. -4. `replacePath` tự động dismiss sheet và cover đang mở. - -- [ ] **Step 2: Chạy test để xác nhận FAIL với code v1 hiện tại** - -Run: `cd /Users/lequangtrongtai/orca/BaseNavigationStack && swift test --filter NavigationRouterTests` -Expected: FAIL - -- [ ] **Step 3: Hiện thực hóa NavigationRouter 2.0** - -Viết lại `Sources/BaseNavigationStack/BaseNavigationStack.swift` và các file liên quan: -- Áp dụng `@MainActor @Observable public final class BaseNavigationStack` (để backward compatible) và cung cấp class mới `NavigationRouter`. -- Sửa hàm `dismiss()`: -```swift -@MainActor -public func dismiss() { - if state.presentingSheet != nil { - state.presentingSheet = nil - } else if state.presentingFullScreen != nil { - state.presentingFullScreen = nil - } else if !state.navigationPath.isEmpty { - state.navigationPath.removeLast() - } else { - state.isPresented.wrappedValue = nil - } -} -``` -- Cơ chế debounce/guard chống double push: -```swift -@MainActor -public func pushToView(_ viewSpec: ScreenView) { - // Tránh append liên tiếp cùng một target trong cùng 1 frame - if state.navigationPath.last != viewSpec { - state.navigationPath.append(viewSpec) - } -} -``` - -- [ ] **Step 4: Chạy lại test suite để xác nhận PASS** - -Run: `cd /Users/lequangtrongtai/orca/BaseNavigationStack && swift test` -Expected: PASS 100% - -- [ ] **Step 5: Commit thay đổi task 2** - -```bash -git add Sources/BaseNavigationStack/ Tests/BaseNavigationStackTests/ -git commit -m "feat(core): implement NavigationRouter 2.0 with swift 6 strict concurrency" -``` - ---- - -### Task 3: Bộ kiểm thử nâng cao & Nested Navigation Flows (P0) - -**Files:** -- Create: `Tests/BaseNavigationStackTests/NestedNavigationTests.swift` -- Create: `Tests/BaseNavigationStackTests/ConcurrencySafetyTests.swift` - -**Interfaces:** -- Consumes: `NavigationRouter`, `BaseNavigationStack` -- Produces: Test cases bao phủ toàn bộ scenario: - - Tab Router độc lập không ảnh hưởng lẫn nhau. - - Modal chứa Stack con (Parent -> Sheet -> Child Stack Push -> Child Stack Pop -> Parent Dismiss). - - Multi-threaded MainActor access isolation. - -- [ ] **Step 1: Viết test suite Nested Navigation** - -Hiện thực hóa `NestedNavigationTests.swift`: -- Mô phỏng App có MainRouter và SettingsRouter bên trong Sheet. -- Verify khi MainRouter mở Sheet Settings, SettingsRouter push màn hình con `subSettings`. -- Verify đóng MainRouter Sheet sẽ deinit và dọn dẹp an toàn SettingsRouter. - -- [ ] **Step 2: Viết test suite Concurrency & Rapid Interaction** - -Hiện thực hóa `ConcurrencySafetyTests.swift`: -- Test gọi rapid `pushToView` liên tiếp 5 lần với cùng destination xem có bị trùng lặp không mong muốn. -- Test `popBack()` khi stack rỗng không gây crash hay index out of bounds. - -- [ ] **Step 3: Chạy toàn bộ test suite và xuất report coverage** - -Run: `cd /Users/lequangtrongtai/orca/BaseNavigationStack && swift test --enable-code-coverage` -Expected: Mọi test case đều PASS với thời gian thực thi < 0.5s. - -- [ ] **Step 4: Commit thay đổi task 3** - -```bash -git add Tests/BaseNavigationStackTests/ -git commit -m "test: add nested navigation and concurrency safety test suites" -``` - ---- - -### Task 4: Cập nhật Example App & Đồng bộ API Documentation (P1) - -**Files:** -- Modify: `NavigationStackExample/NavigationStackExample/BaseDefineTarget/ViewNavigationTarget.swift` -- Modify: `NavigationStackExample/NavigationStackExample/ContentView.swift` -- Modify: `NavigationStackExample/NavigationStackExample/Utils/View+Extension.swift` -- Modify: `README.md` - -**Interfaces:** -- Consumes: Public API `BaseNavigationStack` 2.0 -- Produces: Ứng dụng mẫu hoàn chỉnh chạy được trên Simulator, README chính xác 100% kèm code snippets. - -- [ ] **Step 1: Cập nhật code mẫu trong NavigationStackExample** - -- Sửa `ViewNavigationTarget`: Bỏ closure trong `case updateProfile` để tránh lỗi non-Sendable và crash hash. -- Cập nhật `ContentView.swift`: Sử dụng `@Bindable` native của SwiftUI thay cho helper `binding(keyPath:)`. - -- [ ] **Step 2: Cập nhật README.md** - -- Sửa các badge bị gãy link (xóa badge `LFAlertController`). -- Thêm badge Swift 6.0, iOS 17.0+, macOS 14.0+, MIT License. -- Viết lại phần Usage đúng với API v2.0 (hướng dẫn dùng 1 generic type hoặc Router chuẩn). -- Bổ sung hướng dẫn giải quyết bài toán Nested Navigation & Deep Link. - -- [ ] **Step 3: Chạy test và verify example** - -Kiểm tra cú pháp và build không có warning. -Run: `swift test` - -- [ ] **Step 4: Commit thay đổi task 4** - -```bash -git add NavigationStackExample/ README.md -git commit -m "docs: update example app and align readme with 2.0 api" -``` - ---- - -### Task 5: Thiết lập CI/CD Chuẩn Open-Source (GitHub Actions & SwiftLint) (P0) - -**Files:** -- Create: `.swiftlint.yml` -- Create: `.github/workflows/ci.yml` -- Create: `.github/workflows/release.yml` -- Create: `.github/dependabot.yml` -- Create: `.github/PULL_REQUEST_TEMPLATE.md` - -**Interfaces:** -- Consumes: GitHub Actions runner macOS 15, `swift test`, `xcodebuild` -- Produces: Tự động hóa kiểm thử PR/Push, tự động tạo Release khi có git tag. - -- [ ] **Step 1: Tạo file cấu hình `.swiftlint.yml`** - -Tạo `.swiftlint.yml` phù hợp Swift 6, tắt các rule quá khắt khe đối với view builder trong SwiftUI. - -- [ ] **Step 2: Tạo workflow `.github/workflows/ci.yml`** - -Tạo workflow CI gồm: -1. `lint`: Chạy swiftlint trên macOS runner. -2. `test-macos`: Chạy `swift test --enable-code-coverage` trên macOS 15. -3. `test-ios`: Chạy `xcodebuild test` trên iOS Simulator iPhone 16. - -- [ ] **Step 3: Tạo workflow `.github/workflows/release.yml` và community files** - -- `.github/workflows/release.yml`: Tự động build và phát hành GitHub Release kèm release notes khi có tag `v*`. -- Thêm PR template và dependabot. - -- [ ] **Step 4: Kiểm tra cú pháp YAML của workflows** - -Run: `git diff --check` -Expected: Không có lỗi thụt lề hay trailing whitespace trong file YAML. - -- [ ] **Step 5: Commit thay đổi task 5** - -```bash -git add .swiftlint.yml .github/ -git commit -m "ci: add comprehensive github actions workflows and open source standards" -``` diff --git a/docs/superpowers/plans/2026-10-19-navigation-container-and-performance.md b/docs/superpowers/plans/2026-10-19-navigation-container-and-performance.md deleted file mode 100644 index 4d5eee0..0000000 --- a/docs/superpowers/plans/2026-10-19-navigation-container-and-performance.md +++ /dev/null @@ -1,136 +0,0 @@ -# Navigation Container, Ergonomics & Performance Implementation Plan - -> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. - -**Goal:** Hiện thực hóa `BaseNavigationContainer` và ViewModifier declarative `.navigationRouter(...)`, tích hợp Stack Depth Guard giới hạn độ sâu stack chống memory bloating/warnings, hỗ trợ Async navigation action an toàn qua Actor boundaries, và cập nhật toàn bộ UI Showcase tương tác hoàn chỉnh. - -**Architecture:** Sử dụng SwiftUI View composition thuần túy, đóng gói `NavigationStack`, `navigationDestination`, `.sheet`, `.fullScreenCover` vào một container duy nhất có generic constraints `Hashable & Identifiable & Sendable`. Quản lý state qua observation field-level tracking giúp triệt tiêu re-renders ngoài ý muốn. - -**Tech Stack:** Swift 6.0, iOS 17.0+, macOS 14.0+, SwiftUI, Observation, XCTest / Swift Testing. - -**Spec:** `docs/superpowers/specs/2026-10-19-navigation-container-and-performance-design.md` - -## Global Constraints - -- **Zero External Dependencies:** Chỉ dùng framework có sẵn của Apple. -- **Strict Concurrency Compliant:** `@MainActor` cô lập UI, `nonisolated` bridge cho background tasks. -- **Performance:** Thao tác kiểm tra độ sâu stack và deduplication chạy trong O(1). - -## Review Focus - -1. **Stack Overflow / Max Depth:** Nếu đẩy liên tục vượt quá `maxDepth` (mặc định 30), router phải reject hoặc log warning an toàn thay vì làm đầy heap memory. -2. **Actor Hopping Safety:** `router.send { $0.push(...) }` phải thực thi đúng trên `@MainActor` kể cả khi gọi từ một background detached task. -3. **Observation Granularity:** View chỉ lắng nghe Sheet không được re-render khi Stack path thay đổi. - ---- - -### Task 1: Bổ sung Stack Depth Guard & Async Navigation Helper vào Router Core - -**Files:** -- Modify: `Sources/BaseNavigationStack/NavigationRouter.swift` -- Test: `Tests/BaseNavigationStackTests/PerformanceAndAsyncTests.swift` - -**Interfaces:** -- Consumes: `NavigationRouter` -- Produces: - - `public var maxDepth: Int = 30` - - `public func push(_ route: Route)` có kiểm tra `path.count < maxDepth` - - `nonisolated public func send(_ action: @escaping @MainActor (NavigationRouter) -> Void)` - -- [ ] **Step 1: Viết test cho Stack Depth Guard và Async send** - -Tạo `Tests/BaseNavigationStackTests/PerformanceAndAsyncTests.swift`: -- Test push 35 màn hình khi `maxDepth = 30` -> Verify stack dừng ở 30. -- Test gọi `send` từ `Task.detached` -> Verify route được đẩy vào stack trên main actor. - -- [ ] **Step 2: Hiện thực hóa thay đổi trong NavigationRouter.swift** - -Thêm `maxDepth` và `send` method vào `NavigationRouter.swift`. - -- [ ] **Step 3: Chạy test kiểm chứng** - -Run: `swift test --filter PerformanceAndAsyncTests` -Expected: PASS - -- [ ] **Step 4: Commit task 1** - -```bash -git add Sources/BaseNavigationStack/NavigationRouter.swift Tests/BaseNavigationStackTests/PerformanceAndAsyncTests.swift -git commit -m "feat(router): add stack depth guard and async send helper" -``` - ---- - -### Task 2: Hiện thực hóa BaseNavigationContainer & ViewModifier Declarative - -**Files:** -- Create: `Sources/BaseNavigationStack/Views/BaseNavigationContainer.swift` -- Create: `Sources/BaseNavigationStack/Modifiers/NavigationRouterModifier.swift` -- Test: `Tests/BaseNavigationStackTests/ContainerViewTests.swift` - -**Interfaces:** -- Produces: - ```swift - public struct BaseNavigationContainer: View - ``` - ```swift - extension View { - public func navigationRouter(...) -> some View - } - ``` - -- [ ] **Step 1: Tạo BaseNavigationContainer.swift** - -Tạo component bọc `NavigationStack(path: $router.path)` kèm các destination modifiers. - -- [ ] **Step 2: Tạo NavigationRouterModifier.swift** - -Tạo extension modifier hỗ trợ declarative style. - -- [ ] **Step 3: Viết test kiểm tra build và render của container** - -Tạo `ContainerViewTests.swift` verify container khởi tạo thành công trên môi trường test. - -- [ ] **Step 4: Chạy swift test** - -Run: `swift test` -Expected: PASS 100% - -- [ ] **Step 5: Commit task 2** - -```bash -git add Sources/BaseNavigationStack/ Views/ Modifiers/ Tests/ -git commit -m "feat(ui): add BaseNavigationContainer and declarative view modifiers" -``` - ---- - -### Task 3: Cập nhật Interactive Showcase Demo trong NavigationStackExample - -**Files:** -- Modify: `NavigationStackExample/NavigationStackExample/ContentView.swift` -- Modify: `NavigationStackExample/NavigationStackExample/View/ListView.swift` -- Modify: `NavigationStackExample/NavigationStackExample/View/BaseView.swift` - -**Interfaces:** -- Consumes: `BaseNavigationContainer`, `NavigationRouter` -- Produces: 3 Tab tương tác sinh động: Stack Trail, Nested Modals, Async & Stress Test. - -- [ ] **Step 1: Viết lại ContentView.swift thành 3 Tab Showcase** - -Hiện thực hóa giao diện TabView gồm 3 flows: -1. "Stack Explorer": Push/Pop, hiển thị visual trail số lượng view hiện tại. -2. "Nested Flow": Demo Sheet chứa child router độc lập. -3. "Async & Stress": Nút bấm gọi delay 1s và nút bấm 10 lần liên tục verify debounce. - -- [ ] **Step 2: Chạy swift build và swiftlint** - -Run: `swift build && swiftlint --strict --quiet` -Expected: Exit code 0, không có warning. - -- [ ] **Step 3: Commit task 3** - -```bash -git add NavigationStackExample/ -git commit -m "feat(demo): build comprehensive 3-tab interactive showcase" -``` diff --git a/docs/superpowers/specs/2026-10-19-navigation-container-and-performance-design.md b/docs/superpowers/specs/2026-10-19-navigation-container-and-performance-design.md deleted file mode 100644 index e273396..0000000 --- a/docs/superpowers/specs/2026-10-19-navigation-container-and-performance-design.md +++ /dev/null @@ -1,54 +0,0 @@ -# BaseNavigationStack 2.0: Container View, Async Ergonomics & Performance Spec - -**Goal:** Cung cấp container component SwiftUI `BaseNavigationContainer` và ViewModifier declarative gọn nhẹ, hỗ trợ điều hướng bất đồng bộ (Async navigation / Actor safe), kiểm soát tối đa số lượng view trong stack tránh memory bloating/warnings, và tối ưu hiệu năng O(1) observation. - -## 1. Kiến trúc thành phần - -### 1.1. BaseNavigationContainer -Component SwiftUI đóng gói toàn bộ lifecycle điều hướng: -```swift -public struct BaseNavigationContainer< - Route: Hashable & Sendable, - Sheet: Identifiable & Hashable & Sendable, - Cover: Identifiable & Hashable & Sendable, - Content: View, - Destination: View, - SheetContent: View, - CoverContent: View ->: View -``` -- Tự động quản lý `NavigationStack(path: $router.path)`. -- Gắn `.navigationDestination(for: Route.self)` ở cấp độ root container chuẩn Apple HIG. -- Quản lý `.sheet(item: $router.sheet)` và `.fullScreenCover(item: $router.cover)`. -- Tự động inject `.environment(router)` xuống cây view phân cấp. - -### 1.2. ViewModifier Extension `.navigationRouter(...)` -Cung cấp giải pháp linh hoạt khi end-user đã có sẵn `NavigationStack`: -```swift -extension View { - public func navigationRouter( - _ router: NavigationRouter, - @ViewBuilder destination: @escaping (Route) -> some View, - @ViewBuilder sheet: @escaping (Sheet) -> some View = { _ in EmptyView() }, - @ViewBuilder cover: @escaping (Cover) -> some View = { _ in EmptyView() } - ) -> some View -} -``` - -## 2. Kiểm soát hiệu năng & Tránh lỗi số lượng View trong Stack - -1. **Stack Depth Guard (`maxDepth: Int`)**: - - Khi độ sâu stack vượt quá ngưỡng (ví dụ: > 30 màn hình), router tự động cảnh báo qua logger hoặc giới hạn để tránh crash bộ nhớ và SwiftUI layout recursion warnings. -2. **O(1) Deduplication / Debounce**: - - So sánh nhanh `path.last == route` (O(1)) để ngăn chặn việc người dùng double-tap tạo ra 2 màn hình giống hệt nhau liên tiếp. -3. **Observation Field-Level Tracking**: - - Tách biệt `path`, `sheet`, `cover` trong `@Observable`. Chỉ các View tiêu thụ thuộc tính tương ứng mới được re-render khi state thay đổi. -4. **Actor-Safe Background Hopping**: - - Bổ sung `nonisolated public func send(_ action: @escaping @MainActor (NavigationRouter) -> Void)` cho phép gọi điều hướng an toàn từ `Task.detached` hoặc background actor. - -## 3. UI Showcase Demo - -Xây dựng bộ demo tương tác 3 tabs trực quan trong `NavigationStackExample`: -- **Tab 1 - Core Stack**: Push/Pop, hiển thị visual stack trail, popToRoot. -- **Tab 2 - Nested Modals**: Mở Sheet chứa sub-router riêng, verify đóng độc lập. -- **Tab 3 - Async & Performance**: Giả lập API delay 1s -> navigate, stress-test nút bấm liên tục.