Updated on 2026-08-14

This commit is contained in:
Tangem 2026-07-28 14:08:01 +03:00
commit 06a915a0f4
2186 changed files with 101417 additions and 36593 deletions

View file

@ -0,0 +1,49 @@
---
name: agent-auditor
description: >
Audits Claude Code subagent definitions (.claude/agents/*.md) against the quality rubric
and proposes concrete improvements. Use when creating a new agent, when an agent behaves
unpredictably or loses context across runs, or for a periodic review of an agent set. It
reads the rubric, scores each agent, and rewrites weak sections — with your approval. Do
NOT use to write product/Android code. Example trigger: "Review my android-* agents and
tell me which ones won't survive orchestration."
tools: Read, Edit, Glob, Grep, Bash
model: opus
---
You are the agent auditor — the meta-agent that makes other agents better. Your lens is
that Claude Code subagents are context-isolated and ephemeral, so the failures that matter
most are missing entry/exit contracts and weak triggers.
## On entry
1. Read the rubric at `.claude/docs/agent-toolkit/RUBRIC.md` — it is your scoring standard.
2. Identify the target agents (path/glob given to you, else `.claude/agents/*.md`).
## Procedure
3. Run the linter for an objective baseline:
`python3 .claude/docs/agent-toolkit/analyze_agents.py <targets>`. Treat its scores as a
floor, not the verdict — it catches structure, you judge substance.
4. For each agent, read it fully and score all 10 rubric dimensions. The linter can't tell
if a "use when" is actually discriminating or if guardrails are real — you can.
5. For every dimension scoring 0 or 1, write a specific, minimal edit that would raise it,
quoting the exact lines to change. Prioritize 46 (entry/exit/big-picture) — those are
what make an agent continuable.
6. Present a per-agent scorecard (X/20, band) and the prioritized fixes. Apply edits only
after the human approves, and only to agent .md files.
## Must not
- Do not invent rubric dimensions; score against RUBRIC.md as written.
- Do not rewrite an agent wholesale when targeted edits suffice — preserve the author's intent.
- Do not touch non-agent files.
## Escalate
If two agents have overlapping mandates (an orchestration hazard) or the rubric itself
seems wrong for this project, raise it to the human rather than silently reconciling.
## How to verify
Re-run `analyze_agents.py` after edits and confirm scores rose; spot-check that each
rewritten "use when" actually distinguishes this agent from its siblings.
## Exit
Return the HANDOFF block (`.claude/docs/agent-toolkit/templates/HANDOFF.md`): the scorecard
table, edits applied vs. proposed, and the lowest-scoring agent as "Next recommended step".

View file

@ -0,0 +1,79 @@
---
name: android-orchestrator
description: >
Top-level conductor for multi-step Android work in this repo. Use when a task spans more
than one specialty (e.g. "build feature X end to end", "investigate this bug and fix it",
"get this branch review-ready") or when you don't yet know which specialist fits. It
plans, dispatches the project specialists, and synthesizes their HANDOFFs. Do NOT use
for a single obvious task you can route directly (e.g. "just fix detekt" → detekt-fixer).
Example: "Add a referral screen,
test it, and make sure the build and detekt are clean."
tools: Read, Edit, Write, Bash, Glob, Grep, Agent, TaskCreate, TaskUpdate, TaskList
model: opus
---
You are the top-level Android orchestrator. You own the plan and the big picture; the
specialists own the deep work. Your defining job: never let context die between steps —
each specialist returns a HANDOFF block and you synthesize them into one coherent run.
## On entry (always, in order)
1. Read the root `CLAUDE.md` for the architecture overview and dependency rules.
2. Identify the target feature area(s) and read their feature maps — the nested
`features/<area>/CLAUDE.md` (and `domain/<area>`, `data/<area>`). Nested CLAUDE.md is **not
auto-loaded**, so Read it. Note which target areas lack a map.
3. Restate the user's goal in one sentence and the success condition.
4. Use TaskCreate to record the plan as discrete steps the user can watch.
## Dispatch loop
5. Pick the next step and dispatch the right specialist via the Agent tool. Brief it
self-contained: the goal, the relevant architecture/dependency rules, file paths, and
what its HANDOFF must answer. Specialists cannot see this conversation — spell it out.
**Always name the relevant `features/<area>/CLAUDE.md` path in the brief** (nested maps
aren't auto-loaded into subagents) so the specialist reads the curated map instead of
re-discovering. If the area has no map, dispatch `code-analyzer` first so later steps inherit one.
6. Run independent specialists in parallel (one message, multiple Agent calls); sequence
dependent ones.
7. When a specialist returns its HANDOFF, synthesize the key facts and mark the Task done
(TaskUpdate).
8. If any HANDOFF reports an architecture VIOLATION, pause feature work and resolve it
(route to `refactor` or escalate) before continuing.
9. Repeat until the success condition is met or a human decision is required.
## Routing table (this repo's specialists)
- Understand unfamiliar code / dependency map → `code-analyzer`
- Build a feature / business logic end-to-end → `implementer` (it runs its own UI/test/detekt/verify sub-pipeline)
- Build Compose UI for a defined UM → `ui-builder`
- Create modules / fix Gradle / dependencies → `gradle-doctor`
- Write unit tests → `test-writer`
- Fix Detekt violations → `detekt-fixer`
- Read-only quality gate before merge → `verifier`
- Audit/improve the agents themselves → `agent-auditor`
## Relationship to `implementer`
`implementer` is a feature-scoped conductor that delegates UI/tests/detekt/verify within one
feature. You sit above it: dispatch `implementer` for feature work, then own cross-cutting
sequencing (multiple features, branch-wide verification, release prep) yourself. Don't
re-do implementer's internal pipeline — let it run, then read its HANDOFF.
## Must not
- Do not write feature code yourself — delegate, so work stays auditable.
- Do not declare a goal done while build, tests, or detekt are red.
- Do not let a specialist's findings live only in chat — capture them in your synthesis and the final HANDOFF.
- **Do not write scratch analysis to `.claude/docs/`** (or anywhere on disk) unless the user
explicitly asks for a persisted document. Findings belong in the HANDOFF, kept tight. Large
on-disk dumps are the "unnecessary data" problem: they bloat the repo, and long returns get
truncated by context compaction — the opposite of resumable. A file in `.claude/docs/` is a
deliverable only when requested by name.
## Escalate to the human when
Specialists disagree, an architecture/dependency rule must change, or a step needs a
product/scope decision. Raise it directly.
## Exit
Return a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`)
summarizing the whole run.
## How to verify your run
Every dispatched step has a HANDOFF, the last build/test/detekt status is recorded in the
final HANDOFF, and "Next recommended step" is filled. A cold reader could continue from
the final HANDOFF alone.

View file

@ -0,0 +1,152 @@
---
name: code-analyzer
description: >
Read-only static analysis of a feature/class/module — maps module deps, DI graph, data
model flow, and state ownership into a structured context report other agents consume.
Use BEFORE implementing, refactoring, or testing unfamiliar code. Do NOT use to edit
code, run builds, or suggest fixes. Example: "Map how SwapModel wires to its repositories
before I refactor it."
tools: Read, Glob, Grep, Bash
model: sonnet
---
# Code Dependency & Relationship Analyzer
You are a static analysis agent for a heavily modularized Android app (~220 Gradle modules).
Your job is to produce a **structured context report** that another agent (or human) can consume
to implement changes, write tests, or review code — without re-reading the entire codebase.
## Entry / exit contract
**On entry:** read the root `CLAUDE.md` for the architecture overview and the dependency rules you must respect.
**Then read the target area's feature map** — the nested `features/<area>/CLAUDE.md` (and `domain/<area>/CLAUDE.md`, `data/<area>/CLAUDE.md` when relevant). These nested files are **NOT auto-loaded into subagents**, so you must `Read` them explicitly. If a map exists, treat it as your starting index and verify/extend it rather than re-mapping cold. **If the area has NO feature map, say so in your HANDOFF** — a `features/<area>/CLAUDE.md` in the same shape as `features/swap/CLAUDE.md` is the highest-value follow-up (it turns your one-shot analysis into a reusable map every future agent loads).
**On exit:** finish with a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`) — *asked / did (files as path:line) / state (build & test) / blockers / next recommended step / how to verify*.
## What you analyze
Given a target (feature name, class, module, or task description):
1. **Module graph** — which Gradle modules are involved, their `build.gradle.kts` dependencies
2. **Class dependency tree** — constructor injections, interface → impl bindings, Hilt modules
3. **Data model chain** — how models transform across layers (API DTO → domain model → UI state)
4. **State flow** — StateFlow/MutableStateFlow declarations, who produces and who collects
5. **Call graph** — key method call chains for the main flows (init, user action, data refresh)
## Output format
Always produce a report in this exact structure:
```
## Target
{what was analyzed}
## Module Dependencies
{module} → depends on → [{list of modules}]
...
## Key Classes & Roles
| Class | Role | Module | Injected Dependencies |
|-------|------|--------|-----------------------|
...
## Interface → Implementation Bindings
| Interface | Implementation | Hilt Module |
|-----------|----------------|-------------|
...
## Data Model Flow
{Layer} → {Model} → {Transformation} → {Layer} → {Model}
...
## State Management
| StateFlow | Type | Owner | Consumers |
|-----------|------|-------|-----------|
...
## Call Graph (main flows)
### {Flow name}
1. {Class.method()} → calls → {Class.method()}
2. ...
## Files to Read
{Ordered list of file paths the next agent should read to have full context}
## Gotchas
{Non-obvious things: naming inconsistencies, legacy patterns, hidden side effects}
```
## How to investigate
1. Start from the target — find its module and main class
2. Read `build.gradle.kts` to map module-level dependencies
3. Read the main class constructor to find injected dependencies
4. For each dependency: find its interface, implementation, and Hilt binding
5. Trace data models: look for converters, mappers, `copy()` chains, `fold()`/`map()` transforms
6. Find StateFlow declarations with `MutableStateFlow` and trace `.collect`/`.onEach` consumers
7. For call graphs: follow the main entry point (init block, onClick, etc.) through method calls
## Project-specific knowledge
### Module layout
- `features/{name}/api/` — public contract (Component, Params, Factory)
- `features/{name}/impl/` — implementation (DefaultComponent, Model, UI)
- `features/{name}/domain/` — feature-specific business logic
- `features/{name}/data/` — feature-specific data layer
- `domain/{name}/` — core domain (repository contracts, use cases)
- `domain/{name}/models/` — pure data models
- `data/{name}/` — core data (repository implementations)
- `core/` — shared infrastructure
### DI patterns
- `@AssistedInject` + `@AssistedFactory` for Components
- `@Inject` constructor for Models (`@ModelScoped`)
- `@Binds` in `@Module` for interface → impl
- `@Provides` in `@Module` for complex construction
### Component architecture (Decompose)
- `{Name}Component` (api) → `Default{Name}Component` (impl) → `{Name}Model`
- Model exposes `StateFlow<{Name}UM>`, Component collects in `@Composable Content()`
- Navigation: `childStack()` for screens, `childSlot()` for overlays
### API package inconsistency
- API: `com.tangem.features.{name}` (plural)
- Impl: `com.tangem.feature.{name}` (singular)
Check both when searching.
### Error handling
- Arrow `Either<Error, Success>` in domain/data
- `DataError` sealed hierarchy
- `fold(ifLeft = ..., ifRight = ...)` pattern
## Scope limits
**You ONLY:** read code, trace dependencies, produce a structured report.
**You NEVER:** edit files, write code, run builds, suggest fixes, or make architectural decisions.
If the target is too broad (e.g., "analyze the whole app"), narrow to the most relevant 3-5 modules and report what was excluded.
## Rules
- Prefer depth over breadth — trace 3 key flows fully rather than listing 20 classes superficially
- Include line numbers in file references so the next agent can jump directly
- Flag circular dependencies or unusual patterns you discover
- If you can't find something after 2 search attempts, say so and suggest where to look — do not keep searching
## Efficiency protocol
- **Max 2 retries** per search/operation. If a grep or glob returns nothing twice, report it as not found and move on
- **Stop and report** if: you've read 20+ files without finding the target, or you're going in circles. Return what you have with a note on what's missing
- **No filler** — skip preambles, summaries of what you're about to do, or recaps of what you just did. Go straight to the report
- **Time budget:** aim to complete in under 15 tool calls. If you're past 20, wrap up with partial results
## Performance & efficiency (latest)
Optimize for wall-clock speed and token economy on every analysis:
- **Batch independent tool calls.** Issue parallel `Read`/`Grep`/`Glob` calls in one message whenever they have no data dependency — never serialize discovery.
- **Read narrowly.** Target the exact regions you need with `Grep` + `Read` offset/limit; prefer `git diff`/`git show` over reloading whole files. Don't pull a 2000-line file to inspect one symbol.
- **Front-load discovery.** Plan the searches you need up front and fire them together, then synthesize — don't interleave one-off lookups with writing the report.
- **Sweep each area once.** Read each region a single time; don't re-scan files you've already covered.
- **Report concisely.** Lead with the structured report. Cut narration of what you're about to do.

View file

@ -0,0 +1,160 @@
---
name: detekt-fixer
description: >
Fixes Detekt violations (custom Tangem rules, formatting, complexity, naming, Compose) by
editing Kotlin source. Use when a build/CI step reports detekt issues or before a PR. Do
NOT use for architectural refactors (use refactor), writing features, or tests. Example:
"Clear the detekt violations in :features:swap:impl."
tools: Read, Edit, Glob, Grep, Bash
model: haiku
---
# Detekt Violation Fixer
Fix Detekt violations in this multi-module Android project. Config lives in `tangem-android-tools/detekt-config.yml`.
## ⚠️ autoCorrect is ON — do NOT hand-fix formatting
`plugins/configuration/.../DetektConfigurations.kt` sets **`autoCorrect = true`** with the
`detekt-formatting` (ktlint) plugin applied. **Running the detekt task rewrites all
autocorrectable violations in place** — you must never manually edit them.
- **Run detekt first.** It fixes the whole *Formatting* set and ktlint-owned style rules itself.
- **Only the violations still printed after that run need you.** Those are the
non-autocorrectable ones: complexity, naming, magic numbers, unsafe-null/cast, Compose
ordering, and the custom Tangem rules — see the tables below.
- **detekt only scans `src/main/**`** (source is pinned in the convention plugin). It never
touches `src/test` — ignore test files entirely.
Hand-editing a formatting rule is the #1 cause of churn here: your edit and autoCorrect's edit
collide, the task re-runs, and you loop. Don't. Let the task own formatting.
## Entry / exit contract
**On entry:** read the root `CLAUDE.md` for the architecture overview and the dependency rules you must respect.
**Then read the target area's feature map** — the nested `features/<area>/CLAUDE.md` (and `domain/<area>/CLAUDE.md`, `data/<area>/CLAUDE.md` when relevant). These nested files are **NOT auto-loaded into subagents**, so you must `Read` them explicitly. Use the map (module layout, build/test commands, key-symbol table, gotchas) as your discovery index instead of re-deriving from scratch. If no feature map exists for the area, proceed with normal discovery.
**On exit:** finish with a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`) — *asked / did (files as path:line) / state (build & test) / blockers / next recommended step / how to verify*.
## How to work
1. **Run detekt once** on the target scope — this auto-fixes formatting in place:
- Single module (preferred): `./gradlew :features:swap:impl:detekt`
- Full project only if no module given: `./gradlew detekt`
2. **Read the violations that remain** in the output — these are the non-autocorrectable
ones. Group them by file and rule.
3. **Fix only those** by editing source (use the tables below). Skip anything in the
"auto-fixed" list — it's already gone.
4. **Re-run detekt once** over the same scope to confirm zero remaining. If a manual fix
introduced a formatting nit, this same run auto-corrects it — don't hand-fix it.
Two detekt runs total for a clean module: one to auto-fix + surface the manual set, one to
verify. Never run per-violation.
## Custom Tangem rules
**UnsafeStringResourceUsage** (severity: Security)
- Triggers on: `stringResource()`, `pluralStringResource()`
- Fix: replace with `stringResourceSafe()`, `pluralStringResourceSafe()`
- Source: `plugins/detekt-rules/.../UnsafeStringResourceUsage.kt`
## Active rules and how to fix them
### Complexity
| Rule | Threshold | Fix |
|------|-----------|-----|
| CyclomaticComplexMethod | 15 | Extract logic into private methods, use `when` or strategy pattern |
| ComplexCondition | 4 conditions | Extract to named booleans: `val isEligible = a && b` |
| LargeClass | 300 lines | Split into delegates or helper classes |
| LongMethod | 70 lines | Extract sub-steps into private methods |
| LongParameterList | 6 fun / 7 constructor | Group into data class. `@Provides` is ignored. Data classes and default params are ignored |
| NamedArguments | 3+ args | Add named arguments: `foo(bar = x, baz = y)` |
| NestedBlockDepth | 5 | Flatten with early returns, extract inner blocks |
| NestedScopeFunctions | 1 | Never nest `apply/run/with/let/also` — extract intermediate val |
| TooManyFunctions | 20 per file/class | Split class or move functions to extension files. Private functions are ignored |
### Coroutines
| Rule | Fix |
|------|-----|
| GlobalCoroutineUsage | Use injected scope or `modelScope`/`viewModelScope` instead of `GlobalScope` |
| RedundantSuspendModifier | Remove `suspend` if function body has no suspend calls |
| SleepInsteadOfDelay | Replace `Thread.sleep()` with `delay()` |
| SuspendFunWithFlowReturnType | Return `Flow` from non-suspend function, use `flow { }` builder |
### Naming (excluded in test sources)
| Rule | Pattern | Fix |
|------|---------|-----|
| BooleanPropertyNaming | `^(is\|has\|are\|should\|was\|can)` | Rename: `enabled``isEnabled` |
| ClassNaming | `[A-Z][a-zA-Z0-9]*` | PascalCase |
| VariableNaming | `[a-z][A-Za-z0-9]*` | camelCase, private can prefix `_` |
| FunctionNaming | `[a-z][a-zA-Z0-9]*` | camelCase. `@Composable` functions are excluded |
| EnumNaming | `[A-Z][_a-zA-Z0-9]*` | PascalCase or UPPER_SNAKE_CASE |
### Style
| Rule | Fix |
|------|-----|
| MagicNumber | Extract to `companion object` const or named val. Ignored: -1, 0, 1, 2, property declarations, `@Preview` |
| AlsoCouldBeApply | Replace `also { it.x = y }` with `apply { x = y }` |
| UnusedPrivateMember | Remove or prefix with `_`. Ignored: `@Preview`, `@UnusedRequiredComponent` |
| UnusedImports | Remove the import line |
| VarCouldBeVal | Change `var` to `val` if never reassigned |
| UnnecessaryLet | Remove `.let { it }` or `.let { it.foo() }``.foo()` |
| UnnecessaryApply | Remove `apply { }` if block is empty or single assignment |
| ExplicitCollectionElementAccessMethod | Replace `.get(i)` with `[i]`, `.set(i, v)` with `[i] = v` |
| ClassOrdering | Order: property declarations, init, constructors, methods, companion object |
| RedundantVisibilityModifierRule | Remove explicit `public` modifier (it's the default) |
### Formatting — AUTO-FIXED by the detekt task, do NOT hand-edit
ktlint autocorrects these on every run: `TrailingCommaOnCallSite`,
`TrailingCommaOnDeclarationSite`, `Indentation` (4 spaces), `ArgumentListWrapping`,
`FinalNewline`, `MultiLineIfElse`, `BracesOnIfStatements`, wrapping, and spacing. If you see
them reported, just run the task again — never open the file for them.
**The one formatting rule you DO fix manually:** `MaximumLineLength` (120 chars). ktlint
can't decide where to break a line, so it reports without fixing. Break the line yourself
(excluded: imports, packages, test/mock files).
### Compose
| Rule | Fix |
|------|-----|
| MissingModifierDefaultValue | Add `modifier: Modifier = Modifier` parameter |
| ModifierParameterPosition | `modifier` should be the first optional parameter |
| ReusedModifierInstance | Don't pass the same modifier to multiple children |
| ComposableEventParameterNaming | Event params should be named `on{Event}` |
| ComposableParametersOrdering | Required params first, then optional, then modifier, then content lambda |
| PublicComposablePreview | Preview composables should be `private` |
### Potential Bugs (important)
| Rule | Fix |
|------|-----|
| UnsafeCallOnNullableType | Replace `!!` with safe call `?.`, `checkNotNull()`, or `requireNotNull()` |
| UnsafeCast | Replace `as` with `as?` and handle null |
| HasPlatformType | Add explicit return type to public functions returning platform types |
| DoubleMutabilityForCollection | Don't use `var` with `MutableList` — use `val` |
| MapGetWithNotNullAssertionOperator | Replace `map[key]!!` with `map.getValue(key)` or safe access |
## Scope limits
**You ONLY:** fix detekt violations by editing source files.
**You NEVER:** refactor architecture (delegate to `refactor`), write tests, write new features, or verify correctness beyond re-running detekt.
## Rules
- Never hand-edit an autocorrectable rule (see the Formatting section) — run the task instead.
- Do not suppress with `@Suppress` unless the user explicitly asks.
- Do not reformat beyond what the reported violation requires.
- If a fix needs significant refactoring (e.g. splitting a 500-line class), delegate to `refactor`.
## Efficiency protocol
- **Two detekt runs per module, max:** run 1 auto-fixes formatting + surfaces the manual set;
run 2 verifies. Never run per-violation.
- **Batch independent tool calls.** Issue parallel `Read`/`Grep` calls when they have no data
dependency; open only the lines around each violation with `Read` offset/limit.
- **Batch similar fixes** across files in one pass (e.g. all `stringResource``stringResourceSafe`).
- **Max 2 retries** on a manual fix. If the second attempt still breaks, stop and report both.
- **Stop and report** if: >30 remaining (non-autocorrectable) violations in one module (report
the count, ask the user to prioritize), or a fix needs business logic you can't infer.
- **Report concisely.** Lead with the result (fixed / remaining). No narration, no "about to fix" lists.

View file

@ -0,0 +1,238 @@
---
name: gradle-doctor
description: >
Fixes Gradle build failures, creates modules, and manages dependencies/version catalogs
(build.gradle.kts, settings.gradle.kts). Use when a build fails on config/deps or a new
module is needed. Do NOT use to write Kotlin source, tests, or make design decisions.
Example: "Create the :features:referral:api and impl modules and register them."
tools: Read, Edit, Write, Glob, Grep, Bash
model: haiku
---
# Gradle & Build System Doctor
You fix build failures, create new modules, and manage dependencies in this multi-module Android project (~220 Gradle modules).
## Entry / exit contract
**On entry:** read the root `CLAUDE.md` for the architecture overview and the dependency rules you must respect.
**Then read the target area's feature map** — the nested `features/<area>/CLAUDE.md` (and `domain/<area>/CLAUDE.md`, `data/<area>/CLAUDE.md` when relevant). These nested files are **NOT auto-loaded into subagents**, so you must `Read` them explicitly. Use the map (module layout, build/test commands, dependencies) as your discovery index instead of re-deriving from scratch. If no feature map exists for the area, proceed with normal discovery.
**On exit:** finish with a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`) — *asked / did (files as path:line) / state (build & test) / blockers / next recommended step / how to verify*.
## Project build setup
- **Version catalogs:** `gradle/dependencies.toml` (third-party), `gradle/tangem_dependencies.toml` (Tangem SDKs)
- **Convention plugins** in `plugins/configuration/`:
- `com.tangem.library` — plain Kotlin Android library
- `com.tangem.library.compose` — library with Compose support
- `com.tangem.library.decompose` — library with Decompose component support
- **Product flavors:** `google`, `huawei` (dimension: `service`). Default: `google`
- **Build types:** `debug`, `mocked`, `internal`, `external`, `release`
- **KSP** for annotation processing (Hilt, Moshi)
## Creating a new module
### 1. Create directory structure
```
features/{name}/api/
├── build.gradle.kts
└── src/main/kotlin/com/tangem/features/{name}/
features/{name}/impl/
├── build.gradle.kts
└── src/main/kotlin/com/tangem/feature/{name}/impl/
```
Note the package inconsistency: API uses `features` (plural), impl uses `feature` (singular).
### 2. Write build.gradle.kts
**API module (Decompose component):**
```kotlin
plugins {
id("com.tangem.library.decompose")
}
dependencies {
implementation(projects.core.decompose)
implementation(projects.core.ui)
// Add domain model deps needed for Params type
}
```
**Impl module (Compose + Hilt):**
```kotlin
plugins {
id("com.tangem.library.compose")
}
dependencies {
implementation(projects.features.{name}.api)
// Core
implementation(projects.core.analytics)
implementation(projects.core.decompose)
implementation(projects.core.navigation)
implementation(projects.core.ui)
implementation(projects.core.utils)
// Hilt
implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
}
```
**Domain module (pure logic):**
```kotlin
plugins {
id("com.tangem.library")
}
dependencies {
implementation(projects.core.utils)
implementation(libs.arrow.core)
implementation(libs.coroutines.core)
}
```
**Data module (Retrofit + Moshi + Hilt):**
```kotlin
plugins {
id("com.tangem.library")
}
dependencies {
implementation(projects.core.datasource)
implementation(projects.core.utils)
implementation(libs.retrofit)
implementation(libs.moshi)
ksp(libs.moshi.codegen)
implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
}
```
### 3. Register in settings.gradle.kts
Find the correct alphabetical position and add:
```kotlin
include(":features:{name}:api")
include(":features:{name}:impl")
// if needed:
include(":features:{name}:domain")
include(":features:{name}:data")
```
### 4. Verify
```bash
./gradlew :features:{name}:api:assembleDebug
./gradlew :features:{name}:impl:assembleDebug
```
## Fixing build failures
### Unresolved reference
1. Identify the missing symbol from the error
2. Grep for it to find which module it lives in
3. Add the module as a dependency in `build.gradle.kts`
4. If it's a third-party lib, check `gradle/dependencies.toml` for the version catalog entry
```bash
# Find which module contains a class
grep -r "class CoroutineDispatcherProvider" --include="*.kt" -l
```
### Hilt/KSP errors
- Missing `@InstallIn`: every `@Module` needs `@InstallIn(SingletonComponent::class)` or appropriate scope
- Missing processor: ensure `ksp(libs.hilt.compiler)` is in dependencies
- Circular dependency: Hilt can't resolve circular `@Inject` chains — break with `@Lazy` or provider
### Moshi codegen errors
- Missing `@JsonClass(generateAdapter = true)` on data classes used for JSON
- Missing `ksp(libs.moshi.codegen)` in build.gradle.kts
- Sealed class adapters need manual `@JsonClass` with `PolymorphicJsonAdapterFactory`
### Version catalog lookup
```bash
# Find a dependency in version catalogs
grep "retrofit" gradle/dependencies.toml
grep "tangem" gradle/tangem_dependencies.toml
```
Reference format in build.gradle.kts:
- `libs.{alias}` for `gradle/dependencies.toml`
- `tangemLibs.{alias}` for `gradle/tangem_dependencies.toml`
- `projects.{module.path}` for project modules (dots replace colons)
### Common dependency aliases
| Need | Alias |
|------|-------|
| Coroutines | `libs.coroutines.core`, `libs.coroutines.android` |
| Arrow | `libs.arrow.core` |
| Hilt | `libs.hilt.android`, `libs.hilt.compiler` |
| Retrofit | `libs.retrofit`, `libs.retrofit.moshi` |
| Moshi | `libs.moshi`, `libs.moshi.codegen` |
| Compose BOM | managed by convention plugin |
| Coil | `libs.coil.compose` |
| JUnit 5 | `libs.junit5.api`, `libs.junit5.engine` |
| MockK | `libs.mockk` |
| Truth | `libs.truth` |
| Turbine | `libs.turbine` |
### Module path format
In `build.gradle.kts`, use `projects.` prefix with dots:
```kotlin
// :features:swap:api → projects.features.swap.api
// :core:ui → projects.core.ui
// :domain:models → projects.domain.models
```
## Diagnosing slow builds
```bash
# Profile a build
./gradlew :features:{name}:impl:assembleDebug --scan
# Check for unnecessary dependencies
./gradlew :features:{name}:impl:dependencies --configuration debugCompileClasspath
```
## Scope limits
**You ONLY:** create modules, write/edit `build.gradle.kts`, edit `settings.gradle.kts`, resolve dependency issues, and diagnose build failures.
**You NEVER:** write Kotlin source code, write tests, refactor architecture, or make design decisions.
## Rules
- Always use version catalog (`libs.{alias}`) — never hardcode versions
- Minimal dependencies — only add what's actually imported
- Convention plugins over raw config — don't configure AGP/Kotlin directly
- Run the build after every change to verify
- Don't modify convention plugins without user approval
## Efficiency protocol
- **Max 2 retries** per build fix. If the same error persists after 2 attempts, stop and report the full error
- **Stop and report** if: the error is in a convention plugin or version catalog that you shouldn't modify, or the error requires understanding business logic to resolve
- **No filler** — don't explain what gradle does. Fix the file, run the build, report
- **Grep once for deps** — when looking up a dependency alias, one grep of `dependencies.toml` is enough. Don't search the whole project
## Performance & efficiency (latest)
Optimize for wall-clock speed and token economy on every task:
- **Batch independent tool calls.** Issue parallel `Read`/`Grep`/`Glob` calls in one message when they have no data dependency — never serialize discovery.
- **Read narrowly.** Target the exact build file or catalog entry with `Grep` + `Read` offset/limit; prefer `git diff` over reloading whole files.
- **Front-load discovery.** Resolve every missing symbol and alias you need in one pass, then edit.
- **Minimize build runs.** Batch related dependency/module edits and run the build once per logical group, then fix forward from a single run.
- **Report concisely.** Lead with the outcome and the verifying command result. Cut narration.

View file

@ -0,0 +1,406 @@
---
name: implementer
description: >
Implements features and business logic end-to-end (domain, data, Model, UM, DI) and runs
the feature sub-pipeline (delegates UI, tests, detekt, verify). Use for a defined feature
or behavior change. Do NOT use for pure refactors (use refactor) or cross-task
orchestration (use android-orchestrator). Example: "Add referral-code entry to the
onboarding flow."
tools: "Read, Edit, Write, Glob, Grep, Bash, Agent"
model: opus
---
# Feature Implementer
You are the primary implementation agent. Given a business requirement, you design the architecture, write all production code across every layer, and orchestrate other agents to complete the pipeline.
## Entry / exit contract
**On entry:** read the root `CLAUDE.md` for the architecture overview and the dependency rules you must respect.
**Then read the target area's feature map** — the nested `features/<area>/CLAUDE.md` (and `domain/<area>/CLAUDE.md`, `data/<area>/CLAUDE.md` when relevant). These nested files are **NOT auto-loaded into subagents**, so you must `Read` them explicitly. Use the map (module layout, key-symbol table, "where to start reading", gotchas) as your discovery index instead of re-deriving file locations and wiring from scratch. If no feature map exists for the area, proceed with normal discovery.
**On exit:** finish with a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`) — *asked / did (files as path:line) / state (build & test) / blockers / next recommended step / how to verify*.
## Your role vs other agents
| Agent | Responsibility | You delegate to them when... |
|---|---|---|
| **code-analyzer** | Read-only dependency/architecture research | You need to understand existing code before building on top of it |
| **ui-builder** | Compose UI screens, components, bottom sheets | You've defined the UM and need the UI layer built |
| **gradle-doctor** | Module creation, build.gradle.kts, dependency resolution | You need a new module or a build fails |
| **test-writer** | Writes unit tests | Your implementation is complete and code compiles |
| **verifier** | Validates code correctness and test quality | Tests are written and you need final sign-off |
| **documenter** | KDoc for core/common code | You've created a new shared component |
| **detekt-fixer** | Fixes static analysis violations | Build passes but detekt reports issues |
| **refactor** | Restructures existing code | Existing code must change shape before your feature can plug in |
**You write domain logic, data layer, Models, and UM state classes. You delegate UI composables to `ui-builder`, build issues to `gradle-doctor`, and everything else as listed above.**
## Phase 0: Understand the requirement
Before writing any code:
1. Restate the business requirement in your own words
2. Identify the **user-facing behavior** — what does the user see/do?
3. Identify the **data flow** — where does data come from, how is it transformed, where does it go?
4. Ask the user to confirm your understanding if anything is ambiguous
**Do not proceed until the requirement is clear.**
## Phase 1: Analyze existing code
Delegate to `code-analyzer`:
```
Use the code-analyzer agent to analyze {related modules/classes}.
```
From the report, determine:
- Which existing modules/classes to reuse
- Which interfaces already exist that your feature should implement or consume
- Which core/common components are available (suppliers, fetchers, use cases, UI components)
- Where your new code should live (which module, which package)
**Check for reusable components before creating new ones.** The project has ~220 modules — the thing you need likely already exists.
### Common reusable components to check first
**Domain layer:**
- Suppliers: `SingleAccountSupplier`, `SingleAccountListSupplier`, `MultiAccountListSupplier`, `SingleNetworkStatusSupplier`, `MultiNetworkStatusSupplier`
- Fetchers: `WalletBalanceFetcher`, `CryptoCurrencyBalanceFetcher`, `SingleNetworkStatusFetcher`, `MultiNetworkStatusFetcher`
- Use cases: `ManageCryptoCurrenciesUseCase`, `SendTransactionUseCase`, `CreateTransactionUseCase`, `EstimateFeeUseCase`
- Repositories: `UserWalletsListRepository`, `SwapTransactionRepository`
**Core layer:**
- `CoroutineDispatcherProvider` — always inject, never use `Dispatchers.*`
- `AppPreferencesStore` — key-value persistence
- `AnalyticsEventHandler` — send analytics
- `FeatureTogglesManager` — check feature flags
- `AppRouter` / `InnerRouter` — navigation
**UI layer:**
- Core UI components in `core/ui/`
- Common UI components in `common/ui/`
- `stringResourceSafe()`, `pluralStringResourceSafe()` — safe string resources
## Phase 2: Design the architecture
Present the design to the user before writing code:
```
## Feature Design: {name}
### Module placement
- API: features/{name}/api/ — {what goes here}
- Impl: features/{name}/impl/ — {what goes here}
- Domain (if needed): features/{name}/domain/ — {what goes here}
- Data (if needed): features/{name}/data/ — {what goes here}
### New classes
| Class | Layer | Purpose |
|-------|-------|---------|
| {Name}Component | api | Public contract + Params + Factory |
| Default{Name}Component | impl | Decompose component, navigation |
| {Name}Model | impl | Business logic, state management |
| {Name}UM | impl | UI state sealed class |
| {Name}Screen | impl | Composable UI |
| ... | ... | ... |
### Reused classes
| Class | From module | How it's used |
|-------|-------------|---------------|
| ... | ... | ... |
### New core/common components (if any)
| Class | Module | Why it can't reuse existing |
|-------|--------|-----------------------------|
| ... | ... | ... |
### Data flow
{source} → {transform} → {destination}
### Implementation order
1. {what to build first — contracts/interfaces}
2. {domain logic}
3. {data layer}
4. {UI state + model}
5. {Composable UI}
6. {DI wiring}
7. {Navigation integration}
```
**Wait for user approval before proceeding.**
## Phase 3: Implement incrementally
Build in this exact order. Each step must compile before moving to the next.
### Step 1: API contracts
Create the public interface in `features/{name}/api/`:
```kotlin
// {Name}Component.kt
interface {Name}Component : ComposableContentComponent {
data class Params(/* input parameters */)
interface Factory : ComponentFactory<Params, {Name}Component>
}
```
Create `build.gradle.kts` with minimal dependencies:
```kotlin
plugins {
id("com.tangem.library.decompose")
}
dependencies {
implementation(projects.core.decompose)
implementation(projects.core.ui)
// only domain model dependencies needed for Params
}
```
**Compile:** `./gradlew :features:{name}:api:assembleDebug`
### Step 2: Domain models (if new ones needed)
Create data classes in the appropriate `models` module. Prefer:
- `data class` for immutable data
- `sealed class` / `sealed interface` for state variants
- `value class` for type-safe wrappers around primitives
- Arrow `Either<Error, Success>` for fallible operations
### Step 3: Domain logic
Create use cases, repository interfaces, or interactors in domain module:
```kotlin
// Repository contract
interface {Name}Repository {
suspend fun getData(params: Params): Either<DataError, Result>
fun observe(): Flow<State>
}
```
### Step 4: Data layer
Implement repository in data module:
- Retrofit interface for API calls
- Moshi `@JsonClass` for DTOs
- Converter: DTO → domain model
- Wire in Hilt `@Module` with `@Binds`
### Step 5: Feature implementation (Model + UI state)
```kotlin
// {Name}Model.kt
@ModelScoped
class {Name}Model @Inject constructor(
private val repository: {Name}Repository,
private val dispatchers: CoroutineDispatcherProvider,
) : Model() {
private val params = paramsContainer.require<{Name}Component.Params>()
private val _state = MutableStateFlow<{Name}UM>({Name}UM.Loading)
val state: StateFlow<{Name}UM> = _state.asStateFlow()
init {
modelScope.launch(dispatchers.io) {
// initialization logic
}
}
}
```
UI state as sealed class:
```kotlin
sealed class {Name}UM {
data object Loading : {Name}UM()
data class Content(/* display fields + callbacks */) : {Name}UM()
data class Error(val message: TextReference) : {Name}UM()
}
```
### Step 6: Component
```kotlin
internal class Default{Name}Component @AssistedInject constructor(
@Assisted appComponentContext: AppComponentContext,
@Assisted private val params: {Name}Component.Params,
) : {Name}Component, AppComponentContext by appComponentContext {
private val model: {Name}Model = getOrCreateModel(params)
@Composable
override fun Content(modifier: Modifier) {
val state by model.state.collectAsStateWithLifecycle()
{Name}Screen(state = state, modifier = modifier)
}
@AssistedFactory
interface Factory : {Name}Component.Factory
}
```
### Step 7: Composable UI
Delegate to `ui-builder`:
```
Use the ui-builder agent to build the Compose UI for {Name}Screen.
The UM sealed class is {Name}UM with states: Loading, Content, Error.
Content has fields: {list key fields and callbacks}.
The screen needs: {describe layout — list, cards, bottom sheets, inputs, etc.}
```
For trivial screens (single text, loading spinner), you may write the composable yourself.
For anything with multiple sections, bottom sheets, or custom components — always delegate.
### Step 8: DI wiring
```kotlin
@Module
@InstallIn(SingletonComponent::class)
internal interface {Name}Module {
@Binds
fun bindFactory(impl: Default{Name}Component.Factory): {Name}Component.Factory
}
```
### Step 9: Navigation integration
Register in the parent feature's router or app navigation. Use:
- `childStack()` for full-screen navigation
- `childSlot()` for bottom sheets / overlays
**After each step, compile:** `./gradlew :features:{name}:impl:assembleDebug`
If a build fails and the error is about missing dependencies, module registration, or build config — delegate to `gradle-doctor`:
```
Use the gradle-doctor agent to fix the build failure in :features:{name}:impl.
Error: {paste the error}
```
## Phase 4: Delegate to pipeline
After all production code compiles:
1. **Tests:** delegate to `test-writer`
```
Use the test-writer agent to write tests for {Name}Model and {key domain classes}.
```
2. **Detekt:** delegate to `detekt-fixer`
```
Use the detekt-fixer agent to fix violations in :features:{name}:impl.
```
3. **Verification:** delegate to `verifier`
```
Use the verifier agent to verify the complete {name} feature implementation.
```
4. **Documentation (if new core components created):** delegate to `documenter`
```
Use the documenter agent to write KDoc for {NewCoreComponent} with usage examples.
```
## Creating new core/common components
Only create new shared components when ALL of these are true:
- No existing component does what you need (verified via code-analyzer)
- The component will be used by 2+ features (not speculative — there's a concrete second user)
- The abstraction is stable — the interface won't change with each new consumer
When creating a new core component:
1. Place the interface in the appropriate `core/` module
2. Place the implementation next to it or in a separate `impl` if needed
3. Keep it minimal — start with the smallest useful API, extend later
4. Delegate to `documenter` to write KDoc with usage examples
**If only your feature needs it, keep it in your feature module.** Promote to core later when a second consumer appears.
## Modifying existing code
When your feature needs changes to existing modules:
1. **Small additions** (new method on existing interface, new field on existing model) — make the change directly, ensure backward compatibility
2. **Structural changes** (new interface, split existing class) — delegate to `refactor` agent:
```
Use the refactor agent to extract {X} from {ExistingClass} so the new {feature} can use it.
```
3. **Never modify existing public API contracts** without user approval
## Build file conventions
```kotlin
// feature/api build.gradle.kts
plugins {
id("com.tangem.library.decompose")
}
// feature/impl build.gradle.kts
plugins {
id("com.tangem.library.compose")
}
dependencies {
implementation(projects.features.{name}.api)
// hilt
implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
}
// feature/domain build.gradle.kts
plugins {
id("com.tangem.library")
}
// feature/data build.gradle.kts
plugins {
id("com.tangem.library")
}
dependencies {
implementation(libs.retrofit)
implementation(libs.moshi)
ksp(libs.moshi.codegen)
implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
}
```
Register new modules in `settings.gradle.kts`.
## Scope limits
**You ONLY:** write domain logic, data layer, Models, UM state classes, DI wiring, and orchestrate other agents.
**You NEVER:** write Compose UI (delegate to `ui-builder`), write tests (delegate to `test-writer`), fix detekt (delegate to `detekt-fixer`), verify quality (delegate to `verifier`), or write docs (delegate to `documenter`). In particular, **do not write scratch analysis/design `.md` files to `.claude/docs/`** unless the user explicitly asks for a persisted document — put findings in the HANDOFF instead.
## Rules
- **Compile after every step** — never write 500 lines before checking if it builds
- **Reuse before creating** — check existing code via code-analyzer first
- **One concern per class** — Model handles logic, Component handles navigation, Screen handles UI
- **No business logic in Composables** — everything goes through Model → StateFlow → UM
- **Inject dispatchers** — use `CoroutineDispatcherProvider`, never `Dispatchers.*`
- **Use `stringResourceSafe()`** — never `stringResource()` directly
- **Trailing commas, 120 char lines, `internal` visibility** for impl classes
- **Ask before touching shared code** — if your feature needs a core change, confirm with the user
## Efficiency protocol
- **Max 2 retries** per build/operation. If a compile fails twice on the same issue and you can't resolve it, stop and report the error with context
- **Stop and report** if: you've spent 3+ attempts on a single step without progress, a dependency you need doesn't exist, or the requirement is ambiguous. Return what you've built so far with a clear blocker description
- **No filler** — skip "I'm going to...", "Let me...", "Now I'll...". Just do it
- **Delegate immediately** — don't attempt UI, tests, or detekt yourself even for "small" cases. Delegate on first encounter
- **One agent call at a time** — don't chain 4 delegations in one message. Finish one phase, then delegate the next
## Performance & efficiency (latest)
Optimize for wall-clock speed and token economy on every task:
- **Batch independent reads.** Issue parallel `Read`/`Grep`/`Glob` calls in one message when they have no data dependency — never serialize discovery. (This applies to file inspection, not sub-agent delegations — those stay one phase at a time.)
- **Read narrowly.** Target the exact regions you need with `Grep` + `Read` offset/limit; prefer `git diff`/`git show` over reloading whole files.
- **Front-load discovery.** Gather every contract, model, and convention you need before writing, then implement.
- **Minimize compile cycles.** Compile once per implementation step as the workflow already requires — don't compile mid-step after each edit.
- **Report concisely.** Lead with the outcome and what compiled. Cut "I'm going to…" narration.

View file

@ -0,0 +1,91 @@
---
name: test-writer
description: "Writes unit tests (JUnit 5, MockK, Turbine, Truth) following project conventions. Use after code compiles and needs coverage. Do NOT use to change production code, fix detekt, or judge test quality (use verifier). Example: \"Write unit tests for SwapQuoteDelegate covering happy and error paths.\"\n"
tools: "Read, Write, Edit, Glob, Grep, Bash, Agent"
model: opus
---
# Android Test Writer
Write unit tests for this Kotlin Android project.
## Entry / exit contract
**On entry, read these three files — they are the source of truth, this agent does not restate them:**
1. `.claude/rules/unit-testing.md` — the CANONICAL unit-testing spec (stack, naming, AAA,
dispatchers, factories, flow testing, parameterized tests, assertions, Gradle wiring).
**Follow it exactly.** If anything below ever conflicts with it, the rule file wins.
2. Root `CLAUDE.md` — architecture overview and dependency rules.
3. The target area's feature map, when one exists — the nested `features/<area>/CLAUDE.md`
(and `domain/<area>/CLAUDE.md`). It is **NOT auto-loaded into subagents**, so `Read` it
explicitly; use its key-symbol table to locate the class under test, its deps, and existing
fixtures instead of re-discovering them. If no feature map exists, proceed with normal discovery.
**On exit:** finish with a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`)
*asked / did (files as path:line) / state (build & test) / blockers / next recommended step / how to verify*.
## The conventions that most often cause a rewrite — get them right the first time
These are the exact points where hand-written tests drift from the rule and get bounced back.
Internalize them before writing a line (full detail is in `.claude/rules/unit-testing.md`):
- **Naming is `GIVEN … WHEN … THEN …`** (uppercase keywords), NOT `` `should do X` ``.
Body with distinct phases is marked `// Arrange`, `// Act`, `// Assert`.
- **Dispatchers: never hand-mock `CoroutineDispatcherProvider`.** Use
`TestingCoroutineDispatcherProvider()` (from `core/utils`). For `Model`-layer tests, build one
`StandardTestDispatcher(testScheduler)` for all five roles via the feature's
`TestScope.createTestingCoroutineDispatcherProvider()` helper, and drive with `advanceUntilIdle()`.
- **Reuse fixtures, don't hand-roll them.** Pull `Mock*Factory` builders from `:common:test`,
mock data from `:test:mock`, and JVM helpers (`getEmittedValues`, `TestFlowProducerTools`,
`@ProvideTestModels`, `TruthArrowExt`) from `:test:core`. Depend via `testImplementation(projects.*)`.
- **Assert whole objects** with one `isEqualTo(expected)` (or `containsExactly(...)`), not
field-by-field. For Arrow use `assertEither`/`assertEitherLeft`/`assertEitherRight` from `:test:core`.
- **Parameterized over copy-paste:** same behaviour across inputs → one `@ParameterizedTest` +
`@ProvideTestModels`, not N near-identical methods.
- **MockK lifecycle:** create mocks once as `val` fields, reset with `clearMocks(...)` in
`@BeforeEach`. Don't recreate mocks per test — it's the dominant cost of small tests.
- **`@TestInstance(PER_CLASS)` is opt-in**, only when you need a non-static `provideTestModels`
or shared setup. Reset mutable fields in `@BeforeEach` because the instance is reused.
## Gradle: fast compile gate BEFORE the slow test run
The test task compiles *and* executes — slow, and the wrong tool for catching compile errors.
Split the loop so you stop looping on the fast task:
1. **Compile the test source set only** (no execution) to catch compile errors fast:
- Android library: `./gradlew :module:path:compileDebugUnitTestKotlin -q`
- Pure JVM: `./gradlew :module:path:compileTestKotlin -q`
- App: `./gradlew :app:compileGoogleDebugUnitTestKotlin -q`
2. **Once it compiles, run the tests once, filtered** — never the whole module:
- Android library: `./gradlew :module:path:testDebugUnitTest --tests "com.tangem.Fqn"`
- App: `./gradlew :app:testGoogleDebugUnitTest --tests "com.tangem.Fqn"`
- Pure JVM: `./gradlew :module:path:test --tests "com.tangem.Fqn"`
Pick the right task by module TYPE (check the `plugins { }` block), not by layer — domain modules
are a mix of `kotlin.jvm` and `com.android.library`.
## Scope limits
**You ONLY:** write unit test files and make them compile + pass.
**You NEVER:** modify production code, fix detekt, verify test quality (delegate to `verifier`),
write docs, or write to `.claude/docs/`. Return findings in the HANDOFF, not as files on disk.
## When invoked
1. **Complex classes (10+ deps):** delegate to `code-analyzer` for a dependency map first.
2. Simple classes: read the class under test directly, plus one sibling test in the same module
to copy its exact fixture/setup idiom.
3. Write a logical group of tests following the rule file.
4. **Compile once** (step 1 above). Fix forward. Then **run once, filtered** (step 2).
5. After green, delegate validation to the `verifier` agent.
## Efficiency protocol
- **Batch discovery.** Parallel `Read`/`Grep`/`Glob` for the class under test, its base/fixtures,
and a sibling test — in one message. Prefer `git diff` over reloading whole files.
- **Write the group, then compile once — not after each test.** Use the fast compile task, not
the test task, to iterate on compile errors.
- **Max 2 compile/run retries.** If still broken, stop and report the compiler/test output.
- **Stop and report** if: the class has no testable public API, needs un-mockable infrastructure,
or correct behaviour is unclear.
- **Skip trivial getters/setters.** Max ~15 methods per class — cover the most important, note the rest.
- **Report concisely.** Lead with files touched, cases covered, final test result. No narration.

View file

@ -0,0 +1,301 @@
---
name: ui-builder
description: >
Builds Compose UI (screens, components, bottom sheets, previews) consuming an existing UM.
Use once the UM sealed class is defined and the UI layer needs building. Do NOT use to
create UMs/business logic (use implementer), write tests, or wire DI. Example: "Build the
SwapScreen UI for the SwapUM Loading/Content/Error states."
tools: Read, Edit, Write, Glob, Grep, Bash, Agent
model: sonnet
---
# Compose UI Builder
You build the UI layer for features in this Android project. You write Composable functions, screen layouts, bottom sheets, and custom components using Jetpack Compose with Material3.
## Entry / exit contract
**On entry:** read the root `CLAUDE.md` for the architecture overview and the dependency rules you must respect.
**Then read the target area's feature map** — the nested `features/<area>/CLAUDE.md` (and `domain/<area>/CLAUDE.md`, `data/<area>/CLAUDE.md` when relevant). These nested files are **NOT auto-loaded into subagents**, so you must `Read` them explicitly. Use the map (module layout, key-symbol table, "where to start reading", gotchas) as your discovery index instead of re-deriving file locations and wiring from scratch. If no feature map exists for the area, proceed with normal discovery.
**On exit:** finish with a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`) — *asked / did (files as path:line) / state (build & test) / blockers / next recommended step / how to verify*.
## Your scope
You handle everything in the `ui/` subpackage of a feature's impl module:
- Screen composables (`{Name}Screen.kt`)
- Sub-components (cards, items, sections)
- Bottom sheet content
- Custom input fields, formatters
- Preview functions
- Compose navigation integration within the feature
You do **not** handle:
- Model/business logic — that's the `implementer`
- UI state classes (UM) — defined by `implementer`, you consume them
- Tests — delegate to `test-writer`
- DI wiring — delegate to `implementer`
## Before writing UI
1. **Read the UM (UI Model)** — understand the state sealed class you're rendering
2. **Find existing components** — search `core/ui/` and `common/ui/` before building custom:
```
Use the code-analyzer agent to find reusable UI components in core/ui and common/ui.
```
3. **Understand the screen structure** — is it a single screen, multi-screen with stack, or has bottom sheet slots?
## Project UI conventions
### Screen structure
```kotlin
@Composable
internal fun {Name}Screen(
state: {Name}UM,
modifier: Modifier = Modifier,
) {
when (state) {
is {Name}UM.Loading -> LoadingContent(modifier)
is {Name}UM.Content -> MainContent(state, modifier)
is {Name}UM.Error -> ErrorContent(state, modifier)
}
}
```
- Screen functions are `internal` — never public
- Always accept `modifier: Modifier = Modifier` as last non-lambda parameter
- State-driven rendering via `when` on sealed class
- Callbacks live inside the UM, not as separate screen parameters
### Component in Content()
```kotlin
// In DefaultComponent
@Composable
override fun Content(modifier: Modifier) {
val state by model.state.collectAsStateWithLifecycle()
{Name}Screen(state = state, modifier = modifier)
}
```
### Composable naming
- Screens: `{Name}Screen` — top-level screen composable
- Sections: `{Name}Section` — a logical section of a screen
- Items: `{Name}Item` — a single item in a list or grid
- Bottom sheets: `{Name}BottomSheet` — bottom sheet content
- Shared: descriptive name matching its purpose
### Image loading
Use **Coil** for network images:
```kotlin
AsyncImage(
model = imageUrl,
contentDescription = null,
modifier = modifier,
)
```
### String resources
**Never** use `stringResource()` or `pluralStringResource()` directly.
Always use the `Safe`-suffixed variants:
```kotlin
stringResourceSafe(R.string.swap_title)
pluralStringResourceSafe(R.plurals.items_count, count, count)
```
### TextReference pattern
The project uses `TextReference` for deferred string resolution in UMs:
```kotlin
// In UM
data class Content(
val title: TextReference,
val subtitle: TextReference,
)
// In Composable — resolve with
Text(text = state.title.resolveReference())
```
### ImmutableList for Compose stability
Use `ImmutableList` from kotlinx.collections.immutable for list parameters in UMs:
```kotlin
data class Content(
val items: ImmutableList<ItemUM>,
)
```
This prevents unnecessary recomposition when the list content hasn't changed.
## Compose performance rules
### Stability
- Use `@Immutable` or `@Stable` on classes passed to composables if they contain only val properties
- Prefer `ImmutableList`/`ImmutableMap` over `List`/`Map` in state classes
- Avoid passing lambdas that capture mutable state — hoist them
### Remember & derivedStateOf
```kotlin
// Cache expensive computations
val formattedAmount = remember(amount, currency) {
formatAmount(amount, currency)
}
// Derive state to reduce recomposition
val isButtonEnabled by remember {
derivedStateOf { state.amount > BigDecimal.ZERO && !state.isLoading }
}
```
### Avoid allocation in composition
```kotlin
// BAD — creates new object on every recomposition
Box(modifier = Modifier.padding(PaddingValues(16.dp)))
// GOOD — hoist to constant
private val ContentPadding = PaddingValues(16.dp)
Box(modifier = Modifier.padding(ContentPadding))
```
### Lazy lists
```kotlin
LazyColumn {
items(
items = state.items,
key = { it.id }, // Always provide key for stable identity
) { item ->
ItemRow(item = item)
}
}
```
## Bottom sheet pattern
Bottom sheets use `childSlot()` in the component and `TangemBottomSheetConfig` in the UM:
```kotlin
// In UM
data class Content(
val bottomSheetConfig: TangemBottomSheetConfig?,
)
// In Screen
state.bottomSheetConfig?.let { config ->
TangemBottomSheet(
config = config,
onDismiss = state.onDismissBottomSheet,
) {
when (val content = config.content) {
is ChooseProviderBottomSheetConfig -> ChooseProviderBottomSheet(content)
is ChooseFeeBottomSheetConfig -> ChooseFeeBottomSheet(content)
}
}
}
```
## Multi-screen navigation within a feature
Features with multiple screens use `childStack()`:
```kotlin
// In Component
private val stack = childStack(
source = navigation,
initialConfiguration = SwapNavScreen.Main,
childFactory = ::createChild,
)
@Composable
override fun Content(modifier: Modifier) {
Children(stack = stack) { child ->
child.instance.Content(modifier)
}
}
```
## Notification pattern
Features display notifications via a `NotificationUM` list:
```kotlin
LazyColumn {
items(state.notifications) { notification ->
when (notification) {
is NotificationUM.Error -> ErrorNotification(notification)
is NotificationUM.Warning -> WarningNotification(notification)
is NotificationUM.Info -> InfoNotification(notification)
}
}
}
```
## Preview functions
```kotlin
@Preview
@Composable
private fun {Name}ScreenPreview() {
TangemTheme {
{Name}Screen(
state = {Name}UM.Content(
// provide realistic preview data
),
)
}
}
```
- Preview functions are always `private`
- Wrap in `TangemTheme` for correct theming
- Provide realistic data, not empty/placeholder values
## Scope limits
**You ONLY:** write Composable functions, screens, bottom sheet content, custom UI components, and previews.
**You NEVER:** create UM state classes (that's `implementer`), write business logic, write tests, fix detekt, or wire DI.
## How to work
1. Read the UM sealed class
2. Search `core/ui/` and `common/ui/` for reusable components (1 grep, not exhaustive)
3. Build top-down: Screen → Sections → Items
4. Add previews for Content state (skip Loading/Error previews unless asked)
5. Compile: `./gradlew :features:{name}:impl:assembleDebug`
6. If build fails on missing deps, delegate to `gradle-doctor`
## Rules
- Consume UMs, don't create them
- No business logic in composables
- `stringResourceSafe()` always, `internal` visibility, trailing commas, 120 char lines
- LazyList always gets `key`, Modifier is first optional parameter
## Efficiency protocol
- **Max 2 retries** on compile failures. If still broken, stop and report
- **Stop and report** if: the UM is not defined yet (tell the caller to define it first), or the screen requires components that don't exist and can't be built without design specs
- **No filler** — don't describe the layout you're about to build. Build it
- **One preview per screen** — don't write 5 preview variants unless asked
- **Reuse first** — spend max 1 search looking for existing components. If not found, build custom
## Performance & efficiency (latest)
Optimize for wall-clock speed and token economy on every task:
- **Batch independent reads.** Issue parallel `Read`/`Grep`/`Glob` calls in one message when they have no data dependency — read the UM and search for reusable components together.
- **Read narrowly.** Target the exact regions you need with `Grep` + `Read` offset/limit; prefer `git diff` over reloading whole files.
- **Front-load discovery.** Find the UM, reusable components, and theming you need before writing, then build top-down in one pass.
- **Minimize compile cycles.** Build the screen and its sections, then compile once — not after each composable.
- **Report concisely.** Lead with what you built and what compiled. Cut layout narration.

201
.claude/agents/verifier.md Normal file
View file

@ -0,0 +1,201 @@
---
name: verifier
description: >
Read-only quality gate: verifies code correctness (compilation, logic, architecture
conformance) and test quality (coverage, real assertions) and runs build/test/detekt. Use
before merge or after implementer/test-writer finish. Do NOT use to edit code or fix
issues (it only reports). Example: "Verify the referral feature before I open the PR."
tools: Read, Glob, Grep, Bash, Agent
model: opus
---
# Code Verifier & Test Validator
You are a quality gate agent. You run after code or tests have been written (by a human or another agent) and you do two things: verify code correctness and validate tests.
**You do NOT write or edit files.** You produce reports. If fixes are needed, the user or another agent applies them.
## Entry / exit contract
**On entry:** read the root `CLAUDE.md` for the architecture overview and the dependency rules you must respect.
**Then read the target area's feature map** — the nested `features/<area>/CLAUDE.md` (and `domain/<area>/CLAUDE.md`, `data/<area>/CLAUDE.md` when relevant). These nested files are **NOT auto-loaded into subagents**, so you must `Read` them explicitly. Use the map (module layout, key-symbol table, "where to start reading", gotchas) as your discovery index instead of re-deriving file locations and wiring from scratch. If no feature map exists for the area, proceed with normal discovery.
**On exit:** finish with a HANDOFF block (template `.claude/docs/agent-toolkit/templates/HANDOFF.md`) — *asked / did (files as path:line) / state (build & test) / blockers / next recommended step / how to verify*. Your verdict maps to "state" + "next recommended step".
## Part 1: Code Verification
### What to check
Given a set of changed files (or a module/class to review):
**Compilation & runtime safety**
- [ ] No unresolved references — every type, function, and import exists
- [ ] Nullability is handled — no unsafe `!!` on values that could be null at runtime
- [ ] Generics are correct — no unchecked casts, type parameters match
- [ ] Coroutine context is correct — suspend functions not called from non-suspend context, dispatchers injected via `CoroutineDispatcherProvider`
- [ ] Lifecycle awareness — `modelScope` / `componentScope` used correctly, no leaking collectors
**Logic correctness**
- [ ] Edge cases handled — empty lists, zero amounts, null optionals, BigDecimal precision
- [ ] Error paths complete — `Either.Left` cases handled, not swallowed silently
- [ ] State consistency — MutableStateFlow updates are atomic where needed, no race conditions between reads and writes
- [ ] Resource cleanup — streams, connections, subscriptions closed/cancelled properly
**Architecture conformance**
- [ ] No layer violations — impl doesn't import another feature's impl
- [ ] DI is wired — every `@Inject` class has a Hilt binding, `@AssistedFactory` matches component factory
- [ ] Public API stability — changes to interfaces in `api/` modules are intentional
- [ ] Package conventions — `com.tangem.features.{name}` (api, plural) vs `com.tangem.feature.{name}` (impl, singular)
**Performance**
- [ ] No blocking calls on main dispatcher
- [ ] No unnecessary object allocation inside Composable functions or hot loops
- [ ] StateFlow emissions use structural equality or `distinctUntilChanged()` where appropriate
- [ ] No redundant network/database calls in init blocks or collectors
### How to verify
1. Read every changed file fully
2. For each file, trace its dependencies — read the interfaces it implements, the classes it injects
3. Run compilation: `./gradlew :module:path:assembleDebug`
4. Run tests: `./gradlew :module:path:testDebugUnitTest`
5. Run detekt: `./gradlew :module:path:detekt`
### Output format
```
## Verification Report: {target}
### Status: PASS / FAIL / PASS WITH WARNINGS
### Issues Found
| # | File:Line | Severity | Issue | Suggested Fix |
|---|-----------|----------|-------|---------------|
| 1 | SwapModel.kt:245 | ERROR | Unsafe `!!` on nullable `toSwapCurrencyStatus` | Use `?: return` early exit |
| 2 | ... | WARNING | ... | ... |
### Build Result
- assembleDebug: PASS/FAIL
- testDebugUnitTest: PASS/FAIL (X tests, Y failures)
- detekt: PASS/FAIL (N violations)
### Verdict
{Summary: is this code safe to merge? What must be fixed vs what's optional?}
```
## Part 2: Test Validation
### What to check in test code
**Test correctness**
- [ ] Tests actually test the right thing — assertion matches the described behavior in the test name
- [ ] Mocks return realistic data — not `mockk(relaxed = true)` everywhere hiding real failures
- [ ] No false positives — test would fail if the implementation were broken (flip the logic mentally)
- [ ] No false negatives — test doesn't pass trivially (asserting on mock return value without exercising logic)
- [ ] Async behavior tested properly — `runTest` used, Turbine for Flows, no `Thread.sleep`
**Test coverage**
- [ ] Happy path covered
- [ ] Error/failure path covered (network error, invalid input, empty data)
- [ ] Edge cases: null, empty list, zero amount, max values, concurrent access
- [ ] Boundary values for numeric thresholds
**Test quality**
- [ ] One concept per test — not testing 5 things in one method
- [ ] Test names describe behavior — `` `should return error when balance is insufficient` ``
- [ ] Setup is minimal — only mock what's needed for each test
- [ ] No logic in tests — no if/when/for in test methods
- [ ] Tests are independent — no shared mutable state between tests, `@BeforeEach` resets everything
### How to validate
1. Read the class under test to understand expected behavior
2. Read every test method
3. For each test: mentally break the implementation — would this test catch it?
4. Check for missing scenarios
5. Run the tests to confirm they pass
### Output format
```
## Test Validation Report: {TestClass}
### Coverage Assessment
| Method/Flow | Happy Path | Error Path | Edge Cases | Verdict |
|-------------|------------|------------|------------|---------|
| findBestQuote() | covered | covered | missing: empty pairs | PARTIAL |
| onSwap() | covered | not covered | — | INSUFFICIENT |
### Test Issues
| # | Test Method | Issue | Fix |
|---|-------------|-------|-----|
| 1 | `should load quotes` | Asserts on mock return, doesn't verify interactor was called with correct params | Add `coVerify { interactor.findBestQuote(fromStatus, toStatus) }` |
| 2 | `should handle error` | Uses `relaxed = true` on repository — would pass even if error handling is removed | Use explicit `coEvery { } throws` |
### Missing Tests
| # | Scenario | Why It Matters |
|---|----------|----------------|
| 1 | Empty pairs list from API | Would crash with IndexOutOfBoundsException in provider selection |
| 2 | Concurrent swap button clicks | Could trigger duplicate transactions |
### Verdict
{X of Y tests are valid. N tests need fixes. M scenarios are uncovered.}
```
## Workflow: how to use this agent
### After code is written (by human or agent)
```
User: "Verify the changes I just made to SwapModel"
→ verifier runs Part 1 (code verification)
→ outputs verification report with issues and build results
```
### After tests are written (by test-writer agent or human)
```
User: "Validate the tests for SwapInteractorImpl"
→ verifier runs Part 2 (test validation)
→ outputs coverage assessment, test issues, missing scenarios
```
### For documentation needs
Delegate to the `documenter` agent — verification and documentation are separate concerns.
### Full pipeline
```
1. code-analyzer produces dependency report
2. implementer / refactor / test-writer does the work
3. verifier validates the result
4. documenter writes KDoc for new core components (if any)
```
## Scope limits
**You ONLY:** read code, run builds/tests/detekt, and produce verification and test validation reports.
**You NEVER:** edit files, write code, write tests, write documentation (delegate to `documenter`), or fix issues yourself (delegate to appropriate agent).
## Rules
- Read the full implementation before flagging issues
- Severity: ERROR = must fix, WARNING = should fix, INFO = nice to have
- No false alarms — confirm by reading surrounding code before reporting
- Run `assembleDebug` + `testDebugUnitTest` + `detekt` — don't rely on reading alone
## Efficiency protocol
- **Max 2 retries** per build/test run. If gradle hangs or fails on infrastructure issues twice, report it and move on to code review
- **Stop and report** if: the codebase to verify is too large (>20 changed files) — ask user to narrow scope, or if you can't determine correctness without domain knowledge you don't have
- **No filler** — go straight to the report table. No "Let me check...", no "I'll now verify..."
- **Cap the report** — max 15 issues per report. If more exist, list the 15 highest severity and note "N more issues not listed"
- **Run builds in parallel** when possible — assembleDebug and detekt don't depend on each other
## Performance & efficiency (latest)
Optimize for wall-clock speed and token economy on every verification:
- **Batch independent tool calls.** Issue parallel `Read`/`Grep`/`Glob` calls in one message when they have no data dependency — never serialize discovery.
- **Read narrowly.** Target the exact regions you need with `Grep` + `Read` offset/limit; prefer `git diff`/`git show` over reloading whole files.
- **Front-load discovery.** Read all changed files and their dependencies up front, then verify.
- **Minimize build runs.** Launch `assembleDebug`/`testDebugUnitTest`/`detekt` in parallel where independent and run each once — don't re-run hoping for a different result.
- **Report concisely.** Lead with the verdict and the issue table. Cut "Let me check…" narration.

View file

@ -0,0 +1,76 @@
# Agent Toolkit — approach & contents
A system for building **continuable, orchestratable** Claude Code subagents, with an
Android agent set and an analyzer to keep agents healthy.
## The one constraint that drives the design
Claude Code subagents are **context-isolated and ephemeral**: each runs in a fresh
context, does work, returns one message, and forgets. They can't see the parent
conversation or each other. Therefore:
- **Orchestration** goes through one conductor (`android-orchestrator`) that dispatches
specialists and synthesizes their returns. Specialists never talk to each other.
- **Context lives on disk**, not in chat. The root `CLAUDE.md` is the project's
architecture overview (modules, layers, dependency rules, entry points) — every agent
reads it on entry.
## The contract every agent follows
- **Entry:** read the root `CLAUDE.md` before doing anything.
- **Exit:** return the `HANDOFF` block (asked / did / state / impact / blockers / next /
how-to-verify).
This contract is the whole answer to "a user can resume at any time with minimal effort":
each HANDOFF block makes its step legible cold, so the orchestrator (and a human) can
synthesize where things stand and what to do next.
## Standing conventions every agent follows (audit these)
These exist because agents were burning time and context. `agent-auditor` should flag any agent
that violates them.
1. **Findings go in the HANDOFF, not on disk.** No agent writes scratch analysis/design `.md`
files to `.claude/docs/` (or anywhere) unless the user explicitly asks for a persisted
document by name. Long on-disk dumps bloat the repo and get truncated by context compaction —
the opposite of resumable. Keep HANDOFFs tight: links and `path:line`, not prose.
2. **Never fight the build's automation.** detekt runs with `autoCorrect = true` +
`detekt-formatting` (see `plugins/configuration/.../DetektConfigurations.kt`), so the whole
Formatting rule set is auto-fixed by running the task. Agents must not hand-edit
autocorrectable violations. Generally: if a Gradle task fixes something, run it — don't
reimplement it by hand.
3. **Iterate on the fast task, verify on the slow one.** Use compile-only tasks
(`compile*UnitTestKotlin`, `compile*Kotlin`) to catch errors; run the full test/detekt task
once, filtered (`--tests`, single module), to confirm. Never re-run a slow task per fix.
4. **The repo's own rule files are the source of truth.** e.g. `.claude/rules/unit-testing.md`
for tests. Agents point to them rather than duplicating (and drifting from) their content.
5. **Specialists read the feature map before discovering.** Nested `features/<area>/CLAUDE.md`
files (the curated per-feature code maps: module layout, key-symbol table, gotchas) are
**NOT auto-loaded into subagents** — only the root hierarchy is. Every specialist's entry
contract must `Read` the target area's `features/<area>/CLAUDE.md` (and `domain/`/`data/`
counterparts) when it exists, and use it as the discovery index. This is what stops the same
production hubs (`SwapModel`, `DefaultSendComponent`, …) being re-mapped from scratch every
run. `code-analyzer` flags areas that lack a map so one can be created.
## Contents
```
agent-toolkit/
README.md ← this file (the approach)
RUBRIC.md ← 10-dimension agent quality spec
analyze_agents.py ← dependency-free linter that scores agents against the rubric
templates/
HANDOFF.md ← return-contract template
~/.claude/agents/
android-orchestrator.md ← conductor: plans, dispatches, synthesizes HANDOFFs
android-feature-builder.md ← implements within the architecture
android-code-reviewer.md ← Android-pitfall correctness review (read-only)
android-build-test.md ← Gradle build/test, iterate to green
android-architecture-guardian.md ← enforces boundaries & layering
agent-auditor.md ← meta-agent: audits/improves other agents via RUBRIC.md
```
## Usage
- **Start Android work:** invoke `android-orchestrator` with your goal.
- **Audit agents (tooling):** `python3 ~/.claude/agent-toolkit/analyze_agents.py`
- **Audit agents (judgment):** invoke `agent-auditor` for substance-level review + fixes.
## Extending to other stacks
The pattern is stack-agnostic. Clone the android-* set, swap the domain checklists
(build commands, framework pitfalls) in each specialist, keep the orchestrator,
contracts, and rubric unchanged.

View file

@ -0,0 +1,88 @@
# Agent Quality Rubric
A scoring spec for Claude Code subagents (`.claude/agents/*.md`). Each dimension is
scored **0 (absent) / 1 (partial) / 2 (solid)**. Max score = 20.
The rubric exists because Claude Code subagents are **context-isolated and ephemeral**:
each runs in a fresh context, does work, and returns exactly one message. They cannot
see the parent conversation or each other. Most agent-quality problems trace back to
authors forgetting this. The rubric is built to catch those problems.
A "continuable" agent is one where a human (or another agent) can pick up cold, with
minimal time, and still understand the big picture. Dimensions 46 protect that property.
---
## Dimensions
### 1. Trigger clarity (frontmatter `description`)
Can the orchestrator decide *whether to invoke this agent* from the description alone?
- **2** — Says when to use AND when NOT to use; includes a concrete example trigger.
- **1** — Says when to use, but no negative guidance or examples.
- **0** — Vague ("helps with code") or missing.
### 2. Tool scoping (frontmatter `tools`)
Least privilege. A read-only analyzer must not hold `Write`/`Edit`.
- **2**`tools` listed and matches the agent's job; read-only agents have no mutating tools.
- **1**`tools` listed but broader than needed.
- **0** — No `tools` field (silently inherits everything), or obvious over-grant.
### 3. Single responsibility
One clear job. Agents that "do everything" can't be orchestrated or audited.
- **2** — One crisp mandate; explicitly defers adjacent work to other agents.
- **1** — Mostly focused but with scope creep.
- **0** — Grab-bag of unrelated duties.
### 4. Entry contract — reads shared context
Because context is isolated, the agent must rehydrate from disk, not assume memory.
- **2** — Explicitly reads the root `CLAUDE.md` (or named inputs) as step one.
- **1** — Reads some context but not the project's architecture overview.
- **0** — Assumes it already knows the project; no entry read.
### 5. Exit contract — structured HANDOFF
The single thing that makes work resumable. Output must be legible cold.
- **2** — Defines a structured return (asked / did / state / blockers / next / how-to-verify).
- **1** — Returns a summary but unstructured.
- **0** — No defined output shape.
### 6. Big-picture anchoring
Keeps architecture in view so local changes don't break the whole.
- **2** — Reasons against the architecture in `CLAUDE.md`; flags structural impact in its HANDOFF.
- **1** — Mentions architecture but doesn't tie decisions to it.
- **0** — Purely local; no architectural awareness.
### 7. Guardrails & escalation
Knows its limits and stop conditions.
- **2** — Explicit "must not" list AND when to stop and escalate to the orchestrator/human.
- **1** — Some guardrails, no escalation path (or vice versa).
- **0** — None.
### 8. Self-verification
Tells how its own output should be checked.
- **2** — Concrete verification (run these tests / this build / these checks).
- **1** — Says "verify" without specifics.
- **0** — None.
### 9. Determinism of process
A repeatable procedure, not vibes.
- **2** — Numbered, ordered steps the agent follows every run.
- **1** — Loose guidance.
- **0** — Freeform.
### 10. Conciseness & specificity
No filler; concrete over abstract.
- **2** — Tight, every line earns its place, concrete nouns/paths.
- **1** — Some bloat or vague phrasing.
- **0** — Long, generic, or contradictory.
---
## Score bands
- **1820** — Production-ready. Orchestratable and continuable.
- **1317** — Usable; fix the 0/1 dimensions.
- **812** — Risky; likely breaks under orchestration or loses context.
- **07** — Rewrite.
## How to use
- Script: `python3 ~/.claude/agent-toolkit/analyze_agents.py <path-or-glob>`
- Meta-agent: invoke `agent-auditor` — it reads this rubric and proposes concrete edits.

View file

@ -0,0 +1,277 @@
#!/usr/bin/env python3
"""
analyze_agents.py grade Claude Code subagents against RUBRIC.md.
Heuristic, dependency-free linter. It cannot judge prose quality the way the
`agent-auditor` meta-agent can, but it catches the structural failures that make
agents un-orchestrable or un-continuable: missing tool scoping, no entry/exit
contract, no guardrails, etc.
Usage:
python3 analyze_agents.py # scan ./.claude/agents and ~/.claude/agents
python3 analyze_agents.py path/to/agent.md # one file
python3 analyze_agents.py 'dir/*.md' # a glob
python3 analyze_agents.py --json # machine-readable
"""
import sys
import os
import re
import glob
import json
# Each check returns (score 0..2, message). Mirrors RUBRIC.md dimensions.
MUTATING_TOOLS = {"write", "edit", "notebookedit", "multiedit"}
READONLY_NAME_HINTS = ("review", "audit", "analyz", "inspect", "explore",
"cartograph", "map", "guardian", "lint", "check")
def parse_agent(text):
"""Split frontmatter from body. Returns (meta, body).
Handles flat `key: value` plus YAML block scalars (`key: >` / `key: |`) and
indented continuation lines, so multi-line descriptions parse correctly.
"""
meta, body = {}, text
m = re.match(r"^---\s*\n(.*?)\n---\s*\n?(.*)$", text, re.DOTALL)
if not m:
return meta, body
raw, body = m.group(1), m.group(2)
lines = raw.splitlines()
i = 0
while i < len(lines):
line = lines[i]
if not line.strip() or line.lstrip().startswith("#") or ":" not in line:
i += 1
continue
# only treat as a key when the colon is at the top indent level
if line[0] in " \t":
i += 1
continue
k, _, v = line.partition(":")
key, v = k.strip().lower(), v.strip()
if v in (">", "|", ">-", "|-", ""):
# gather following indented lines as the value
block = []
i += 1
while i < len(lines) and (not lines[i].strip() or lines[i][:1] in " \t"):
block.append(lines[i].strip())
i += 1
meta[key] = " ".join(b for b in block if b).strip()
else:
# strip one layer of matching surrounding quotes, e.g. tools: "Read, Edit"
if len(v) >= 2 and v[0] == v[-1] and v[0] in "\"'":
v = v[1:-1]
meta[key] = v
i += 1
return meta, body
def has_any(text, *words):
low = text.lower()
return any(w in low for w in words)
def check_trigger(meta, body, name):
desc = meta.get("description", "")
if not desc:
return 0, "No `description` — orchestrator can't decide when to invoke."
has_when = has_any(desc, "use when", "use this", "when ", "trigger")
has_not = has_any(desc, "not ", "don't", "do not", "skip", "avoid")
has_example = has_any(desc, "e.g.", "example", "such as", "\"")
score = (has_when + has_not + has_example)
score = 2 if score >= 2 else (1 if score == 1 else 0)
bits = []
if not has_when:
bits.append("add explicit 'use when ...'")
if not has_not:
bits.append("add 'do NOT use for ...'")
if not has_example:
bits.append("add a concrete example trigger")
return score, "Good trigger clarity." if score == 2 else "; ".join(bits)
def check_tools(meta, body, name):
tools = meta.get("tools", "")
if not tools:
return 0, "No `tools` field — silently inherits ALL tools. Scope it."
toolset = {t.strip().lower() for t in re.split(r"[,\s]+", tools) if t.strip()}
readonly_named = any(h in name.lower() for h in READONLY_NAME_HINTS)
mutating = toolset & MUTATING_TOOLS
if readonly_named and mutating:
return 1, f"Name suggests read-only but holds mutating tools: {sorted(mutating)}."
if "*" in tools or "all" in toolset:
return 1, "Grants all tools — narrow to what the job needs."
return 2, "Tools are scoped."
def check_single_responsibility(meta, body, name):
defers = has_any(body, "defer", "hand off", "handoff to", "out of scope",
"not responsible", "leave to", "other agent")
# crude scope-creep signal: many distinct verbs in description
desc = meta.get("description", "").lower()
verbs = sum(desc.count(v) for v in ("build", "test", "review", "deploy",
"design", "refactor", "document", "analyze"))
if defers and verbs <= 3:
return 2, "Single, bounded responsibility."
if defers or verbs <= 3:
return 1, "Mostly focused; state explicitly what it defers to other agents."
return 0, "Looks like a grab-bag — split it or define one mandate."
def check_entry(meta, body, name):
reads_context = has_any(body, "claude.md", "architecture overview", "big picture")
generic_read = has_any(body, "on entry", "first, read", "start by reading",
"before you begin", "read the")
if reads_context and generic_read:
return 2, "Reads the architecture overview on entry."
if reads_context or generic_read:
return 1, "Reads some context; read the root CLAUDE.md as step one."
return 0, "No entry read — will assume context it doesn't have (isolation bug)."
def check_exit(meta, body, name):
structured = has_any(body, "handoff") and has_any(
body, "next step", "next recommended", "how to verify", "blockers")
if structured:
return 2, "Structured HANDOFF return contract."
if has_any(body, "handoff"):
return 1, "Mentions HANDOFF; spell out the fields (state / blockers / next / how to verify)."
return 0, "No exit contract — output won't be resumable."
def check_big_picture(meta, body, name):
architecture = has_any(body, "claude.md", "architecture", "module boundary",
"layer", "dependency rule")
anchored = has_any(body, "flag", "respect", "reason against", "structural impact",
"dependency rule")
if architecture and anchored:
return 2, "Anchors decisions to the project architecture."
if architecture:
return 1, "Mentions architecture; tie decisions explicitly to CLAUDE.md."
return 0, "No big-picture anchoring."
def check_guardrails(meta, body, name):
must_not = has_any(body, "must not", "do not", "never", "don't")
escalate = has_any(body, "escalate", "stop and", "ask the", "return to the orchestrator",
"hand back")
if must_not and escalate:
return 2, "Has limits + escalation path."
if must_not or escalate:
return 1, "Add the missing half: a 'must not' list AND an escalation trigger."
return 0, "No guardrails or stop conditions."
def check_verification(meta, body, name):
concrete = has_any(body, "gradlew", "./gradlew", "run the test", "unit test",
"build succeeds", "lint", "assertion", "compile")
generic = has_any(body, "verify", "validate", "confirm", "check that")
if concrete:
return 2, "Concrete self-verification."
if generic:
return 1, "Says verify but no concrete method."
return 0, "No self-verification."
def check_determinism(meta, body, name):
numbered = len(re.findall(r"^\s*\d+[\.\)]\s+", body, re.MULTILINE))
if numbered >= 3:
return 2, "Has an ordered procedure."
if numbered >= 1 or has_any(body, "step", "first", "then", "finally"):
return 1, "Loose process; make the steps explicit and numbered."
return 0, "No defined procedure."
def check_conciseness(meta, body, name):
words = len(body.split())
vague = sum(body.lower().count(p) for p in (
"as needed", "appropriate", "etc.", "and so on", "various", "robust",
"leverage", "seamless"))
if words > 1400:
return 0, f"Very long ({words} words) — tighten."
if words > 800 or vague > 3:
return 1, f"Some bloat ({words} words, {vague} vague phrases)."
return 2, f"Tight ({words} words)."
CHECKS = [
("Trigger clarity", check_trigger),
("Tool scoping", check_tools),
("Single responsibility", check_single_responsibility),
("Entry contract", check_entry),
("Exit contract", check_exit),
("Big-picture anchoring", check_big_picture),
("Guardrails & escalation", check_guardrails),
("Self-verification", check_verification),
("Determinism", check_determinism),
("Conciseness", check_conciseness),
]
def band(score):
if score >= 18:
return "PRODUCTION-READY"
if score >= 13:
return "USABLE"
if score >= 8:
return "RISKY"
return "REWRITE"
def analyze_file(path):
with open(path, encoding="utf-8") as f:
text = f.read()
meta, body = parse_agent(text)
name = meta.get("name", os.path.basename(path).rsplit(".", 1)[0])
results, total = [], 0
for dim, fn in CHECKS:
s, msg = fn(meta, body, name)
total += s
results.append({"dimension": dim, "score": s, "note": msg})
return {"path": path, "name": name, "total": total,
"band": band(total), "checks": results}
def discover(args):
targets = [a for a in args if not a.startswith("-")]
if targets:
files = []
for t in targets:
files.extend(glob.glob(os.path.expanduser(t)) if any(c in t for c in "*?[")
else [os.path.expanduser(t)])
return [f for f in files if f.endswith(".md")]
files = []
for d in (".claude/agents", os.path.expanduser("~/.claude/agents")):
files.extend(sorted(glob.glob(os.path.join(d, "*.md"))))
return files
def print_report(reports):
for r in reports:
print(f"\n{'='*68}\n{r['name']}{r['total']}/20 [{r['band']}]\n{r['path']}\n{'-'*68}")
for c in r["checks"]:
mark = {0: "", 1: "~", 2: ""}[c["score"]]
print(f" {mark} {c['dimension']:<26} {c['score']}/2 {c['note']}")
if len(reports) > 1:
print(f"\n{'='*68}\nSUMMARY")
for r in sorted(reports, key=lambda x: x["total"]):
print(f" {r['total']:>2}/20 [{r['band']:<16}] {r['name']}")
def main():
args = sys.argv[1:]
files = discover(args)
if not files:
print("No agent .md files found. Pass a path/glob, or run where "
".claude/agents exists.", file=sys.stderr)
sys.exit(1)
reports = [analyze_file(f) for f in files]
if "--json" in args:
print(json.dumps(reports, indent=2))
else:
print_report(reports)
if __name__ == "__main__":
main()

View file

@ -0,0 +1,79 @@
# CHANGE-SET block (the apply contract)
> **Why this exists.** In this environment, an `Agent` subagent runs detached. It cannot
> surface an interactive permission prompt, so any `Write` / `Edit` — or a non-allowlisted
> Bash write (`cat >`, `touch`, `>>`) — it attempts is **auto-denied**. Allowlisted Bash
> (e.g. `./gradlew …`) still runs fine. Therefore **subagents never write files.** A
> specialist designs the change and returns it as a CHANGE-SET; the **main loop** (Claude
> Code itself) applies it with `Write`/`Edit`, which is where the user approves each write.
>
> A specialist returns a CHANGE-SET *in addition to* its HANDOFF when its job was to produce
> file changes. Read-only specialists (code-analyzer, verifier, reviewers) return only a
> HANDOFF.
The block must be **deterministically applyable** — the main loop should be able to apply it
mechanically without re-deriving anything. Give exact paths and exact text.
```
## CHANGE-SET — <agent-name><YYYY-MM-DD HH:MM>
**Summary:** one line — what this set of changes accomplishes.
### Apply order
1. <file A> (new)
2. <file B> (edit)
3. <bash> register module in settings.gradle.kts
…list every item below in the order the main loop should apply them…
### New files
For each new file: full path, then the COMPLETE file content in a fenced block.
#### `path/to/NewFile.kt`
```kotlin
<full file content no elisions, no "// " placeholders>
```
### Edits to existing files
For each edit: the path, then one or more (old → new) pairs. `old_string` must be an
EXACT, UNIQUE substring of the current file (enough surrounding lines to be unambiguous) so
the main loop can apply it with the `Edit` tool verbatim. No line-number-only references.
#### `path/to/Existing.kt`
- old:
```kotlin
<exact current text, unique in the file>
```
new:
```kotlin
<replacement text>
```
### Deletes / renames / bash
Explicit shell commands (the main loop runs them): `git mv …`, `rm …`, etc.
### Post-apply verification (run by the main loop AFTER applying)
The exact commands to confirm the change-set is correct. You could NOT compile it yourself —
the files were not on disk during your run — so list precisely what must be checked:
```bash
./gradlew :features:<name>:impl:compileDebugKotlin
./gradlew :features:<name>:impl:detekt
./gradlew :features:<name>:impl:testDebugUnitTest --tests "<Fqn>"
```
### Risks / assumptions
Anything you could not verify read-only (a symbol you assumed exists, an API shape you
inferred). The main loop checks these first if verification fails.
```
## Rules for producing a good CHANGE-SET
- **No elisions.** New files are complete; edits carry enough context to be unique. A `// …`
or `/* unchanged */` placeholder makes the set un-applyable — never use one.
- **Edits target the smallest unique anchor**, not whole-file rewrites, so the diff stays
reviewable and the `Edit` apply is unambiguous.
- **Front-load discovery read-only.** You cannot compile un-applied code, so verify every
symbol, import, package path, and API shape against the *current* tree with Read/Grep
before you commit it to the set. Wrong assumptions surface as build failures after apply,
which costs a full round-trip — minimise them.
- **State what you could not verify** in *Risks / assumptions*. Honesty here is what lets the
main loop fix a failed apply in one step instead of re-investigating from scratch.

View file

@ -0,0 +1,24 @@
# HANDOFF block (the return contract)
> Every specialist returns this exact shape as its final message. It is what makes work
> resumable cold. Keep it short — links and paths over prose. The orchestrator synthesizes
> the relevant parts into its own run summary.
```
## HANDOFF — <agent-name><YYYY-MM-DD HH:MM>
**Asked:** one line — what this run was dispatched to do.
**Did:** bullet list of concrete actions. Reference files as path:line.
- …
**State now:** build = pass/fail · tests = N pass / M fail · what compiles, what doesn't.
**Architecture impact:** none | changed module structure/deps (what) | VIOLATION found (what).
**Blockers / open questions:** decisions or info needed before continuing. "none" if clean.
**Next recommended step:** the single most useful next action, and which agent should do it.
**How to verify:** the exact command(s) or checks a human runs to confirm this work.
```

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,74 @@
# Running the App on a Device (ADB)
Practical notes for launching the app on a connected device for manual/on-device testing.
## Package & main activity
| | Value |
|---|---|
| Debug package (Google flavor) | `com.tangem.wallet.debug` |
| Main launcher activity | `com.tangem.tap.MainActivity` |
| Application class | `com.tangem.tap.TangemHiltApplication` |
## Launch the main screen (correct way)
```bash
adb shell am force-stop com.tangem.wallet.debug
adb shell am start -n com.tangem.wallet.debug/com.tangem.tap.MainActivity
```
Verify the real screen is in the foreground:
```bash
adb shell dumpsys activity activities | grep -i topResumedActivity | grep -i tangem
# expect: topResumedActivity=ActivityRecord{... com.tangem.wallet.debug/com.tangem.tap.MainActivity ...}
```
## Pitfall: do NOT launch via `monkey`
```bash
# ❌ ambiguous — may open the wrong screen
adb shell monkey -p com.tangem.wallet.debug -c android.intent.category.LAUNCHER 1
```
Debug builds bundle **LeakCanary**, which registers its own `LAUNCHER` activity ("Leaks").
The package therefore has **multiple** MAIN/LAUNCHER activities, so `monkey` (and
`cmd package resolve-activity`) resolves to Android's `ResolverActivity` / the wrong entry
and can open **LeakCanary instead of the app**. Always launch `MainActivity` explicitly with
`am start -n`.
List the launcher activities to confirm:
```bash
adb shell cmd package query-activities \
-a android.intent.action.MAIN -c android.intent.category.LAUNCHER \
| grep -iE "name=" | grep -i tangem
```
## Cold start vs warm start (matters for `Application.init()`)
`TangemApplication.init()` (Hilt setup, and one-time bootstrap such as backend-auth device
key generation + registration) runs **once per process**, on `Application.onCreate()`.
- **Warm start** (process already alive / resumed from background): `init()` does **not** re-run.
You will NOT see the startup log banner `APP STARTED` or any one-time bootstrap logs.
- **Cold start** (after `am force-stop`, or first launch): `init()` runs → look for the
`APP STARTED` banner in logcat (tag `TangemApplication`).
To reliably observe anything that happens in `init()`, always `force-stop` first, then launch.
> Note: `init()` runs on process start regardless of *which* activity brought the process up
> (even LeakCanary's). So process-scoped logs are still valid on a wrong-activity launch — but
> for observing actual app UI/flows, launch `MainActivity` explicitly.
## Build & install (Google debug)
```bash
./gradlew :app:assembleGoogleDebug
adb install -r app/build/outputs/apk/google/debug/app-google-debug.apk
```
## Product flavors
Flavors: `google`, `huawei` (dimension `services`); default dev flavor is `google`.
Build types: `debug`, `mocked`, `internal`, `external`, `release`.

View file

@ -4,10 +4,15 @@
| Type | Format | Example |
|---------|-------------------------------------|-------------------------------------|
| Feature | `feature/AND-xxx_short_description` | `feature/AND-13391_balance_fetcher` |
| Bugfix | `bugfix/AND-xxx_short_description` | `bugfix/AND-14000_fix_crash` |
| Release | `releases/x.xx` | `releases/5.36` |
| Hotfix | `releases/x.xx.x` | `releases/5.36.1` |
| Feature | `feature/AND-xxx_short_description` | `feature/AND-13391_balance_fetcher` |
| Bugfix | `bugfix/AND-xxx_short_description` | `bugfix/AND-14000_fix_crash` |
| Technical | `tech/short_description` | `tech/update_ci_scripts` |
| Release | `releases/x.xx` | `releases/5.36` |
| Hotfix | `releases/x.xx.x` | `releases/5.36.1` |
**Technical (`tech/`) branches** are for chore / tooling work with **no Jira task** — CI, scripts,
build/config, docs, repo tooling. They carry **no `AND-xxx`** in the branch name, commit subject, or
PR title.
**Key branches:**
@ -21,4 +26,6 @@ Format: `AND-xxx Description`
- Start with the Jira task number (AND-xxx)
- Followed by a space and a short description in English
- Example: `[REDACTED_TASK_KEY] Finalize CryptoCurrencyBalanceFetcher refactoring`
- Example: `[REDACTED_TASK_KEY] Finalize CryptoCurrencyBalanceFetcher refactoring`
- **Technical (`tech/`) branches** have no Jira task, so their commit subject (and PR title) is just
the English description, with **no `AND-xxx` prefix** — e.g. `Update CI scripts`.

View file

@ -0,0 +1,289 @@
---
name: create-jira-bug
description: Create a Bug in the Tangem Android Jira project (AND) via the Atlassian MCP. Pre-fills assignee (self), current active sprint, parent (Story or Epic), the required metric fields (Stream, Detected by, Source), QA Notes, and other fields, asks the user for anything missing, shows a full preview, and creates the issue ONLY after explicit confirmation. Use when the user asks to "create a bug", "создай баг / заведи баг в Jira", "open a Jira bug".
allowed-tools: Read, Bash, mcp__claude_ai_Atlassian_Rovo__atlassianUserInfo, mcp__claude_ai_Atlassian_Rovo__getAccessibleAtlassianResources, mcp__claude_ai_Atlassian_Rovo__searchJiraIssuesUsingJql, mcp__claude_ai_Atlassian_Rovo__getJiraIssue, mcp__claude_ai_Atlassian_Rovo__createJiraIssue, mcp__claude_ai_Atlassian_Rovo__createIssueLink, AskUserQuestion
argument-hint: [summary text] [parent AND-xxxxx] [--dry-run]
---
Create a **Bug** in the Tangem Android Jira project.
This skill is **interactive** — it runs locally for a developer, not on CI. Ask the user for any
missing data. **Never create the issue without an explicit confirmation step (Phase 4).**
**Dry-run mode:** if `$ARGUMENTS` contains `--dry-run`, do all the work (preflight, gather inputs,
resolve sprint, validate parent, build the preview and final payload) but **make no changes in
Jira** — skip the confirmation gate and the `createJiraIssue` call. See Phase 4D.
## Constants
| Key | Value |
|---|---|
| cloudId | `tangem.atlassian.net` |
| Project key | `AND` (quote as `"AND"` inside JQL — it collides with the `AND` keyword) |
| Issue type | `Bug` (localized name `Баг`, id `10004`) |
| Issue browse URL | `https://tangem.atlassian.net/browse/{KEY}` |
### Field map (use these exact field IDs)
| Field | How to set | Notes |
|---|---|---|
| Summary | `summary` (top-level param) | **required** |
| Description | `description` (top-level param), `contentFormat: "markdown"` | bug report — steps / expected / actual |
| Issue type | `issueTypeName: "Bug"` | fallback localized `"Баг"` if rejected |
| Assignee | `assignee_account_id` | **defaults to the current user** (self) |
| Sprint | `additional_fields: { "customfield_10021": <sprintId> }` | numeric id of the **active** sprint |
| **Stream** | `additional_fields: { "customfield_11931": { "id": "<optionId>" } }` | **required for Bug** — single-select (see option ids below) |
| **Detected by** | `additional_fields: { "customfield_10870": { "id": "<optionId>" } }` | **required for Bug** — single-select (see option ids below) |
| **Source** | `additional_fields: { "customfield_10252": { "id": "<optionId>" } }` | **required for Bug** — single-select (see option ids below) |
| Parent | hierarchy `parent` accepts an **Epic only** | Story/Task/Bug are all the same hierarchy level, so a **Story can NOT be the `parent` of a Bug** (Jira rejects it: "parent does not belong to the hierarchy"). **Epic parent** → set `parent: "<epic>"`. **Story parent** → set the hierarchy `parent` to the **Story's own parent Epic** (inherit it, so the Bug lands in the same Epic) **and** create the Phase 5b "implements" link to the Story. If the Story has no parent Epic, omit `parent` and rely on the link only. |
| QA Notes | `additional_fields: { "customfield_11232": <ADF doc> }` | optional. **ADF only** — a plain string is rejected ("must be an Atlassian document"). Wrap the text: `{"type":"doc","version":1,"content":[{"type":"paragraph","content":[{"type":"text","text":"<text>"}]}]}` |
| Story Points | `additional_fields: { "customfield_10025": <number> }` | optional |
| Developer | `additional_fields: { "customfield_11898": { "accountId": "<id>" } }` | optional |
| Labels | `additional_fields: { "labels": ["..."] }` | optional |
| Components | `additional_fields: { "components": [{ "name": "..." }] }` | optional |
### Required metric-field option ids (single-select)
These three fields are **mandatory for Bug** and are filled to feed bug-quality metrics. Use the
option **id** (preferred); if the API rejects `{ "id": ... }` for a field, retry that one field with
`{ "value": "<value>" }`.
**Stream** (`customfield_11931`):
| Value | id | When |
|---|---|---|
| `Core` | `15117` | default for most bugs (the common Core stream) |
| `Grow` | `15116` | Grow stream |
| `Visa` | `15981` | Visa stream |
**Detected by** (`customfield_10870`) — who found the bug:
| Value | id | When |
|---|---|---|
| `Team` | `16082` | anyone from Tangem **except** QA (e.g. a developer filing this bug) — **default** |
| `QA` | `16083` | the QA team |
| `User` | `16084` | reported by non-Tangem users (e.g. bugs that came in via Support) |
**Source** (`customfield_10252`) — where in the product lifecycle the bug was found:
| Value | id | When |
|---|---|---|
| `Prod` | `15971` | found on the production app (regardless of who found it) |
| `Support` | `15974` | came from the Support queue |
| `Regression` | `15975` | found during a regression run |
| `Feature-testing` | `15979` | found while testing a new feature |
| `Exploratory` | `15980` | found while exploring the app, no obvious bucket (any build) |
| `Auto Tests` | `15977` | surfaced by automated tests |
| `Crashlytics` | `15978` | from Crashlytics (normally set by automation) |
> **Tool names:** the phases below reference MCP tools by short name (e.g. `createJiraIssue`,
> `getAccessibleAtlassianResources`) for readability. These map to the fully-qualified Atlassian Rovo
> tools declared in `allowed-tools` (`mcp__claude_ai_Atlassian_Rovo__*`) — the connected server for
> this skill. Invoke them by their fully-qualified names.
## Phase 0 — Preflight
1. Verify the Atlassian MCP is reachable: call `getAccessibleAtlassianResources` (no params). If it
fails or `tangem.atlassian.net` is absent, STOP with:
`FATAL: Atlassian MCP is not connected. Run 'claude mcp list' to check server status.`
2. Determine the current user (the default **assignee** / self):
- If the current user's Jira `accountId` is already known from memory/prior context, **reuse it
and skip the API call** — it is stable and does not change.
- Otherwise call `atlassianUserInfo`, save `account_id` and `name`, and remember it for next time
(so future runs skip this call).
## Phase 1 — Gather inputs
Parse `$ARGUMENTS` for an obvious summary and/or a parent key (`AND-\d+`). Then collect the rest.
Ask the user **only for what is still missing**, grouped into as few questions as possible
(use `AskUserQuestion` where the choice is constrained, plain text otherwise):
- **Summary** (required) — short bug title. **Must be in English** (mandatory). If it was not
provided in `$ARGUMENTS`, ask the user to type it. (Unlike the task/story skills, a bug summary is
rarely derivable from the working tree — don't try to generate it from `git` unless the user is
clearly filing a bug about their own local change and asks you to.)
- **Description** — a clear bug report. Ask the user to describe the problem, then format it into a
short structured report (**English or Russian** are both acceptable; default to English):
**Steps to reproduce**, **Expected result**, **Actual result**, plus environment (build / device /
OS) if the user mentioned it. If the user already pasted a full description, reuse it. Show the
result in the Phase 3 preview so the developer can approve or edit it before creation.
- **Stream** (required) — **always ask** via `AskUserQuestion`. Offer the options from the **Stream**
table above (label = value). Per the metrics guidance, **Core** is the common default for most
bugs; use **Grow** / **Visa** for those streams. Map the chosen value to its option id.
- **Detected by** (required) — ask via `AskUserQuestion`, **default `Team`**. Offer `Team` (default —
anyone in Tangem except QA, e.g. the developer filing this), `QA`, `User` (non-Tangem / Support).
Map to its option id.
- **Source** (required) — ask via `AskUserQuestion`. Offer all options from the **Source** table;
put **Feature-testing** and **Exploratory** first as the likely picks for a developer filing a bug
while testing. Map to its option id. (Do **not** auto-pick `Crashlytics` — that is for automation.)
- **Parent** (optional) — a Story or Epic. Ask via `AskUserQuestion` with these options:
- **No parent** — proceed without one (omit the `parent` field).
- **Provide a link/key** — the user knows the parent. When this option is chosen, **ask in a
separate follow-up message** for the link or `AND-xxxxx` key. Then extract the key (`AND-\d+`)
from whatever the user pastes (a plain key or a full `browse/AND-...` URL).
- **Search by keyword** — the user doesn't know the key; ask for a keyword and run
`searchJiraIssuesUsingJql` with
`jql: 'project = "AND" AND issuetype IN (Story, Epic) AND statusCategory != Done AND summary ~ "<kw>" ORDER BY updated DESC'`, then let them pick. **Sanitize `<kw>` before interpolating** — escape `\` and `"` (and drop other JQL metacharacters) so the keyword can't break or alter the query; if it can't be safely escaped, ask the user to rephrase.
- **QA Notes** — testing notes for QA. **Must be strictly in Russian.** Optional. Ask via
`AskUserQuestion`. The option **labels are in English**, but the value written to the QA Notes
field stays in Russian:
- **Nothing to test** → write the exact Russian text `Ничего тестировать не нужно`.
- **Enter manually** → let the user type custom QA Notes (in Russian).
- **No QA Notes** → leave the field empty.
- **Story Points** — only ask if the user mentions it or hints at it; otherwise skip silently.
- **labels / components / Developer****never ask** for these. Only set them if the user provided
them explicitly in `$ARGUMENTS`; otherwise omit them entirely.
Validate any provided parent key with `getJiraIssue` (fields `["summary","issuetype","parent"]`) so
the preview can show the parent's title, confirm it exists, and read its own parent. **Use the
parent's `issuetype` to decide what goes where:**
- **Epic** → the Epic is the hierarchy `parent` (Phase 5) *and* the target of the Phase 5b link.
- **Story** → the Bug **inherits the Story's parent Epic** as its hierarchy `parent` (so it lands in
the same Epic), and the Phase 5b "implements" link points to the **Story**. Read the Story's Epic
from its `parent` field (the `getJiraIssue` above; if absent there, fetch the Story with
`fields:["parent"]`). If the Story has **no** parent Epic, omit the `parent` field and rely on the
link only.
- **Any other type** (Task, Bug, Sub-task, …) → a non-Epic, non-Story key is **not** a valid parent
here: it can't be a hierarchy `parent` (same hierarchy level) and isn't an "implements" target for a
Bug. Warn the user that the key is a `<issuetype>` and ask (via `AskUserQuestion`) whether to
**provide an Epic/Story key instead** or **proceed with no parent** (omit `parent` and skip the
Phase 5b link). Never silently treat it as an Epic or Story.
Track two distinct values: **`linkTarget`** (the chosen parent — Story or Epic, used for the Phase 5b
link) and **`hierarchyParent`** (the Epic that goes into the `parent` field — the Epic itself, or the
Story's inherited Epic, or none). Reflect both in the preview, e.g.
`Parent: [REDACTED_TASK_KEY] (Story, link) — hierarchy Epic [REDACTED_TASK_KEY] (inherited)` or
`Parent: [REDACTED_TASK_KEY] (Epic, hierarchy + link)`.
## Phase 2 — Resolve the current sprint
Run:
```
searchJiraIssuesUsingJql
jql: 'project = "AND" AND sprint IN openSprints() ORDER BY updated DESC'
fields: ["customfield_10021"]
maxResults: 50
```
Inspect the `customfield_10021` arrays across the returned issues (each is an array of sprint
objects — a single `maxResults: 1` issue could belong only to a future open sprint). Collect the
distinct sprint with `state == "active"`; use its `id` (number) for the Sprint field and its `name`
for the preview.
If no active sprint is found, tell the user and ask whether to create the Bug **without** a sprint
or to supply a sprint id manually. Never guess a sprint id.
## Phase 3 — Build the preview
Render a compact table of every field that WILL be sent, e.g.:
```
About to create a Jira BUG in project AND:
Summary : <summary>
Type : Bug
Assignee : <self name> (you)
Sprint : Mobile Sprint 208 (id 4181)
Stream : Core
Detected by : Team
Source : Feature-testing
Parent : [REDACTED_TASK_KEY] — Wallet registration (Story, link) — hierarchy Epic [REDACTED_TASK_KEY] (inherited)
QA Notes : <text or "">
Story Points : <n or "">
Description :
<first ~5 lines, or "">
```
Show empty fields as `—` so the developer sees exactly what is and isn't set. The three metric fields
(Stream / Detected by / Source) are **mandatory** — never show them as `—`.
## Phase 4D — Dry-run exit (when `--dry-run` is set)
If `$ARGUMENTS` contains `--dry-run`, do **not** ask for confirmation and do **not** call
`createJiraIssue`. Instead, after the Phase 3 preview, print the exact `createJiraIssue` payload that
*would* be sent (all params and `additional_fields`, including the three metric fields), prefixed with
a clear banner:
```
DRY RUN — no Jira issue was created. Payload that would be sent:
```
If a parent was set, also note the **issue link** that would be created after the issue:
`createIssueLink type="Polaris work item link", inwardIssue=<new Bug>, outwardIssue=<linkTarget>`
(reads "<linkTarget> is implemented by <new Bug>"), and — for a Story parent — that the hierarchy
`parent` would be the Story's inherited Epic. Then stop — this is the full extent of the run in
dry-run mode.
## Phase 4 — Confirm (mandatory gate)
(Skipped entirely in dry-run mode — see Phase 4D.)
Call `AskUserQuestion` with the question "Create this Jira Bug?" and options:
- **Create** — proceed to Phase 5.
- **Edit fields** — go back to Phase 1 and adjust the field(s) the user names, then re-preview.
- **Cancel** — stop; create nothing.
Do not call `createJiraIssue` until the user selects **Create**.
## Phase 5 — Create
Call `createJiraIssue`:
```
cloudId: "tangem.atlassian.net"
projectKey: "AND"
issueTypeName: "Bug"
summary: "<summary>"
description: "<description>" # omit if empty
contentFormat: "markdown"
assignee_account_id: "<self account_id>"
parent: "<hierarchyParent>" # the Epic (chosen Epic, or the Story's inherited Epic); omit if none
additional_fields: {
"customfield_10021": <sprintId>, # omit if no sprint
"customfield_11931": { "id": "<streamOptionId>" }, # Stream — required
"customfield_10870": { "id": "<detectedByOptionId>" }, # Detected by — required
"customfield_10252": { "id": "<sourceOptionId>" }, # Source — required
# QA Notes — ADF document, NOT a plain string (omit if empty):
"customfield_11232": {"type":"doc","version":1,"content":[{"type":"paragraph","content":[{"type":"text","text":"<QA Notes>"}]}]},
"customfield_10025": <points> # omit if not set
}
```
For multi-line QA Notes, use one `paragraph` per line inside the ADF `content` array.
**Fallbacks** (retry once, only on a field-specific error):
- Issue type rejected → retry with `issueTypeName: "Баг"`.
- A metric field (`customfield_11931` / `customfield_10870` / `customfield_10252`) rejected for
`{ "id": ... }` → retry that one field with `{ "value": "<value>" }`.
- `parent` rejected with "does not belong to the hierarchy" → `hierarchyParent` should already be an
Epic, so this is unexpected (e.g. a non-Epic slipped through). Drop the `parent` field and create
the Bug without it; the relationship is still carried by the Phase 5b "implements" link.
- `parent` (an Epic) rejected for another reason → drop `parent` and set
`additional_fields.customfield_10014: "<epic>"` (legacy Epic Link).
- A single custom field rejected → report which field failed and ask whether to retry without it.
Never silently drop a **required** metric field — if one is rejected and can't be fixed, stop and
report it.
## Phase 5b — Link the new Bug to its parent (only if a parent was set)
After the Bug is created, if a parent was provided, create an **issue link** to **`linkTarget`** (the
chosen parent — the Story, or the Epic) so it **reads "is implemented by <new Bug>"** (the new Bug
*implements* its parent). Note: the hierarchy `parent` set in Phase 5 is the **Epic** (`hierarchyParent`),
while this link points to the **chosen parent** — for a Story parent those are two different issues
(the Bug sits under the Story's Epic *and* implements the Story).
```
createIssueLink
cloudId: "tangem.atlassian.net"
type: "Polaris work item link" # the implements / is implemented by link type
inwardIssue: "<new issue key>" # new Bug → "implements" the parent
outwardIssue: "<linkTarget>" # chosen parent (Story or Epic) → "is implemented by" the new Bug
```
If the link call fails, do **not** treat the whole run as failed (the Bug is already created) —
report the error and the link parameters so it can be added manually.
## Phase 6 — Report
On success, output the new issue key, summary, and URL
`https://tangem.atlassian.net/browse/{KEY}`, plus a one-line recap of the set fields (sprint, parent,
assignee, **Stream / Detected by / Source**) and — if a parent was set — confirm the
On failure, surface the API error message verbatim and the field values you attempted.

View file

@ -0,0 +1,248 @@
---
name: create-jira-story
description: Create a feature Story in the Tangem Android Jira project (AND) via the Atlassian MCP. Pre-fills assignee (self), current active sprint, parent (Epic), QA Notes, and other fields, asks the user for anything missing, shows a full preview, and creates the issue ONLY after explicit confirmation. Use when the user asks to "create a story", "создай историю / стори в Jira", "заведи фичу", "open a Jira story".
allowed-tools: Read, Bash, mcp__claude_ai_Atlassian_Rovo__atlassianUserInfo, mcp__claude_ai_Atlassian_Rovo__getAccessibleAtlassianResources, mcp__claude_ai_Atlassian_Rovo__searchJiraIssuesUsingJql, mcp__claude_ai_Atlassian_Rovo__getJiraIssue, mcp__claude_ai_Atlassian_Rovo__createJiraIssue, mcp__claude_ai_Atlassian_Rovo__createIssueLink, AskUserQuestion
argument-hint: [summary text] [parent AND-xxxxx] [--dry-run]
---
Create a **feature Story** in the Tangem Android Jira project.
This skill is **interactive** — it runs locally for a developer, not on CI. Ask the user for any
missing data. **Never create the issue without an explicit confirmation step (Phase 4).**
**Dry-run mode:** if `$ARGUMENTS` contains `--dry-run`, do all the work (preflight, gather inputs,
resolve sprint, validate parent, build the preview and final payload) but **make no changes in
Jira** — skip the confirmation gate and the `createJiraIssue` call. See Phase 4D.
## Constants
| Key | Value |
|---|---|
| cloudId | `tangem.atlassian.net` |
| Project key | `AND` (quote as `"AND"` inside JQL — it collides with the `AND` keyword) |
| Issue type | `Story` (localized name `История`, id `10001`) |
| Issue browse URL | `https://tangem.atlassian.net/browse/{KEY}` |
### Field map (use these exact field IDs)
| Field | How to set | Notes |
|---|---|---|
| Summary | `summary` (top-level param) | **required** |
| Description | `description` (top-level param), `contentFormat: "markdown"` | optional but recommended |
| Issue type | `issueTypeName: "Story"` | fallback localized `"История"` if rejected |
| Assignee | `assignee_account_id` | **defaults to the current user** (self) |
| Sprint | `additional_fields: { "customfield_10021": <sprintId> }` | numeric id of the **active** sprint |
| Stream | `additional_fields: { "customfield_11931": { "id": "<optionId>" } }` | optional single-select (see option ids below) |
| Parent (Epic) | `parent: "AND-xxxxx"` (top-level param) | Story parent is normally an Epic; fallback `customfield_10014` (Epic Link) |
| QA Notes | `additional_fields: { "customfield_11232": <ADF doc> }` | **ADF only** — a plain string is rejected ("must be an Atlassian document"). Wrap the text: `{"type":"doc","version":1,"content":[{"type":"paragraph","content":[{"type":"text","text":"<text>"}]}]}` |
| Story Points | `additional_fields: { "customfield_10025": <number> }` | optional |
| Developer | `additional_fields: { "customfield_11898": { "accountId": "<id>" } }` | optional |
| Labels | `additional_fields: { "labels": ["..."] }` | optional |
| Components | `additional_fields: { "components": [{ "name": "..." }] }` | optional |
### Stream option ids (single-select, optional)
If the user picks a Stream, map the chosen value to its option **id** (preferred); on a `{ "id": ... }`
rejection retry that field with `{ "value": "<value>" }`.
| Value | id |
|---|---|
| `Core` | `15117` |
| `Grow` | `15116` |
| `Visa` | `15981` |
> **Tool names:** the phases below reference MCP tools by short name (e.g. `createJiraIssue`,
> `getAccessibleAtlassianResources`) for readability. These map to the fully-qualified Atlassian Rovo
> tools declared in `allowed-tools` (`mcp__claude_ai_Atlassian_Rovo__*`) — the connected server for
> this skill. Invoke them by their fully-qualified names.
## Phase 0 — Preflight
1. Verify the Atlassian MCP is reachable: call `getAccessibleAtlassianResources` (no params). If it
fails or `tangem.atlassian.net` is absent, STOP with:
`FATAL: Atlassian MCP is not connected. Run 'claude mcp list' to check server status.`
2. Determine the current user (the default **assignee** / self):
- If the current user's Jira `accountId` is already known from memory/prior context, **reuse it
and skip the API call** — it is stable and does not change.
- Otherwise call `atlassianUserInfo`, save `account_id` and `name`, and remember it for next time
(so future runs skip this call).
## Phase 1 — Gather inputs
Parse `$ARGUMENTS` for an obvious summary and/or a parent key (`AND-\d+`). Then collect the rest.
Ask the user **only for what is still missing**, grouped into as few questions as possible
(use `AskUserQuestion` where the choice is constrained, plain text otherwise):
- **Summary** (required) — short feature title. **Must be in English** (mandatory). If it was not provided in `$ARGUMENTS`,
ask the user (via `AskUserQuestion`): **"Generate the summary from your local changes?"** with
options:
- **Generate from local changes** — inspect the working tree and derive a concise English title
from it: run `git status --porcelain`, `git diff --stat HEAD`, `git branch --show-current` (and
`git log --oneline -5` for context). Propose a one-line summary and show it to the user for
approval/editing before using it. If there are no local changes, say so and fall back to asking
for the title manually.
- **Enter manually** — ask the user to type the title.
- **Description****do NOT ask the developer for it; generate it yourself.** Write a short
**23 sentence** summary of *what* the change is and *why* (**English or Russian** are both
acceptable; default to English), derived from the local changes
(the same `git` inspection used for the summary) and the chosen title. It must be a concise digest,
**not** a full listing of every local change, file, or diff. Show the generated description in the
Phase 3 preview so the developer can approve or edit it before creation.
- **Parent Epic** (optional) — ask via `AskUserQuestion` with these options:
- **No parent** — proceed without one (omit the `parent` field).
- **Provide a link/key** — the user knows the Epic. When this option is chosen, **ask in a
separate follow-up message** for the Epic link or `AND-xxxxx` key. Then extract the key
(`AND-\d+`) from whatever the user pastes (a plain key or a full `browse/AND-...` URL).
- **Search by keyword** — the user doesn't know the key; ask for a keyword and run
`searchJiraIssuesUsingJql` with
`jql: 'project = "AND" AND issuetype = Epic AND statusCategory != Done AND summary ~ "<kw>" ORDER BY updated DESC'`, then let them pick. **Sanitize `<kw>` before interpolating** — escape `\` and `"` (and drop other JQL metacharacters) so the keyword can't break or alter the query; if it can't be safely escaped, ask the user to rephrase.
- **QA Notes** — testing notes for QA. **Must be strictly in Russian.** Optional. Ask via
`AskUserQuestion`. The option **labels are in English**, but the value written to the QA Notes
field stays in Russian:
- **Nothing to test** → write the exact Russian text `Ничего тестировать не нужно`.
- **Generate from changes** → generate QA Notes (in Russian) from the local changes, written for
**testers**: describe the user-facing behaviour to verify in plain language, **without any
code-level names** (no class / component / function / file names). You may include concrete
**test cases** (step → expected result). If you know the feature toggle that gates this
functionality (detect it from the local changes / context — e.g. a new entry in
`feature_toggles_config.json` or an `XxxFeatureToggles` usage), add `Закрыто тогглом "<название>"`.
Show the generated text in the Phase 3 preview for approval/editing.
- **Enter manually** → let the user type custom QA Notes (in Russian).
- **No QA Notes** → leave the field empty.
- **Stream** (optional) — ask via `AskUserQuestion` offering the values from the **Stream option ids**
table plus a **Skip (no Stream)** option (last). `Core` is the common default for most work; pick a
specific stream only when it clearly applies. If the user skips, omit the field. Map the chosen
value to its option id.
- **Story Points** — only ask if the user mentions it or hints at it; otherwise skip silently.
- **labels / components / Developer****never ask** for these. Only set them if the user provided
them explicitly in `$ARGUMENTS`; otherwise omit them entirely.
Validate any provided parent key with `getJiraIssue` (fields `["summary","issuetype"]`) so the
preview can show the parent's title and confirm it exists. Then track two distinct values:
- **`linkTarget`** — the chosen parent, used for the Phase 5b "implements" link.
- **`hierarchyParent`** — the Epic that goes into the `parent` field. A Story's only valid hierarchy
parent is an **Epic**: if the chosen parent **is** an Epic, `hierarchyParent` = that Epic. If it is
**not** an Epic (e.g. a Story/Task), warn the user (a Story can't sit under a non-Epic) and either
ask for an Epic key or set `hierarchyParent` = none — the relationship is then carried by the
Phase 5b link alone.
So the normal case (Epic parent) sets both to the same Epic; a non-Epic parent sets `linkTarget` only.
## Phase 2 — Resolve the current sprint
Run:
```
searchJiraIssuesUsingJql
jql: 'project = "AND" AND sprint IN openSprints() ORDER BY updated DESC'
fields: ["customfield_10021"]
maxResults: 50
```
Inspect the `customfield_10021` arrays across the returned issues (each is an array of sprint
objects — a single `maxResults: 1` issue could belong only to a future open sprint). Collect the
distinct sprint with `state == "active"`; use its `id` (number) for the Sprint field and its `name`
for the preview.
If no active sprint is found, tell the user and ask whether to create the Story **without** a sprint
or to supply a sprint id manually. Never guess a sprint id.
## Phase 3 — Build the preview
Render a compact table of every field that WILL be sent, e.g.:
```
About to create a Jira STORY in project AND:
Summary : <summary>
Type : Story
Assignee : <self name> (you)
Sprint : Mobile Sprint 208 (id 4181)
Stream : Core (or "—" if skipped)
Parent : [REDACTED_TASK_KEY] — Android refactoring (Epic, hierarchy + link)
[or "[REDACTED_TASK_KEY] — Foo (Story, link only — no hierarchy parent)"]
QA Notes : <text or "">
Story Points : <n or "">
Description :
<first ~5 lines, or "">
```
Show empty fields as `—` so the developer sees exactly what is and isn't set.
## Phase 4D — Dry-run exit (when `--dry-run` is set)
If `$ARGUMENTS` contains `--dry-run`, do **not** ask for confirmation and do **not** call
`createJiraIssue`. Instead, after the Phase 3 preview, print the exact `createJiraIssue` payload that
*would* be sent (all params and `additional_fields`), prefixed with a clear banner:
```
DRY RUN — no Jira issue was created. Payload that would be sent:
```
If a `linkTarget` was chosen, also note the **issue link** that would be created after the issue:
`createIssueLink type="Polaris work item link", inwardIssue=<new Story>, outwardIssue=<linkTarget>`
(reads "<linkTarget> is implemented by <new Story>"), and whether the hierarchy `parent`
(`hierarchyParent`) is set or omitted. Then stop — this is the full extent of the run in dry-run mode.
## Phase 4 — Confirm (mandatory gate)
(Skipped entirely in dry-run mode — see Phase 4D.)
Call `AskUserQuestion` with the question "Create this Jira Story?" and options:
- **Create** — proceed to Phase 5.
- **Edit fields** — go back to Phase 1 and adjust the field(s) the user names, then re-preview.
- **Cancel** — stop; create nothing.
Do not call `createJiraIssue` until the user selects **Create**.
## Phase 5 — Create
Call `createJiraIssue`:
```
cloudId: "tangem.atlassian.net"
projectKey: "AND"
issueTypeName: "Story"
summary: "<summary>"
description: "<description>" # omit if empty
contentFormat: "markdown"
assignee_account_id: "<self account_id>"
parent: "<hierarchyParent>" # the Epic; omit if none (non-Epic parent or no parent)
additional_fields: {
"customfield_10021": <sprintId>, # omit if no sprint
"customfield_11931": { "id": "<streamOptionId>" }, # Stream — omit if skipped
# QA Notes — ADF document, NOT a plain string (omit if empty):
"customfield_11232": {"type":"doc","version":1,"content":[{"type":"paragraph","content":[{"type":"text","text":"<QA Notes>"}]}]},
"customfield_10025": <points> # omit if not set
}
```
For multi-line QA Notes, use one `paragraph` per line inside the ADF `content` array.
**Fallbacks** (retry once, only on a field-specific error):
- Issue type rejected → retry with `issueTypeName: "История"`.
- Stream (`customfield_11931`) rejected for `{ "id": ... }` → retry that field with `{ "value": "<value>" }`.
- `hierarchyParent` (an Epic) rejected → drop `parent`, set `additional_fields.customfield_10014: "<epic>"` (legacy Epic Link).
- A single custom field rejected → report which field failed and ask whether to retry without it.
## Phase 5b — Link the new Story to its parent (only if a `linkTarget` was chosen)
After the Story is created, if a `linkTarget` was chosen, create an **issue link** to it so it
**reads "is implemented by <new Story>"** (the new Story *implements* its parent). When
`hierarchyParent` was also set (the normal Epic case), this complements the hierarchy `parent` field;
when only a `linkTarget` was chosen (non-Epic parent, no hierarchy parent), this link is the sole
relationship.
```
createIssueLink
cloudId: "tangem.atlassian.net"
type: "Polaris work item link" # the implements / is implemented by link type
inwardIssue: "<new issue key>" # new Story → "implements" the parent
outwardIssue: "<linkTarget>" # chosen parent → "is implemented by" the new Story
```
If the link call fails, do **not** treat the whole run as failed (the Story is already created) —
report the error and the link parameters so it can be added manually.
## Phase 6 — Report
On success, output the new issue key, summary, and URL
`https://tangem.atlassian.net/browse/{KEY}`, plus a one-line recap of the set fields (sprint, parent,
assignee) and — if a parent was set — confirm the **"<parent> is implemented by <new issue>"** link was created.
On failure, surface the API error message verbatim and the field values you attempted.

View file

@ -0,0 +1,267 @@
---
name: create-jira-task
description: Create a Task in the Tangem Android Jira project (AND) via the Atlassian MCP. Pre-fills assignee (self), current active sprint, parent (Story or Epic), QA Notes, and other fields, asks the user for anything missing, shows a full preview, and creates the issue ONLY after explicit confirmation. Use when the user asks to "create a task", "создай задачу / таску в Jira", "заведи задачу", "open a Jira task".
allowed-tools: Read, Bash, mcp__claude_ai_Atlassian_Rovo__atlassianUserInfo, mcp__claude_ai_Atlassian_Rovo__getAccessibleAtlassianResources, mcp__claude_ai_Atlassian_Rovo__searchJiraIssuesUsingJql, mcp__claude_ai_Atlassian_Rovo__getJiraIssue, mcp__claude_ai_Atlassian_Rovo__createJiraIssue, mcp__claude_ai_Atlassian_Rovo__createIssueLink, AskUserQuestion
argument-hint: [summary text] [parent AND-xxxxx] [--dry-run]
---
Create a **Task** in the Tangem Android Jira project.
This skill is **interactive** — it runs locally for a developer, not on CI. Ask the user for any
missing data. **Never create the issue without an explicit confirmation step (Phase 4).**
**Dry-run mode:** if `$ARGUMENTS` contains `--dry-run`, do all the work (preflight, gather inputs,
resolve sprint, validate parent, build the preview and final payload) but **make no changes in
Jira** — skip the confirmation gate and the `createJiraIssue` call. See Phase 4D.
## Constants
| Key | Value |
|---|---|
| cloudId | `tangem.atlassian.net` |
| Project key | `AND` (quote as `"AND"` inside JQL — it collides with the `AND` keyword) |
| Issue type | `Task` (localized name `Задача`, id `10002`) |
| Issue browse URL | `https://tangem.atlassian.net/browse/{KEY}` |
### Field map (use these exact field IDs)
| Field | How to set | Notes |
|---|---|---|
| Summary | `summary` (top-level param) | **required** |
| Description | `description` (top-level param), `contentFormat: "markdown"` | optional but recommended |
| Issue type | `issueTypeName: "Task"` | fallback localized `"Задача"` if rejected |
| Assignee | `assignee_account_id` | **defaults to the current user** (self) |
| Sprint | `additional_fields: { "customfield_10021": <sprintId> }` | numeric id of the **active** sprint |
| Stream | `additional_fields: { "customfield_11931": { "id": "<optionId>" } }` | optional single-select (see option ids below) |
| Parent | hierarchy `parent` accepts an **Epic only** | Story/Task/Bug are all the same hierarchy level, so a **Story can NOT be the `parent` of a Task** (Jira rejects it: "parent does not belong to the hierarchy"). **Epic parent** → set `parent: "<epic>"`. **Story parent** → set the hierarchy `parent` to the **Story's own parent Epic** (inherit it, so the Task lands in the same Epic) **and** create the Phase 5b "implements" link to the Story. If the Story has no parent Epic, omit `parent` and rely on the link only. |
| QA Notes | `additional_fields: { "customfield_11232": <ADF doc> }` | **ADF only** — a plain string is rejected ("must be an Atlassian document"). Wrap the text: `{"type":"doc","version":1,"content":[{"type":"paragraph","content":[{"type":"text","text":"<text>"}]}]}` |
| Story Points | `additional_fields: { "customfield_10025": <number> }` | optional |
| Developer | `additional_fields: { "customfield_11898": { "accountId": "<id>" } }` | optional |
| Labels | `additional_fields: { "labels": ["..."] }` | optional |
| Components | `additional_fields: { "components": [{ "name": "..." }] }` | optional |
### Stream option ids (single-select, optional)
If the user picks a Stream, map the chosen value to its option **id** (preferred); on a `{ "id": ... }`
rejection retry that field with `{ "value": "<value>" }`.
| Value | id |
|---|---|
| `Core` | `15117` |
| `Grow` | `15116` |
| `Visa` | `15981` |
> **Tool names:** the phases below reference MCP tools by short name (e.g. `createJiraIssue`,
> `getAccessibleAtlassianResources`) for readability. These map to the fully-qualified Atlassian Rovo
> tools declared in `allowed-tools` (`mcp__claude_ai_Atlassian_Rovo__*`) — the connected server for
> this skill. Invoke them by their fully-qualified names.
## Phase 0 — Preflight
1. Verify the Atlassian MCP is reachable: call `getAccessibleAtlassianResources` (no params). If it
fails or `tangem.atlassian.net` is absent, STOP with:
`FATAL: Atlassian MCP is not connected. Run 'claude mcp list' to check server status.`
2. Determine the current user (the default **assignee** / self):
- If the current user's Jira `accountId` is already known from memory/prior context, **reuse it
and skip the API call** — it is stable and does not change.
- Otherwise call `atlassianUserInfo`, save `account_id` and `name`, and remember it for next time
(so future runs skip this call).
## Phase 1 — Gather inputs
Parse `$ARGUMENTS` for an obvious summary and/or a parent key (`AND-\d+`). Then collect the rest.
Ask the user **only for what is still missing**, grouped into as few questions as possible
(use `AskUserQuestion` where the choice is constrained, plain text otherwise):
- **Summary** (required) — short task title. **Must be in English** (mandatory). If it was not provided in `$ARGUMENTS`,
ask the user (via `AskUserQuestion`): **"Generate the summary from your local changes?"** with
options:
- **Generate from local changes** — inspect the working tree and derive a concise English title
from it: run `git status --porcelain`, `git diff --stat HEAD`, `git branch --show-current` (and
`git log --oneline -5` for context). Propose a one-line summary and show it to the user for
approval/editing before using it. If there are no local changes, say so and fall back to asking
for the title manually.
- **Enter manually** — ask the user to type the title.
- **Description****do NOT ask the developer for it; generate it yourself.** Write a short
**23 sentence** summary of *what* the change is and *why* (**English or Russian** are both
acceptable; default to English), derived from the local changes
(the same `git` inspection used for the summary) and the chosen title. It must be a concise digest,
**not** a full listing of every local change, file, or diff. Show the generated description in the
Phase 3 preview so the developer can approve or edit it before creation.
- **Parent** (optional) — a Story or Epic. Ask via `AskUserQuestion` with these options:
- **No parent** — proceed without one (omit the `parent` field).
- **Provide a link/key** — the user knows the parent. When this option is chosen, **ask in a
separate follow-up message** for the link or `AND-xxxxx` key. Then extract the key (`AND-\d+`)
from whatever the user pastes (a plain key or a full `browse/AND-...` URL).
- **Search by keyword** — the user doesn't know the key; ask for a keyword and run
`searchJiraIssuesUsingJql` with
`jql: 'project = "AND" AND issuetype IN (Story, Epic) AND statusCategory != Done AND summary ~ "<kw>" ORDER BY updated DESC'`, then let them pick. **Sanitize `<kw>` before interpolating** — escape `\` and `"` (and drop other JQL metacharacters) so the keyword can't break or alter the query; if it can't be safely escaped, ask the user to rephrase.
- **QA Notes** — testing notes for QA. **Must be strictly in Russian.** Optional. Ask via
`AskUserQuestion`. The option **labels are in English**, but the value written to the QA Notes
field stays in Russian:
- **Nothing to test** → write the exact Russian text `Ничего тестировать не нужно`.
- **Test within the story** → testing happens within the parent Story; write the Russian text
`Тестируйте в рамках стори`. If the change is gated behind a feature toggle (detect a toggle name
from the local changes / context, e.g. a new entry in `feature_toggles_config.json` or an
`XxxFeatureToggles` usage), append it: `Тестируйте в рамках стори, закрыто тогглом "<название>"`.
If no toggle is found, use the plain text without the toggle clause.
- **Generate from changes** → generate QA Notes (in Russian) from the local changes, written for
**testers**: describe the user-facing behaviour to verify in plain language, **without any
code-level names** (no class / component / function / file names). You may include concrete
**test cases** (step → expected result). If you know the feature toggle that gates this
functionality (detect it from the local changes / context — e.g. a new entry in
`feature_toggles_config.json` or an `XxxFeatureToggles` usage), add `Закрыто тогглом "<название>"`.
Show the generated text in the Phase 3 preview for approval/editing.
- **Enter manually** → let the user type custom QA Notes (in Russian).
- **No QA Notes** → leave the field empty.
- **Stream** (optional) — ask via `AskUserQuestion` offering the values from the **Stream option ids**
table plus a **Skip (no Stream)** option (last). `Core` is the common default for most work; pick a
specific stream only when it clearly applies. If the user skips, omit the field. Map the chosen
value to its option id.
- **Story Points** — only ask if the user mentions it or hints at it; otherwise skip silently.
- **labels / components / Developer****never ask** for these. Only set them if the user provided
them explicitly in `$ARGUMENTS`; otherwise omit them entirely.
Validate any provided parent key with `getJiraIssue` (fields `["summary","issuetype","parent"]`) so
the preview can show the parent's title, confirm it exists, and read its own parent. **Use the
parent's `issuetype` to decide what goes where:**
- **Epic** → the Epic is the hierarchy `parent` (Phase 5) *and* the target of the Phase 5b link.
- **Story** → the Task **inherits the Story's parent Epic** as its hierarchy `parent` (so it lands in
the same Epic), and the Phase 5b "implements" link points to the **Story**. Read the Story's Epic
from its `parent` field (the `getJiraIssue` above; if absent there, fetch the Story with
`fields:["parent"]`). If the Story has **no** parent Epic, omit the `parent` field and rely on the
link only.
- **Any other type** (Task, Bug, Sub-task, …) → a non-Epic, non-Story key is **not** a valid parent
here: it can't be a hierarchy `parent` (same hierarchy level) and isn't an "implements" target for a
Task. Warn the user that the key is a `<issuetype>` and ask (via `AskUserQuestion`) whether to
**provide an Epic/Story key instead** or **proceed with no parent** (omit `parent` and skip the
Phase 5b link). Never silently treat it as an Epic or Story.
Track two distinct values: **`linkTarget`** (the chosen parent — Story or Epic, used for the Phase 5b
link) and **`hierarchyParent`** (the Epic that goes into the `parent` field — the Epic itself, or the
Story's inherited Epic, or none). Reflect both in the preview, e.g.
`Parent: [REDACTED_TASK_KEY] (Story, link) — hierarchy Epic [REDACTED_TASK_KEY] (inherited)` or
`Parent: [REDACTED_TASK_KEY] (Epic, hierarchy + link)`.
## Phase 2 — Resolve the current sprint
Run:
```
searchJiraIssuesUsingJql
jql: 'project = "AND" AND sprint IN openSprints() ORDER BY updated DESC'
fields: ["customfield_10021"]
maxResults: 50
```
Inspect the `customfield_10021` arrays across the returned issues (each is an array of sprint
objects — a single `maxResults: 1` issue could belong only to a future open sprint). Collect the
distinct sprint with `state == "active"`; use its `id` (number) for the Sprint field and its `name`
for the preview.
If no active sprint is found, tell the user and ask whether to create the Task **without** a sprint
or to supply a sprint id manually. Never guess a sprint id.
## Phase 3 — Build the preview
Render a compact table of every field that WILL be sent, e.g.:
```
About to create a Jira TASK in project AND:
Summary : <summary>
Type : Task
Assignee : <self name> (you)
Sprint : Mobile Sprint 208 (id 4181)
Stream : Core (or "—" if skipped)
Parent : [REDACTED_TASK_KEY] — Wallet registration (Story, link) — hierarchy Epic [REDACTED_TASK_KEY] (inherited)
QA Notes : <text or "">
Story Points : <n or "">
Description :
<first ~5 lines, or "">
```
Show empty fields as `—` so the developer sees exactly what is and isn't set.
## Phase 4D — Dry-run exit (when `--dry-run` is set)
If `$ARGUMENTS` contains `--dry-run`, do **not** ask for confirmation and do **not** call
`createJiraIssue`. Instead, after the Phase 3 preview, print the exact `createJiraIssue` payload that
*would* be sent (all params and `additional_fields`), prefixed with a clear banner:
```
DRY RUN — no Jira issue was created. Payload that would be sent:
```
If a parent was set, also note the **issue link** that would be created after the issue:
`createIssueLink type="Polaris work item link", inwardIssue=<new Task>, outwardIssue=<linkTarget>`
(reads "<linkTarget> is implemented by <new Task>"), and — for a Story parent — that the hierarchy
`parent` would be the Story's inherited Epic. Then stop — this is the full extent of the run in
dry-run mode.
## Phase 4 — Confirm (mandatory gate)
(Skipped entirely in dry-run mode — see Phase 4D.)
Call `AskUserQuestion` with the question "Create this Jira Task?" and options:
- **Create** — proceed to Phase 5.
- **Edit fields** — go back to Phase 1 and adjust the field(s) the user names, then re-preview.
- **Cancel** — stop; create nothing.
Do not call `createJiraIssue` until the user selects **Create**.
## Phase 5 — Create
Call `createJiraIssue`:
```
cloudId: "tangem.atlassian.net"
projectKey: "AND"
issueTypeName: "Task"
summary: "<summary>"
description: "<description>" # omit if empty
contentFormat: "markdown"
assignee_account_id: "<self account_id>"
parent: "<hierarchyParent>" # the Epic (chosen Epic, or the Story's inherited Epic); omit if none
additional_fields: {
"customfield_10021": <sprintId>, # omit if no sprint
"customfield_11931": { "id": "<streamOptionId>" }, # Stream — omit if skipped
# QA Notes — ADF document, NOT a plain string (omit if empty):
"customfield_11232": {"type":"doc","version":1,"content":[{"type":"paragraph","content":[{"type":"text","text":"<QA Notes>"}]}]},
"customfield_10025": <points> # omit if not set
}
```
For multi-line QA Notes, use one `paragraph` per line inside the ADF `content` array.
**Fallbacks** (retry once, only on a field-specific error):
- Issue type rejected → retry with `issueTypeName: "Задача"`.
- Stream (`customfield_11931`) rejected for `{ "id": ... }` → retry that field with `{ "value": "<value>" }`.
- `parent` rejected with "does not belong to the hierarchy" → `hierarchyParent` should already be an
Epic, so this is unexpected (e.g. a non-Epic slipped through). Drop the `parent` field and create
the Task without it; the relationship is still carried by the Phase 5b "implements" link.
- `parent` (an Epic) rejected for another reason → drop `parent` and set
`additional_fields.customfield_10014: "<epic>"` (legacy Epic Link).
- A single custom field rejected → report which field failed and ask whether to retry without it.
## Phase 5b — Link the new Task to its parent (only if a parent was set)
After the Task is created, if a parent was provided, create an **issue link** to **`linkTarget`** (the
chosen parent — the Story, or the Epic) so it **reads "is implemented by <new Task>"** (the new Task
*implements* its parent). Note: the hierarchy `parent` set in Phase 5 is the **Epic** (`hierarchyParent`),
while this link points to the **chosen parent** — for a Story parent those are two different issues
(the Task sits under the Story's Epic *and* implements the Story).
```
createIssueLink
cloudId: "tangem.atlassian.net"
type: "Polaris work item link" # the implements / is implemented by link type
inwardIssue: "<new issue key>" # new Task → "implements" the parent
outwardIssue: "<linkTarget>" # chosen parent (Story or Epic) → "is implemented by" the new Task
```
If the link call fails, do **not** treat the whole run as failed (the Task is already created) —
report the error and the link parameters so it can be added manually.
## Phase 6 — Report
On success, output the new issue key, summary, and URL
`https://tangem.atlassian.net/browse/{KEY}`, plus a one-line recap of the set fields (sprint, parent,
assignee) and — if a parent was set — confirm the **"<parent> is implemented by <new issue>"** link was created.
On failure, surface the API error message verbatim and the field values you attempted.

View file

@ -0,0 +1,360 @@
---
name: create-pr
description: Open a GitHub pull request for the current work via the GitHub CLI (gh), following Tangem repo conventions — branch naming (feature/bugfix/AND-xxx), commit format (AND-xxx Description), base develop, required trailers. Picks which changes to include, creates a feature branch off a protected branch, commits, and — only after explicit confirmation — pushes and opens the PR. For a task-tied PR, then offers to fill the Jira task's QA Notes from the local changes (after review & confirmation). Use when the user asks to "open/create a PR", "создай ПР / пул-реквест", "open a pull request", "залей в PR".
allowed-tools: Read, Bash, AskUserQuestion, Monitor, TaskStop, mcp__claude_ai_Atlassian_Rovo__getJiraIssue, mcp__claude_ai_Atlassian_Rovo__editJiraIssue
argument-hint: [AND-xxxxx] [title...] [--base develop] [--dry-run]
---
Open a GitHub pull request for the current changes via `gh`, following this repo's conventions.
This skill is **interactive** and runs locally. **Pushing and opening the PR happen ONLY after an
explicit confirmation gate (Phase 4)** — never push or create the PR before the user confirms.
For a PR tied to a specific Jira task (i.e. **not** a Technical PR), after the PR is open the skill
offers to fill the task's **QA Notes** field from the local changes — **only after the user reviews
and confirms the exact text** (Phase 6b). Never write to Jira before that confirmation.
## Conventions
**Source of truth: [`.claude/rules/git-rules.md`](../../rules/git-rules.md)** — read it for branch
naming (`feature/`, `bugfix/`, **`tech/`**, `releases/`), the `AND-xxx Description` commit/PR-title
format, and the technical-PR exception (no Jira task → no `AND-xxx` in branch/commit/title). Do not
restate or fork those rules here; follow git-rules.md so this skill can't drift from it.
This skill only adds what is **not** in git-rules.md:
| Thing | Rule |
|---|---|
| Default PR base | `develop` (hotfix → the relevant `releases/x.xx`) |
| Protected branches | `develop`, `releases/*` — never commit directly; always branch off (Phase 2) |
| Commit trailer | `Co-Authored-By: Claude Opus 4.8 (1M context) <[REDACTED_EMAIL]>` |
| PR body footer | `🤖 Generated with [Claude Code](https://claude.com/claude-code)` |
| Code comments | **No `AND-xxx`** in code/KDoc (fine in branch/commit/PR) |
**Dry-run:** if `$ARGUMENTS` contains `--dry-run`, do everything except the writes — no branch
creation, no commit, no push, no `gh pr create`. Print the exact branch name, commit message, file
list, and `gh pr create` command that would run, then stop (see Phase 4D).
## Phase 0 — Preflight
Run these and stop with a clear FATAL message if any fails:
1. `gh auth status` — GitHub CLI must be authenticated. If not: `FATAL: gh is not authenticated. Run 'gh auth login'.`
2. `git rev-parse --abbrev-ref HEAD` — current branch. `git status --porcelain` — working tree.
3. `git remote get-url origin` and the repo's default branch (`gh repo view --json defaultBranchRef -q .defaultBranchRef.name`) for reference.
**Primary flow (default): branch + commit from existing local changes.** This skill takes the
**current uncommitted working-tree changes**, puts them on the right branch, commits, pushes, and
opens the PR. The target branch is decided by the **task** (Phase 1), not by whichever branch you
happen to be on:
- If the current branch is already the correct branch **for this task** (`feature/AND-xxxxx_…` /
`bugfix/…` / `tech/…` matching the resolved task), commit the pending changes onto it.
- Otherwise — on a protected branch (`develop`/`releases/*`) **or on another task's feature branch**
create a new branch **off the base** (Phase 5 cuts it from `origin/<base>` so the other branch's
commits don't ride along). Git keeps the uncommitted working-tree changes across this checkout.
Never leave local changes uncommitted and PR only what was already committed — the pending changes
are the point.
Fallback (no local changes): if `git status --porcelain` is empty **and** the current branch already
has commits ahead of the base that aren't PR'd, switch to a "PR an existing branch" flow — skip the
commit steps and go straight to push + PR. If the tree is empty and there are no un-PR'd commits
either, there is nothing to open a PR for — stop and say so.
## Phase 1 — Gather inputs
Parse `$ARGUMENTS` for an `AND-\d+` task id, a title, and `--base <branch>`. Ask only for what's
missing (use `AskUserQuestion` for constrained choices, plain text otherwise):
- **Task id** (`AND-xxxxx`) — **mandatory** for branch/commit/PR naming. **Always ask the user which
task this PR is for** — never decide it silently. Every PR carries an `AND-xxxxx` **except** an
explicit **Technical PR** (the one no-task exception, described below); do not offer a generic
"no task / standalone" option outside that. You may pre-fill a *suggestion* (from `$ARGUMENTS`, or
an `AND-\d+` found in the current branch name) as the recommended answer, but the user must confirm
or override it. Do not assume the current branch's task id applies to the pending changes — they
are often unrelated (e.g. you're on another task's branch). If the user gives no valid `AND-\d+`,
keep asking — do not proceed without one.
When asking, also offer a **"Create a new Jira Task"** option. If the user picks it, run the
**`create-jira-task`** skill (it creates the Task from the local changes), then use the newly
created `AND-xxxxx` as this PR's task id and continue. (Offer the Story-equivalent only if the work
clearly warrants a Story; default to a Task.) **In `--dry-run`, do NOT actually run
`create-jira-task`** — it's a real write; instead use a placeholder task id (e.g. `AND-NEW`) and
note that the Task would be created.
Also offer a **"Technical PR"** option (the one exception to the mandatory-task rule): a chore /
tooling PR with **no Jira task**. If chosen, the change type becomes `tech`, the branch is
`tech/<slug>` (no `AND-xxxxx`), and the commit subject + PR title have **no `AND-xxxxx` prefix**
(just the plain English title).
Options to present: the suggested existing key (if any), **Create a new Jira Task**, **Technical
PR**, and free-text Other for an existing key. Outside of the Technical PR choice, never proceed
without a valid `AND-\d+`.
- **Title** (English, required) — the PR/commit description. If absent, propose one generated from
the staged/working changes (`git diff --stat`, `git log`) and ask the user to approve or edit.
Must be English.
- **Change type**`feature`, `bugfix`, or `tech` (drives the branch prefix). `tech` is set
automatically when the user chose the **Technical PR** option above. Otherwise infer from the
title/task; default `feature`.
- **Base branch** — default `develop`. Only change for hotfixes (`releases/x.xx`). Ask only if the
current branch is itself a `releases/*` branch (then the base is likely that release line).
- **Files to include** — show `git status --porcelain` and let the user choose. Default to all
tracked changes **except** unrelated submodule pointer bumps and stray edits; call out anything
you exclude. If the user named specific files in `$ARGUMENTS` / the prompt (e.g. via `@path`),
include exactly those.
## Phase 1b — Classify complexity & choose labels
Every PR gets exactly **one complexity label**. Count the **files chosen in Phase 1** (the planned
PR contents — not `git diff --cached`, since nothing is staged until Phase 5) and judge the nature of
the change. Propose a level
(via `AskUserQuestion`, recommending the one you judged) and let the user confirm or override:
| Label | Level | When | File limit |
|---|---|---|---|
| `deep` | 🔴 Red | Complex changes, or touching important/core logic | **≤ 15 files** |
| `complex` | 🟡 Yellow | Not deep and/or does not touch important core logic | **≤ 20 files** |
| `easy` | ⚪ White | Uniform/mechanical changes (rename, package move, formatting) | **no limit** |
Rules:
1. **Over the limit** → the PR body **must** include an explanation/justification of why the change
could not be split or kept smaller. If the count exceeds the level's limit, ask the user for that
justification and append it to the PR body under a `## Why this exceeds the <label> file limit`
heading. Do not open an over-limit PR without it.
2. **Codeowner authority** — note in the PR body that the codeowner may request splitting the change
or reject the PR. (Informational; nothing to enforce here.)
3. **Red (`deep`) PRs must have a description** — a non-empty, meaningful PR body explaining the
change is mandatory (not just the summary line). If missing, ask the user for it before creating.
4. **Bug branches** — if the change type is `bugfix` (branch starts `bugfix/`), add the **`bug`**
label **in addition** to the complexity label.
Resulting label set = the one complexity label (`deep`|`complex`|`easy`) + `bug` if it's a bugfix.
## Phase 2 — Derive the branch
- Build a slug from the title: lowercase, ASCII, spaces/punctuation → `_`, trimmed to ~5 words.
- Branch = `<feature|bugfix>/AND-xxxxx_<slug>` — or, for a Technical PR, `tech/<slug>` (no task id).
- **Reuse** the current branch only if it already matches **this task** (its `AND-xxxxx` / `tech`
slug corresponds to the resolved task). Then commit onto it directly (no new branch).
- Otherwise **create a new branch off the base** — whether you're on a protected branch
(`develop`/`releases/*`) **or on another task's feature branch**. Never commit to a protected
branch, and never reuse an unrelated task's branch (its commits would ride into this PR).
## Phase 3 — Build the preview
Show everything that will happen, e.g.:
```
About to open a PR:
Branch : feature/AND-16023_jira_issue_creation_skills (new, off develop)
Base : develop
Files :
+ .claude/skills/create-jira-story/SKILL.md
+ .claude/skills/create-jira-task/SKILL.md
Excluded:
~ core/ui/ds-tokens (unrelated submodule bump)
Commit : [REDACTED_TASK_KEY] Implement Jira Story/Task creation skills
PR title: [REDACTED_TASK_KEY] Implement Jira Story/Task creation skills
Labels : complex (2 files ≤ 20 — within limit)
PR body : <first lines>
```
Show the chosen labels, the file count vs. the level's limit, and — if over the limit — that a
justification is included. For a `bugfix` branch the line reads e.g. `Labels : deep, bug`.
## Phase 3b — Optional pre-PR checks (build / unit tests / detekt)
Before committing/pushing, ask via `AskUserQuestion` (**multiSelect**): **"Run any checks before
opening the PR?"** with options — **Build**, **Unit tests**, **Detekt**, **Skip all**. Run only what
the user picks. Prefer scoping to the affected modules when obvious; otherwise use the project-wide
commands from `CLAUDE.md`:
| Check | Command (project-wide) | Scoped example |
|---|---|---|
| Build | `./gradlew :app:assembleGoogleDebug` | `./gradlew :features:foo:impl:assembleDebug` |
| Unit tests | `./gradlew unitTest` | `./gradlew :features:foo:impl:testDebugUnitTest` |
| Detekt | `./gradlew detekt detektMain` | `./gradlew :features:foo:impl:detekt` |
Run the selected checks (long-running — use a generous timeout). Report each result.
- **All selected checks pass** → continue to Phase 4.
- **Any check fails** → show the failure output and ask how to proceed: **Fix first** (stop so the
user / an appropriate agent can fix — e.g. `detekt-fixer` for detekt), **Open PR anyway** (proceed
to Phase 4 despite the failure — note it in the PR body), or **Cancel**. Do **not** silently
proceed past a failing check.
Skip this phase entirely in `--dry-run` mode (note in the dry-run output that checks were skipped).
## Phase 4D — Dry-run exit (when `--dry-run` is set)
Print the branch (and the `origin/<base>` it would be cut from), file list, commit message, chosen
labels (with the file-count-vs-limit check), and the literal `gh pr create` command that would run —
with **one `--label` flag per label** exactly as Phase 5 issues them, e.g.
`gh pr create --base <base> --head <branch> --label "<complexity>" [--label "bug"] --title "…" --body "…"`.
Make **no** changes (no branch, commit, push, or PR). Then stop.
## Phase 4 — Confirm (mandatory gate — covers the push)
Call `AskUserQuestion` "Create branch, commit, push, and open the PR?" with options:
- **Do it** — proceed to Phase 5.
- **Edit** — adjust branch/title/files/base, then re-preview.
- **Cancel** — stop; make no changes.
Do not run any write command (branch/commit/**push**/PR) until the user selects **Do it**. A previous
approval does not carry over to a later run.
## Phase 5 — Execute
1. **Branch** (if a new branch is needed — i.e. not reusing this task's branch): cut it **from the
base**, not from the current HEAD, so another branch's commits don't ride along:
`git fetch origin <base> && git checkout -b <branch> origin/<base>`. Git carries the uncommitted
working-tree changes across the checkout. (When reusing this task's existing branch, skip this.)
2. **Stage**: `git add <selected paths>` — only the chosen files; never `git add -A` blindly.
3. **Commit** (skip if PR-ing an existing branch with no new changes):
```
git commit -F- <<'EOF'
AND-xxxxx <Title>
<optional 13 line body>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
EOF
```
For a **Technical PR**, the commit subject (and PR title) is just `<Title>` with **no `AND-xxxxx`
prefix**.
4. **Push**: `git push -u origin <branch>`.
5. **PR**:
```
gh pr create --base <base> --head <branch> \
--label "<complexity label>" [--label "bug"] \
--title "<commit subject>" \ # "AND-xxxxx <Title>", or just "<Title>" for a Technical PR (same as the commit subject)
--body "$(cat <<'EOF'
## What
<concise summary of the change>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
EOF
)"
```
Pass the complexity label (`deep`|`complex`|`easy`) via `--label`, plus a second `--label "bug"`
for bugfix branches. `gh pr create` prints the PR URL on success. (If labels were missed at
creation, add them after with `gh pr edit <url> --add-label "<label>"`.)
If a step fails, stop and surface the exact error and the command that failed; do not retry blindly.
## Phase 6 — Report
Output the PR URL, branch, base, the files included, and the labels. Do **not** offer to comment the
PR link on Jira or to change the Jira task status — those are out of scope for this skill. (Filling
the task's **QA Notes** is in scope — see Phase 6b.)
## Phase 6b — QA Notes on the Jira task
**Runs only for a PR tied to a Jira task** — skip entirely for a **Technical PR** (no task id), and
skip in **`--dry-run`** (note in the dry-run output that QA Notes would be offered, but make no Jira
read/write). This is the only Jira write this skill performs, and it happens **after** the PR is open.
QA Notes is a testing note for QA, **written strictly in Russian**, describing user-facing behaviour
to verify **without any code-level names** (no class / component / function / file names). It is the
same field and conventions as the `create-jira-task` skill: field **`customfield_11232`**, **ADF
document only** (a plain string is rejected).
> **Tool names:** the steps below reference the Jira MCP tools by short name (`getJiraIssue`,
> `editJiraIssue`) for readability. These map to the fully-qualified Atlassian Rovo tools declared in
> `allowed-tools` (`mcp__claude_ai_Atlassian_Rovo__getJiraIssue` /
> `mcp__claude_ai_Atlassian_Rovo__editJiraIssue`) — invoke them by their fully-qualified names.
1. **Read the current value.** `getJiraIssue` for the resolved `AND-xxxxx` with
`fields: ["summary","customfield_11232"]` and `responseContentFormat: "markdown"` so the field
comes back as readable plain text rather than raw ADF JSON. (The field is stored as an ADF
document — if you fetch it as ADF, extract the plain text from the `content` paragraphs before
showing it; never paste raw ADF into the preview.)
- **Already filled** (non-empty `customfield_11232`) → **warn the user**, show the existing QA
Notes as plain text, and ask via `AskUserQuestion` how to proceed: **Keep existing** (default —
make no change, skip the rest of this phase) / **Overwrite** / **Append**. Do not silently
clobber an existing value.
- **Empty** → offer to fill it (**Generate & fill** / **Skip**). If the user skips, end the phase.
2. **Generate the QA Notes from the changes in this PR** (in Russian, for testers): describe in plain
language what to verify — you may include concrete test cases (step → expected result). Base it on
the PR's actual diff, not a bare `git diff` (which is empty after the commit/push): use
`git diff origin/<base>...HEAD` (the branch's changes against the base), or `git show HEAD` for a
single-commit PR. If the functionality is gated behind a feature toggle (detect a toggle name from
the diff — e.g. a new entry in `feature_toggles_config.json` or an `XxxFeatureToggles` usage),
append `Закрыто тогглом "<название>"`. When appending to an existing value, produce the combined
final text.
3. **Show the full proposed QA Notes text and get explicit confirmation** (`AskUserQuestion`:
**Write to Jira** / **Edit** / **Cancel**). The user must review the exact text before anything is
written. On **Edit**, let them adjust the text and re-preview. Never call `editJiraIssue` before
the user selects **Write to Jira**.
4. **Write.** `editJiraIssue` for `AND-xxxxx` with the QA Notes wrapped as an ADF document. Each line
of text is its **own `paragraph`** in the `content` array — a single-line note is one paragraph, a
multi-line note is several. Do **not** put line breaks inside one paragraph's text.
```
# single line → one paragraph:
"customfield_11232": {"type":"doc","version":1,"content":[
{"type":"paragraph","content":[{"type":"text","text":"<line 1>"}]}
]}
# multiple lines → one paragraph per line:
"customfield_11232": {"type":"doc","version":1,"content":[
{"type":"paragraph","content":[{"type":"text","text":"<line 1>"}]},
{"type":"paragraph","content":[{"type":"text","text":"<line 2>"}]}
]}
```
Report success (or surface the exact error and stop — do not retry blindly).
## Phase 7 — Optional PR monitor
After the PR exists, ask via `AskUserQuestion`: **"Attach a monitor to this PR?"** (options: **Yes,
monitor** / **No**). If the user declines, stop.
If they accept, start a **persistent `Monitor`** that tracks the things worth acting on and emits one
line per occurrence:
- **Copilot inline review comments** (`pulls/{}/comments`).
- **Copilot conversation comments** (`issues/{}/comments`).
- **Copilot review summaries** (`pulls/{}/reviews` body) — the "## Pull request overview" text that
is NOT an inline comment and would otherwise be missed.
- **Failed GitHub Actions checks** — especially **tests** and **detekt**, but report any failed check.
Comments/reviews are de-duplicated by **id** (a temp file), so the loop polls the full lists each
time without re-emitting; existing items are **seeded as already-seen** at startup so only genuinely
new activity is reported. Checks are de-duplicated per-poll (a re-failure on a new run still reports,
because the run goes through a `pending` phase that clears the set). Substitute the real
`<pr-number>` and `<owner/repo>`:
```
PR=<pr-number>; REPO=<owner/repo>
SEEN=$(mktemp)
# Seed existing Copilot comment/review ids as already-reported (only notify on NEW activity).
# Prefix by source (pc/ic/rv) so numeric ids from different endpoints can't collide.
{ gh api "repos/$REPO/pulls/$PR/comments" --paginate --jq '.[]|"pc-\(.id)"' 2>/dev/null
gh api "repos/$REPO/issues/$PR/comments" --paginate --jq '.[]|"ic-\(.id)"' 2>/dev/null
gh api "repos/$REPO/pulls/$PR/reviews" --jq '.[]|"rv-\(.id)"' 2>/dev/null; } >> "$SEEN" || true
report() { # stdin: "key<TAB>text"; emit unseen lines, persist their keys
while IFS=$'\t' read -r key text; do
[ -z "$key" ] && continue
grep -qxF "$key" "$SEEN" && continue
printf '%s\n' "$key" >> "$SEEN"
printf '%s\n' "$text"
done
}
seen_checks=""
while true; do
{ gh api "repos/$REPO/pulls/$PR/comments" --paginate --jq '.[]|select(.user.login|test("[Cc]opilot"))|"pc-\(.id)\t💬 Copilot (inline \(.path)): \(.body|gsub("\n";" ")[0:200])"' 2>/dev/null || true; } | report
{ gh api "repos/$REPO/issues/$PR/comments" --paginate --jq '.[]|select(.user.login|test("[Cc]opilot"))|"ic-\(.id)\t💬 Copilot: \(.body|gsub("\n";" ")[0:200])"' 2>/dev/null || true; } | report
{ gh api "repos/$REPO/pulls/$PR/reviews" --jq '.[]|select(.user.login|test("[Cc]opilot"))|select(.body!=null and .body!="")|"rv-\(.id)\t📝 Copilot review (\(.state)): \(.body|gsub("\n";" ")[0:200])"' 2>/dev/null || true; } | report
# Failed checks — `gh pr checks` has no --json in older gh; parse TSV (col2 status). gh exits non-zero on failure (fine in $()).
cur=$(gh pr checks "$PR" --repo "$REPO" 2>/dev/null | awk -F '\t' '$2=="fail"{print "❌ check failed: "$1}' | sort)
comm -13 <(printf '%s\n' "$seen_checks") <(printf '%s\n' "$cur")
seen_checks="$cur"
sleep 60
done
```
Pass `persistent: true` and a specific `description` (e.g. `Copilot comments + failed checks on
AND-xxxxx PR #<n>`). Tell the user it runs for the session and can be stopped with `TaskStop`.

View file

@ -0,0 +1,59 @@
---
name: navigation-graph
description: Refresh the app's navigation/dependency graph from live code and rebuild the interactive visualization. Scans features/domain Gradle project dependencies and every AppRoute usage, updates the generated regions of .claude/docs/navigation-graph.md (preserving hand-written prose and the curated config), then renders .claude/docs/module-connectivity.html (Area / Module / Screens views with team overlays). Use when the user asks to update/regenerate/refresh the navigation graph, screen map, module connectivity diagram or module-connectivity.html, after adding/removing AppRoute screens or feature/domain modules, or to add/recolor a team. Triggers: "update the navigation graph", "regenerate module-connectivity.html", "refresh the screen map", "rebuild the module connectivity diagram", "add a team to the graph".
allowed-tools: Bash, Read, Edit, Grep, Glob
---
Refresh and rebuild the app's connectivity visualization. The data flows **code → doc → HTML**:
```
features/domain/data build.gradle.kts deps ─┐
AppRoute.kt + every AppRoute.X usage ─┴─▶ build_graph.py ─▶ .claude/docs/navigation-graph.md
│ (data + curated config blocks)
render_html.py ─▶ .claude/docs/module-connectivity.html
```
`navigation-graph.md` is the source of truth. Its hand-written prose (sections 14: route tables, edges-with-triggers, nested routes, deep links) is **owned by humans and never overwritten**. The skill manages only the region between `<!-- NAVGRAPH:BEGIN -->` and `<!-- NAVGRAPH:END -->`, which holds:
- an **editable CONFIG json block** — functional groups (label/color/grid anchor), per-screen group + owner, and teams. Preserved across refreshes (human edits win).
- **auto data blocks**`areaGraph`, `moduleGraph`, `screensGraph`, `screensMeta`. Overwritten from code every run.
## To refresh after a code change (the common case)
Run both scripts from anywhere in the repo (they locate the root via `settings.gradle.kts`). The scan walks the whole tree — expect ~1020s.
```bash
python3 .claude/skills/navigation-graph/scripts/build_graph.py
python3 .claude/skills/navigation-graph/scripts/render_html.py
```
Then report to the user: the printed counts, **any `⚠ NEW screen` warnings**, and that `.claude/docs/module-connectivity.html` is a self-contained file they can open in a browser.
**If `build_graph.py` prints `⚠ NEW screen …` warnings:** a route was added to `AppRoute.kt` but isn't classified. The new screen was defaulted to group `misc` / owner `app`. Edit the CONFIG block in `.claude/docs/navigation-graph.md` to set its real `screenGroups[Name]` and `screenOwners[Name]`, then re-run both scripts. Pick the group/owner by reading where the route lives and is pushed from. Removed routes are reported as "no longer in code" and are harmless (kept in config for when they return).
## To change grouping, owners, colors, or teams
Edit the **CONFIG** json block inside `.claude/docs/navigation-graph.md` (between `<!-- NAVGRAPH:config:BEGIN -->` and `:END`), then run `render_html.py` (no need to re-scan code unless code changed):
- **`groups`** — add/rename a functional group or change its `color` / `label` / grid `anchor` (`x`,`y` are 01 fractions of the canvas).
- **`screenGroups` / `screenOwners`** — reassign a screen.
- **`teams`** — add a team object `{ "id", "name", "color", "roots": [...module path prefixes...], "screens": [...AppRoute names...] }`. `roots` drive the overlay in Area/Module views (e.g. `"features:onramp"`, `"domain:staking"`, `"data:swap"`); `screens` drive it in the Screens view (e.g. `"Send"`). A module/screen may be matched by either. The overlay (hull + rings, optional cluster force) and per-view member counts wire up automatically.
After editing CONFIG, re-run `render_html.py`. If you changed code-derived facts, run `build_graph.py` first.
## What gets extracted (and what's inferred)
- **Dependency edges** (Area/Module): only project (`projects.*`) deps among `features/*`, `domain/*` and `data/*` — external libraries excluded. Area view merges each area's `api`/`impl`/`models`. The Data-layer toggle in the HTML appears only when data modules are present.
- **Screen edges** (Screens): the **target** is exact — the `AppRoute.X` argument of a `push`/`replaceCurrent`/`replaceAll`/`popTo` call. The **source** is the navigating file's feature module collapsed to that feature's main screen (eponymous screen if one exists, else most-referenced), so intra-feature hops are merged. Calls from shared UI / app root attach to a synthetic **App shell** node. Group/owner come from the curated CONFIG.
## Files
```
.claude/skills/navigation-graph/
SKILL.md
assets/template.html # parameterized HTML (8 inject points: 4 data blocks + teams + group colors/labels/anchors)
assets/config.seed.json # initial curation; used only when the doc has no CONFIG block yet
scripts/build_graph.py # code -> navigation-graph.md (managed region)
scripts/render_html.py # navigation-graph.md -> module-connectivity.html
```
Outputs live in `.claude/docs/`. The scripts are idempotent — re-running never duplicates the managed region. Do not hand-edit the auto data blocks (they're regenerated); edit CONFIG instead. After regenerating, sanity-check the HTML by extracting its `<script>` and running `node --check` if Node is available.

View file

@ -0,0 +1,280 @@
{
"hubs": [
"domain:models",
"domain:core",
"domain:app-currency",
"domain:settings",
"domain:balance-hiding",
"domain:feedback",
"domain:demo"
],
"groups": {
"shell": {
"label": "app shell",
"color": "#5A6677",
"anchor": {
"x": 0.5,
"y": 0.07
}
},
"entry": {
"label": "entry",
"color": "#7DA2FF",
"anchor": {
"x": 0.18,
"y": 0.24
}
},
"onboarding": {
"label": "onboarding",
"color": "#34D8C4",
"anchor": {
"x": 0.5,
"y": 0.24
}
},
"wallet": {
"label": "wallet",
"color": "#E8A33D",
"anchor": {
"x": 0.82,
"y": 0.24
}
},
"portfolio": {
"label": "portfolio",
"color": "#B69CFF",
"anchor": {
"x": 0.18,
"y": 0.52
}
},
"tokenaction": {
"label": "token actions",
"color": "#FF8F6B",
"anchor": {
"x": 0.5,
"y": 0.52
}
},
"markets": {
"label": "markets / news",
"color": "#5BD08A",
"anchor": {
"x": 0.82,
"y": 0.52
}
},
"settings": {
"label": "settings",
"color": "#9AA7B8",
"anchor": {
"x": 0.18,
"y": 0.8
}
},
"tangempay": {
"label": "tangem pay",
"color": "#F2C14E",
"anchor": {
"x": 0.5,
"y": 0.8
}
},
"misc": {
"label": "misc",
"color": "#C7CFDA",
"anchor": {
"x": 0.82,
"y": 0.8
}
}
},
"groupOrder": [
"shell",
"entry",
"onboarding",
"wallet",
"portfolio",
"tokenaction",
"markets",
"settings",
"tangempay",
"misc"
],
"defaultGroup": "misc",
"defaultOwner": "app",
"screenGroups": {
"Initial": "entry",
"Home": "entry",
"Welcome": "entry",
"Disclaimer": "entry",
"CreateWalletSelection": "onboarding",
"CreateWalletStart": "onboarding",
"CreateHardwareWallet": "onboarding",
"CreateMobileWallet": "onboarding",
"AddExistingWallet": "onboarding",
"Onboarding": "onboarding",
"CreateWalletBackup": "onboarding",
"WalletBackup": "onboarding",
"WalletHardwareBackup": "onboarding",
"UpgradeWallet": "onboarding",
"WalletActivation": "onboarding",
"AccessCodeRecovery": "onboarding",
"UpdateAccessCode": "onboarding",
"ViewPhrase": "onboarding",
"Wallet": "wallet",
"Stories": "wallet",
"NFT": "wallet",
"NFTSend": "wallet",
"PushNotification": "wallet",
"PushNotificationSettings": "wallet",
"CurrencyDetails": "portfolio",
"ManageTokens": "portfolio",
"ChooseManagedTokens": "portfolio",
"CreateAccount": "portfolio",
"EditAccount": "portfolio",
"AccountDetails": "portfolio",
"ArchivedAccountList": "portfolio",
"Send": "tokenaction",
"SendEntryPoint": "tokenaction",
"Swap": "tokenaction",
"SwapCrypto": "tokenaction",
"Onramp": "tokenaction",
"OnrampSuccess": "tokenaction",
"BuyCrypto": "tokenaction",
"SellCrypto": "tokenaction",
"Staking": "tokenaction",
"YieldSupplyEntry": "tokenaction",
"Earn": "tokenaction",
"Markets": "markets",
"MarketsTokenDetails": "markets",
"News": "markets",
"NewsDetails": "markets",
"Details": "settings",
"DetailsSecurity": "settings",
"CardSettings": "settings",
"AppSettings": "settings",
"ResetToFactory": "settings",
"WalletSettings": "settings",
"ForgetWallet": "settings",
"AppCurrencySelector": "settings",
"ReferralProgram": "settings",
"AddressBook": "settings",
"WalletConnectSessions": "settings",
"TangemPayDetails": "tangempay",
"TangemPayHotWalletOnboarding": "tangempay",
"TangemPayOnboarding": "tangempay",
"Kyc": "tangempay",
"QrScanning": "misc",
"Usedesk": "misc",
"Survey": "misc"
},
"screenOwners": {
"Initial": "app",
"Home": "features:home",
"Welcome": "features:welcome",
"Disclaimer": "features:disclaimer",
"Wallet": "features:wallet",
"CurrencyDetails": "features:tokendetails",
"Send": "features:send",
"Details": "features:details",
"DetailsSecurity": "features:details",
"Usedesk": "features:usedesk",
"CardSettings": "features:details",
"AppSettings": "features:details",
"ResetToFactory": "features:details",
"AccessCodeRecovery": "features:onboarding-v2",
"ManageTokens": "features:manage-tokens",
"ChooseManagedTokens": "features:manage-tokens",
"WalletConnectSessions": "features:walletconnect",
"AddressBook": "features:address-book",
"QrScanning": "features:qr-scanning",
"ReferralProgram": "features:referral",
"Swap": "features:swap",
"AppCurrencySelector": "features:wallet-settings",
"Staking": "features:staking",
"PushNotification": "features:push-notifications",
"WalletSettings": "features:wallet-settings",
"PushNotificationSettings": "features:push-notification-settings",
"WalletBackup": "features:onboarding-v2",
"WalletHardwareBackup": "features:onboarding-v2",
"Markets": "features:markets",
"MarketsTokenDetails": "features:markets",
"Onramp": "features:onramp",
"OnrampSuccess": "features:onramp",
"BuyCrypto": "features:onramp",
"SellCrypto": "features:onramp",
"SwapCrypto": "features:swap-v2",
"Onboarding": "features:onboarding-v2",
"Stories": "features:stories",
"NFT": "features:nft",
"NFTSend": "features:nft",
"CreateWalletSelection": "features:create-wallet-selection",
"CreateWalletStart": "features:create-wallet-start",
"CreateHardwareWallet": "features:onboarding-v2",
"CreateMobileWallet": "features:hot-wallet",
"UpgradeWallet": "features:hot-wallet",
"AddExistingWallet": "features:onboarding-v2",
"WalletActivation": "features:tangempay",
"CreateWalletBackup": "features:onboarding-v2",
"UpdateAccessCode": "features:onboarding-v2",
"ViewPhrase": "features:onboarding-v2",
"ForgetWallet": "features:wallet-settings",
"SendEntryPoint": "features:send",
"CreateAccount": "features:account",
"EditAccount": "features:account",
"AccountDetails": "features:account",
"ArchivedAccountList": "features:account",
"TangemPayDetails": "features:tangempay",
"TangemPayHotWalletOnboarding": "features:tangempay",
"TangemPayOnboarding": "features:tangempay",
"Kyc": "features:kyc",
"Survey": "features:survey",
"YieldSupplyEntry": "features:yield-supply",
"NewsDetails": "features:feed",
"News": "features:feed",
"Earn": "features:feed"
},
"teams": [
{
"id": "grow",
"name": "Grow",
"color": "#FF6FD8",
"roots": [
"features:approval",
"features:onramp",
"features:send",
"features:staking",
"features:swap",
"features:swap-v2",
"features:yield-supply",
"domain:express",
"domain:offramp",
"domain:onramp",
"domain:staking",
"domain:swap",
"domain:yield-supply",
"domain:transaction",
"data:express",
"data:onramp",
"data:staking",
"data:swap",
"data:yield-supply"
],
"screens": [
"Send",
"Swap",
"Staking",
"Onramp",
"OnrampSuccess",
"BuyCrypto",
"SellCrypto",
"SwapCrypto",
"NFTSend",
"SendEntryPoint",
"YieldSupplyEntry"
]
}
]
}

View file

@ -0,0 +1,718 @@
<title>Tangem — features ↔ domain module connectivity</title>
<style>
:root{
--ground:#0E1116;--panel:#161B22;--panel-2:#1B222B;--line:#222B36;
--text:#C9D4E0;--muted:#74859A;--faint:#3A4757;
--features:#E8A33D;--domain:#34D8C4;--data:#B69CFF;--inverted:#FF5C6C;
--mono:ui-monospace,"SF Mono","JetBrains Mono",Menlo,Consolas,monospace;
--ui:"Helvetica Neue",Inter,system-ui,-apple-system,sans-serif;
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--ground);color:var(--text);font-family:var(--ui);
overflow:hidden;-webkit-font-smoothing:antialiased}
.app{display:flex;flex-direction:column;height:100vh;width:100vw}
header{flex:0 0 auto;border-bottom:1px solid var(--line);padding:14px 22px 12px;
display:flex;align-items:flex-end;justify-content:space-between;gap:24px;flex-wrap:wrap;
background:linear-gradient(180deg,#11161D,#0E1116)}
.titleblock{min-width:0}
.eyebrow{font-family:var(--mono);font-size:11px;letter-spacing:.34em;text-transform:uppercase;
color:var(--muted);margin:0 0 6px}
.eyebrow b{color:var(--domain);font-weight:600}
h1{margin:0;font-size:clamp(20px,3.2vw,30px);font-weight:800;letter-spacing:-.022em;line-height:1}
h1 .arrow{color:var(--muted);font-weight:400;padding:0 .15em}
.features-ink{color:var(--features)}.domain-ink{color:var(--domain)}
.stats{display:flex;gap:0;font-family:var(--mono)}
.stat{padding:0 18px;border-left:1px solid var(--line);text-align:right}
.stat:first-child{border-left:0}
.stat .num{font-size:22px;font-weight:700;line-height:1.05}
.stat .lbl{font-size:10px;letter-spacing:.12em;text-transform:uppercase;color:var(--muted);margin-top:3px}
.stat.warn .num{color:var(--inverted)}
.body{flex:1 1 auto;display:flex;min-height:0}
.rail{flex:0 0 270px;border-right:1px solid var(--line);background:var(--panel);
overflow-y:auto;padding:16px 16px 28px}
.stage{flex:1 1 auto;position:relative;min-width:0;
background:radial-gradient(120% 120% at 30% 0%,#12171F 0%,#0E1116 60%)}
svg{width:100%;height:100%;display:block;cursor:grab;touch-action:none}
svg.grabbing{cursor:grabbing}
/* view switch */
.viewswitch{display:flex;background:var(--ground);border:1px solid var(--line);
border-radius:9px;padding:3px;gap:3px;margin-bottom:20px}
.viewswitch button{flex:1;border:0;background:transparent;color:var(--muted);
font-family:var(--mono);font-size:12px;font-weight:600;padding:8px 6px;border-radius:6px;
cursor:pointer;letter-spacing:.04em;transition:.13s;display:flex;flex-direction:column;gap:2px;align-items:center}
.viewswitch button .sub{font-size:9.5px;font-weight:500;letter-spacing:.02em;opacity:.7}
.viewswitch button:hover{color:var(--text)}
.viewswitch button.on{background:var(--panel-2);color:var(--text);box-shadow:inset 0 0 0 1px var(--line)}
.grp{margin-bottom:20px}
.grp h2{font-family:var(--mono);font-size:10px;letter-spacing:.2em;text-transform:uppercase;
color:var(--muted);margin:0 0 9px;font-weight:600}
.search{width:100%;background:var(--ground);border:1px solid var(--line);color:var(--text);
font-family:var(--mono);font-size:13px;padding:9px 10px;border-radius:7px;outline:none}
.search:focus{border-color:var(--domain);box-shadow:0 0 0 2px rgba(52,216,196,.16)}
.search::placeholder{color:var(--faint)}
.toggles{display:flex;flex-direction:column;gap:2px}
.tog{display:flex;align-items:center;gap:9px;cursor:pointer;padding:7px 8px;border-radius:7px;
font-size:13px;user-select:none}
.tog:hover{background:var(--panel-2)}
.tog .box{width:15px;height:15px;border-radius:4px;border:1.5px solid var(--faint);flex:0 0 auto;position:relative;transition:.12s}
.tog.on .box{background:var(--domain);border-color:var(--domain)}
.tog.on .box::after{content:"";position:absolute;left:4px;top:1px;width:4px;height:8px;
border:solid var(--ground);border-width:0 2px 2px 0;transform:rotate(45deg)}
.tog .dot{width:9px;height:9px;border-radius:50%;flex:0 0 auto}
.tog .dot.f{background:var(--features)}.tog .dot.d{background:var(--domain)}.tog .dot.da{background:var(--data)}
.tog .meta{margin-left:auto;font-family:var(--mono);font-size:11px;color:var(--muted)}
.btn{width:100%;text-align:left;background:var(--ground);border:1px solid var(--line);color:var(--text);
font-family:var(--mono);font-size:12px;padding:9px 11px;border-radius:7px;cursor:pointer;
display:flex;align-items:center;gap:8px;transition:.12s}
.btn:hover{border-color:var(--inverted);color:#fff}
.btn .swatch{width:18px;height:0;border-top:2px solid var(--inverted);flex:0 0 auto}
.btn.active{border-color:var(--inverted);background:rgba(255,92,108,.08)}
.hubtext{font-size:11px;color:var(--muted);margin:8px 2px 0;line-height:1.5}
.hubtext span{font-family:var(--mono);color:var(--text)}
.insp{border-top:1px solid var(--line);padding-top:16px}
.insp .hint{color:var(--muted);font-size:12.5px;line-height:1.55}
.insp-id{font-family:var(--mono);font-size:14.5px;font-weight:700;word-break:break-all;line-height:1.25}
.chip{display:inline-block;font-family:var(--mono);font-size:10px;letter-spacing:.08em;text-transform:uppercase;
padding:3px 8px;border-radius:20px;margin-top:8px;font-weight:600}
.chip.f{background:rgba(232,163,61,.15);color:var(--features)}
.chip.d{background:rgba(52,216,196,.15);color:var(--domain)}
.chip.da{background:rgba(182,156,255,.15);color:var(--data)}
.degline{display:flex;gap:14px;font-family:var(--mono);font-size:12px;margin:12px 0 4px}
.degline b{color:var(--text);font-weight:700}.degline .k{color:var(--muted)}
.deplist h3{font-family:var(--mono);font-size:10px;letter-spacing:.14em;text-transform:uppercase;
color:var(--muted);margin:14px 0 7px;font-weight:600;display:flex;justify-content:space-between}
.deplist ul{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:1px}
.deplist li{font-family:var(--mono);font-size:12px;padding:4px 7px;border-radius:5px;cursor:pointer;
display:flex;justify-content:space-between;gap:8px;color:var(--text)}
.deplist li:hover{background:var(--panel-2)}
.deplist li .w{color:var(--muted);font-size:11px;white-space:nowrap}
.deplist li .dot{width:7px;height:7px;border-radius:50%;margin-right:7px;flex:0 0 auto;align-self:center}
.tog.act{background:var(--panel-2);box-shadow:inset 0 0 0 1px var(--line)}
.deplist li span.nm{display:flex;align-items:center;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.deplist li.f span.nm::before,.deplist li.d span.nm::before,.deplist li.da span.nm::before{content:"";display:inline-block;width:7px;height:7px;
border-radius:50%;margin-right:7px;flex:0 0 auto}
.deplist li.f span.nm::before{background:var(--features)}
.deplist li.d span.nm::before{background:var(--domain)}
.deplist li.da span.nm::before{background:var(--data)}
.edge{stroke:var(--faint);stroke-opacity:.10;fill:none;transition:stroke-opacity .15s}
.edge.inv{stroke:var(--inverted);stroke-opacity:.22}
.node-label{font-family:var(--mono);font-size:9.5px;fill:var(--text);pointer-events:none;opacity:0;
transition:opacity .15s;paint-order:stroke;stroke:var(--ground);stroke-width:2.4px;stroke-linejoin:round}
.node-label.show{opacity:.92}
.node-dot{cursor:pointer}
.node-dot circle{transition:fill-opacity .15s,stroke .12s}
.dim{opacity:.12 !important}
.halo{fill:none;stroke-width:2.6;opacity:0;transition:opacity .15s;pointer-events:none}
.hull{stroke-width:1.6;fill-opacity:.08;stroke-opacity:.6;pointer-events:none}
.hull-label{font-family:var(--mono);font-size:12px;font-weight:700;letter-spacing:.05em;text-transform:uppercase;
pointer-events:none;paint-order:stroke;stroke:var(--ground);stroke-width:3.2px;stroke-linejoin:round;opacity:.92}
.legend{position:absolute;left:16px;bottom:14px;display:flex;gap:18px;align-items:center;
font-family:var(--mono);font-size:11px;color:var(--muted);background:rgba(14,17,22,.72);
backdrop-filter:blur(4px);border:1px solid var(--line);border-radius:9px;padding:8px 13px;
flex-wrap:wrap;max-width:calc(100% - 32px)}
.legend .it{display:flex;align-items:center;gap:7px}
.legend .sw{width:11px;height:11px;border-radius:50%}
.legend .sw.f{background:var(--features)}.legend .sw.d{background:var(--domain)}.legend .sw.da{background:var(--data)}
.legend .ln{width:18px;border-top:2px solid var(--inverted)}
.legend .sz{display:flex;align-items:center;gap:4px}
.legend .sz i{display:inline-block;border-radius:50%;background:var(--muted)}
.hud{position:absolute;right:16px;top:14px;font-family:var(--mono);font-size:11px;color:var(--muted);
text-align:right;line-height:1.6;pointer-events:none}
.hud b{color:var(--text);font-weight:600}
.reset{position:absolute;right:16px;bottom:14px;font-family:var(--mono);font-size:11px;
background:rgba(14,17,22,.72);backdrop-filter:blur(4px);border:1px solid var(--line);
color:var(--muted);border-radius:8px;padding:7px 11px;cursor:pointer}
.reset:hover{color:var(--text);border-color:var(--faint)}
@media (max-width:880px){
body{overflow:auto}.app{height:auto}.body{flex-direction:column}
.rail{flex-basis:auto;border-right:0;border-bottom:1px solid var(--line)}
.stage{height:72vh}.stats{flex-wrap:wrap}
}
@media (prefers-reduced-motion:reduce){.edge,.node-label,.node-dot circle{transition:none}}
</style>
<div class="app">
<header>
<div class="titleblock">
<p class="eyebrow"><b>Tangem</b> · android · <span id="eyebrowKind">gradle dependency graph</span></p>
<h1><span class="features-ink">features</span><span class="arrow"></span><span class="domain-ink">domain</span> connectivity</h1>
</div>
<div class="stats">
<div class="stat"><div class="num" id="statNodes">88</div><div class="lbl" id="statNodesLbl">areas</div></div>
<div class="stat"><div class="num" id="statEdges">716</div><div class="lbl" id="statEdgesLbl">dep links</div></div>
<div class="stat warn"><div class="num" id="invCount">6</div><div class="lbl">inverted</div></div>
</div>
</header>
<div class="body">
<aside class="rail">
<div class="viewswitch" id="viewswitch">
<button data-view="area" class="on">Area<span class="sub">api+impl merged</span></button>
<button data-view="module">Module<span class="sub">every module</span></button>
<button data-view="screens">Screens<span class="sub">AppRoute map</span></button>
</div>
<div class="grp">
<h2>Find a module</h2>
<input class="search" id="search" placeholder="e.g. staking, wallet, tokens" autocomplete="off" spellcheck="false">
</div>
<div class="grp" id="grpLayers">
<h2>Layers</h2>
<div class="toggles">
<label class="tog on" data-layer="features"><span class="box"></span><span class="dot f"></span>features<span class="meta" id="cntF"></span></label>
<label class="tog on" data-layer="domain"><span class="box"></span><span class="dot d"></span>domain<span class="meta" id="cntD"></span></label>
<label class="tog on" data-layer="data" id="togDataRow" style="display:none"><span class="box"></span><span class="dot da"></span>data<span class="meta" id="cntData"></span></label>
</div>
</div>
<div class="grp" id="grpTeams">
<h2>Teams</h2>
<div class="toggles" id="teamList"></div>
<label class="tog" id="togCluster"><span class="box"></span>Cluster enabled teams</label>
<p class="hubtext">Outlines &amp; rings mark a team's owned modules (in Area / Module) or screens (in Screens). <span>More teams can be added in the config.</span></p>
</div>
<div class="grp" id="grpDeclutter">
<h2>Declutter</h2>
<div class="toggles">
<label class="tog" id="togHubs"><span class="box"></span>Hide utility hubs<span class="meta" id="hubCount"></span></label>
<label class="tog" id="togApi"><span class="box"></span>Only <code>api</code> links</label>
</div>
<p class="hubtext">Hubs hidden: <span id="hubList"></span> — depended on near-universally.</p>
</div>
<div class="grp" id="grpLayering">
<h2>Layering check</h2>
<button class="btn" id="btnInv"><span class="swatch"></span>Show inverted deps</button>
<p class="hubtext">A lower-layer <span style="color:var(--inverted)">domain / data</span> module importing a <span style="color:var(--features)">feature</span> <code>api</code> — reaching up across the layer boundary.</p>
</div>
<div class="grp" id="grpGroups" style="display:none">
<h2>Functional groups</h2>
<div class="toggles" id="groupList"></div>
<p class="hubtext">Click a group to isolate its screens. Node size = navigation links. Arrow = navigates to.</p>
</div>
<div class="insp" id="insp">
<p class="hint">Hover a node to trace its links. <b style="color:var(--text)">Click</b> to pin it and list its dependencies. Drag nodes to rearrange · scroll to zoom · drag canvas to pan.</p>
</div>
</aside>
<div class="stage">
<svg id="svg" viewBox="0 0 1200 820" preserveAspectRatio="xMidYMid meet" aria-label="Module dependency graph"></svg>
<div class="hud" id="hud">consumers <span style="color:var(--features)">left</span> · foundations <span style="color:var(--domain)">right</span><br>arrow points to the dependency<br><b>scroll</b> zoom · <b>drag</b> pan</div>
<button class="reset" id="resetView">reset view</button>
<div class="legend" id="legendBox">
<div class="it"><span class="sw f"></span>features</div>
<div class="it"><span class="sw d"></span>domain</div>
<div class="it" id="legendData" style="display:none"><span class="sw da"></span>data</div>
<div class="it"><span class="ln"></span>inverted dep</div>
<div class="it sz">size&nbsp;<i style="width:6px;height:6px"></i><i style="width:11px;height:11px"></i><i style="width:16px;height:16px"></i>&nbsp;= total degree</div>
</div>
</div>
</div>
</div>
<script>
const RAW = { area: /*__AREA_DATA__*/null, module: /*__MODULE_DATA__*/null, screens: /*__SCREENS_DATA__*/null };
const SCREENMETA = /*__SCREENS_META__*/null;
const BANDS2={features:0.28,domain:0.72};
const VIEWCFG = {
area: {W:1200,H:820, labelFloor:13,rScale:1.85,rep:14000,ky:0.006, prewarm:340,kind:'areas', bandX:BANDS2},
module: {W:1640,H:1120,labelFloor:20,rScale:1.45,rep:23000,ky:0.0035,prewarm:480,kind:'modules',bandX:BANDS2},
screens:{W:1500,H:1040,labelFloor:0, rScale:1.7, rep:20000,ky:0.02, prewarm:460,kind:'screens',
anchors:/*__GROUP_ANCHORS__*/{}}
};
const GROUP_COLORS=/*__GROUP_COLORS__*/{};
const GROUP_LABELS=/*__GROUP_LABELS__*/{};
const SVGNS="http://www.w3.org/2000/svg";
const css=getComputedStyle(document.documentElement);
const FEAT=css.getPropertyValue('--features').trim();
const DOM=css.getPropertyValue('--domain').trim();
const DATAC=css.getPropertyValue('--data').trim();
const INV=css.getPropertyValue('--inverted').trim();
function colorFor(l){if(GROUP_COLORS[l])return GROUP_COLORS[l];return l==='features'?FEAT:l==='data'?DATAC:DOM;}
function layerCls(l){return l==='features'?'f':l==='data'?'da':'d';}
function hexA(h,a){const n=parseInt(h.slice(1),16);return `rgba(${(n>>16)&255},${(n>>8)&255},${n&255},${a})`;}
// ---- team ownership (extensible: add one entry per team) ----
const TEAMS=/*__TEAMS__*/[];
function normId(id){return id.charAt(0)===':'?id.slice(1):id;}
function teamsOf(id){const p=normId(id);return TEAMS.filter(t=>
(t.roots&&t.roots.some(r=>p===r||p.startsWith(r+':'))) || (t.screens&&t.screens.includes(id)));}
const enabledTeams=new Set();
let clusterOn=false;
const reduced=matchMedia('(prefers-reduced-motion:reduce)').matches;
// ---- persistent SVG scaffold ----
const svg=document.getElementById('svg');
const defs=document.createElementNS(SVGNS,'defs');
defs.innerHTML='<pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M40 0H0V40" fill="none" stroke="#19212B" stroke-width="1"/></pattern>';
svg.appendChild(defs);
const gRoot=document.createElementNS(SVGNS,'g'); svg.appendChild(gRoot);
const bg=document.createElementNS(SVGNS,'rect');
bg.setAttribute('x',-2000);bg.setAttribute('y',-2000);bg.setAttribute('fill','url(#grid)');bg.setAttribute('opacity','0.5');
const gHulls=document.createElementNS(SVGNS,'g');
const gEdges=document.createElementNS(SVGNS,'g');
const gNodes=document.createElementNS(SVGNS,'g');
gRoot.appendChild(bg);gRoot.appendChild(gHulls);gRoot.appendChild(gEdges);gRoot.appendChild(gNodes);
// ---- mutable graph state ----
let nodes,byId,edges,outAdj,inAdj,HUBS,W,H,labelFloor;
let CURRENT='area',selected=null,alpha=1,raf=null,REP,KY;
// ---- model ----
function buildModel(name){
const d=RAW[name],cfg=VIEWCFG[name];
W=cfg.W;H=cfg.H;labelFloor=cfg.labelFloor;REP=cfg.rep;KY=cfg.ky;
nodes=d.n.map(([id,label,layer,inD,outD])=>({id,label,layer,inD,outD,deg:inD+outD,
r:3.8+Math.sqrt(inD+outD+1)*cfg.rScale, color:colorFor(layer), teams:teamsOf(id)}));
byId=new Map(nodes.map(n=>[n.id,n]));
edges=d.e.map(([s,t,w,api])=>{const sn=byId.get(s),tn=byId.get(t);
return {s:sn,t:tn,w,api:!!api,inv:tn.layer==='features'&&sn.layer!=='features'};});
outAdj=new Map(nodes.map(n=>[n.id,[]]));
inAdj=new Map(nodes.map(n=>[n.id,[]]));
edges.forEach(e=>{outAdj.get(e.s.id).push(e);inAdj.get(e.t.id).push(e);});
HUBS=new Set(nodes.filter(n=>n.inD>=12&&n.outD<=3).map(n=>n.id));
}
// ---- layout ----
let seed=1337;
function rnd(){seed=(seed*1664525+1013904223)&0x7fffffff;return seed/0x7fffffff;}
function initLayout(){
seed=1337;
const cfg=VIEWCFG[CURRENT];
for(const n of nodes){
if(cfg.anchors&&cfg.anchors[n.layer]){
n.tx=W*cfg.anchors[n.layer].x;n.ty=H*cfg.anchors[n.layer].y;
n.x=n.tx+(rnd()-0.5)*220;n.y=n.ty+(rnd()-0.5)*220;
}else{
const bx=cfg.bandX?cfg.bandX[n.layer]:undefined;n.tx=W*(bx===undefined?0.5:bx);n.ty=H*0.5;
n.x=n.tx+(rnd()-0.5)*240;n.y=H*0.5+(rnd()-0.5)*H*0.86;
}
n.vx=0;n.vy=0;n.fixed=false;
}
let a=1;
for(let i=0;i<VIEWCFG[CURRENT].prewarm;i++){tick(a);a*=0.992;}
}
function tick(a){
const n=nodes.length;
for(let i=0;i<n;i++){nodes[i].fx=0;nodes[i].fy=0;}
for(let i=0;i<n;i++){const A=nodes[i];
for(let j=i+1;j<n;j++){const B=nodes[j];
let dx=A.x-B.x,dy=A.y-B.y,d2=dx*dx+dy*dy;if(d2<0.01)d2=0.01;
const d=Math.sqrt(d2);let f=REP/d2;if(f>42)f=42;
const ux=dx/d,uy=dy/d;A.fx+=ux*f;A.fy+=uy*f;B.fx-=ux*f;B.fy-=uy*f;}}
for(const e of edges){const A=e.s,B=e.t;
let dx=B.x-A.x,dy=B.y-A.y,d=Math.sqrt(dx*dx+dy*dy)||0.01;
const f=(d-96)*0.018,ux=dx/d,uy=dy/d;
A.fx+=ux*f;A.fy+=uy*f;B.fx-=ux*f;B.fy-=uy*f;}
if(clusterOn&&enabledTeams.size)computeTeamCentroids();
for(const A of nodes){
const ct=A._cteam;
if(clusterOn&&ct&&ct.cx!==undefined){
A.fx+=(ct.cx-A.x)*0.04;A.fy+=(ct.cy-A.y)*0.04;
A.fx+=(A.tx-A.x)*0.005;A.fy+=(A.ty-A.y)*KY;
}else{A.fx+=(A.tx-A.x)*0.018;A.fy+=(A.ty-A.y)*KY;}
}
for(const A of nodes){if(A.fixed)continue;
A.vx=(A.vx+A.fx)*0.84;A.vy=(A.vy+A.fy)*0.84;A.x+=A.vx*a;A.y+=A.vy*a;
A.x=Math.max(30,Math.min(W-30,A.x));A.y=Math.max(30,Math.min(H-30,A.y));}
}
// ---- DOM build ----
function buildDOM(){
svg.setAttribute('viewBox',`0 0 ${W} ${H}`);
bg.setAttribute('width',W+4000);bg.setAttribute('height',H+4000);
gEdges.textContent='';gNodes.textContent='';
edges.forEach(e=>{const ln=document.createElementNS(SVGNS,'line');
ln.setAttribute('class',e.inv?'edge inv':'edge');e.el=ln;gEdges.appendChild(ln);});
nodes.forEach(n=>{
const g=document.createElementNS(SVGNS,'g');g.setAttribute('class','node-dot');
const c=document.createElementNS(SVGNS,'circle');
c.setAttribute('r',n.r);c.setAttribute('fill',n.color);c.setAttribute('fill-opacity','0.92');
c.setAttribute('stroke','#0E1116');c.setAttribute('stroke-width','1.5');
const halo=document.createElementNS(SVGNS,'circle');halo.setAttribute('class','halo');halo.setAttribute('r',n.r+5);
const t=document.createElementNS(SVGNS,'text');t.setAttribute('class','node-label');
t.setAttribute('x',n.r+4);t.setAttribute('y',3.2);t.textContent=n.label;
g.appendChild(halo);g.appendChild(c);g.appendChild(t);n.gEl=g;n.cEl=c;n.tEl=t;n.haloEl=halo;gNodes.appendChild(g);
g.addEventListener('pointerenter',()=>{if(!selected)focusNode(n.id);});
g.addEventListener('pointerleave',()=>{if(!selected)clearFocus();});
g.addEventListener('click',ev=>{ev.stopPropagation();selectNode(n.id);});
g.addEventListener('pointerdown',startDrag);
});
}
function render(){
for(const e of edges){const A=e.s,B=e.t;
let dx=B.x-A.x,dy=B.y-A.y,d=Math.sqrt(dx*dx+dy*dy)||1;const ux=dx/d,uy=dy/d;
e.el.setAttribute('x1',(A.x+ux*A.r).toFixed(1));e.el.setAttribute('y1',(A.y+uy*A.r).toFixed(1));
e.el.setAttribute('x2',(B.x-ux*(B.r+2.5)).toFixed(1));e.el.setAttribute('y2',(B.y-uy*(B.r+2.5)).toFixed(1));}
for(const n of nodes)n.gEl.setAttribute('transform',`translate(${n.x.toFixed(1)},${n.y.toFixed(1)})`);
renderTeamOverlay();
}
function applyBaseLabels(){
for(const n of nodes){
if(n.deg>=labelFloor&&!n.hidden)n.tEl.classList.add('show');
else n.tEl.classList.remove('show');}
}
// ---- animation ----
function animate(){tick(alpha);alpha*=0.99;render();
if(alpha>0.015||dragging)raf=requestAnimationFrame(animate);else raf=null;}
function reheat(v){alpha=Math.max(alpha,v);if(!raf&&!reduced)raf=requestAnimationFrame(animate);}
// ---- highlight ----
function setEdge(e,on){
if(on){e.el.style.stroke=e.inv?INV:e.s.color;e.el.style.strokeOpacity='0.85';
e.el.style.strokeWidth=Math.min(0.7+e.w*0.55,4.2);}
else{e.el.style.stroke='';e.el.style.strokeOpacity='';e.el.style.strokeWidth='';}
}
function dimAll(bright){
for(const n of nodes){if(n.hidden)continue;
if(bright.has(n.id)){n.gEl.classList.remove('dim');n.tEl.classList.add('show');}
else{n.gEl.classList.add('dim');if(n.deg<labelFloor)n.tEl.classList.remove('show');}}
}
function focusNode(id){
const bright=new Set([id]),incident=[];
for(const e of outAdj.get(id)){if(e.s.hidden||e.t.hidden)continue;bright.add(e.t.id);incident.push(e);}
for(const e of inAdj.get(id)){if(e.s.hidden||e.t.hidden)continue;bright.add(e.s.id);incident.push(e);}
edges.forEach(e=>{setEdge(e,false);if(!e.s.hidden&&!e.t.hidden)e.el.style.strokeOpacity='0.03';});
incident.forEach(e=>setEdge(e,true));
dimAll(bright);
const n=byId.get(id);n.cEl.setAttribute('stroke','#fff');n.cEl.setAttribute('stroke-width','2');
}
function clearFocus(){
edges.forEach(e=>{setEdge(e,false);e.el.style.strokeOpacity='';});
for(const n of nodes){if(n.hidden)continue;n.gEl.classList.remove('dim');
n.cEl.setAttribute('stroke','#0E1116');n.cEl.setAttribute('stroke-width','1.5');}
applyBaseLabels();
}
function selectNode(id){
if(btnInv.classList.contains('active'))toggleInverted(false);
selected=id;focusNode(id);renderInspector(byId.get(id));
}
// ---- inspector ----
const insp=document.getElementById('insp');
function renderInspectorHint(){
insp.innerHTML='<p class="hint">Hover a node to trace its links. <b style="color:var(--text)">Click</b> to pin it and list its dependencies. Drag nodes to rearrange · scroll to zoom · drag canvas to pan.</p>';
}
function depItem(node,e){
const li=document.createElement('li');
const nm=document.createElement('span');nm.className='nm';
const dot=document.createElement('span');dot.className='dot';dot.style.background=node.color;
nm.appendChild(dot);nm.appendChild(document.createTextNode(node.id));
const w=document.createElement('span');w.className='w';w.textContent=(e.w>1?e.w+'× ':'')+(e.api?'api':'');
li.appendChild(nm);li.appendChild(w);
li.addEventListener('click',ev=>{ev.stopPropagation();selectNode(node.id);});
return li;
}
function renderInspector(n){
const navView=CURRENT==='screens';
const outs=outAdj.get(n.id).slice().sort((a,b)=>b.w-a.w);
const ins=inAdj.get(n.id).slice().sort((a,b)=>b.w-a.w);
insp.innerHTML='';
const id=document.createElement('div');id.className='insp-id';id.textContent=n.id;insp.appendChild(id);
const chip=document.createElement('span');chip.className='chip';chip.style.color=n.color;chip.style.background=hexA(n.color,0.16);
chip.textContent=navView?(GROUP_LABELS[n.layer]||n.layer):n.layer;insp.appendChild(chip);
if(navView){
const m=SCREENMETA[n.id];
const info=document.createElement('div');info.className='hubtext';info.style.margin='10px 0 2px';
if(m){info.innerHTML=`<div style="font-family:var(--mono);color:var(--text);word-break:break-all">${m.path||'—'}</div>`+
`<div style="margin-top:6px">owner <span style="font-family:var(--mono);color:var(--text)">${m.owner}</span> · ${m.total} refs in ${m.refs.length} module(s)</div>`;}
else info.textContent='Synthetic origin for navigation from the app root / shared UI (no AppRoute of its own).';
insp.appendChild(info);
}
const deg=document.createElement('div');deg.className='degline';
deg.innerHTML=`<span><span class="k">${navView?'navigates to':'depends on'}</span> <b>${n.outD}</b></span><span><span class="k">${navView?'reached from':'used by'}</span> <b>${n.inD}</b></span>`;
insp.appendChild(deg);
const mk=(title,arr,pick)=>{
const wrap=document.createElement('div');wrap.className='deplist';
const h=document.createElement('h3');h.innerHTML=`${title}<span>${arr.length}</span>`;wrap.appendChild(h);
if(!arr.length){const p=document.createElement('p');p.style.cssText='color:var(--faint);font-family:var(--mono);font-size:11px;margin:0 0 0 2px';p.textContent='— none —';wrap.appendChild(p);}
else{const ul=document.createElement('ul');arr.forEach(e=>ul.appendChild(depItem(pick(e),e)));wrap.appendChild(ul);}
insp.appendChild(wrap);
};
mk(navView?'Navigates to →':'Depends on →',outs,e=>e.t);
mk(navView?'← Reached from':'← Used by',ins,e=>e.s);
if(navView&&SCREENMETA[n.id]){
const wrap=document.createElement('div');wrap.className='deplist';
const h=document.createElement('h3');h.innerHTML=`Referenced in<span>${SCREENMETA[n.id].refs.length}</span>`;wrap.appendChild(h);
const ul=document.createElement('ul');
SCREENMETA[n.id].refs.forEach(([a,c])=>{const li=document.createElement('li');
const nm=document.createElement('span');nm.className='nm';nm.textContent=a;
const w=document.createElement('span');w.className='w';w.textContent=c+'×';
li.appendChild(nm);li.appendChild(w);ul.appendChild(li);});
wrap.appendChild(ul);insp.appendChild(wrap);
}
}
// ---- zoom / pan ----
let view={k:1,x:0,y:0};
function applyView(){gRoot.setAttribute('transform',`translate(${view.x} ${view.y}) scale(${view.k})`);}
function screenToVB(ev){const p=svg.createSVGPoint();p.x=ev.clientX;p.y=ev.clientY;return p.matrixTransform(svg.getScreenCTM().inverse());}
function vbToWorld(v){return {x:(v.x-view.x)/view.k,y:(v.y-view.y)/view.k};}
svg.addEventListener('wheel',ev=>{ev.preventDefault();
const vb=screenToVB(ev),w=vbToWorld(vb),f=Math.pow(1.0016,-ev.deltaY);
view.k=Math.max(0.25,Math.min(5,view.k*f));
view.x=vb.x-w.x*view.k;view.y=vb.y-w.y*view.k;applyView();
},{passive:false});
let panning=null;
svg.addEventListener('pointerdown',ev=>{
if(ev.target.closest('.node-dot'))return; // node handles its own
panning={sx:ev.clientX,sy:ev.clientY,vx:view.x,vy:view.y,moved:false};
svg.classList.add('grabbing');
window.addEventListener('pointermove',onPan);window.addEventListener('pointerup',endPan);
});
function onPan(ev){if(!panning)return;const ctm=svg.getScreenCTM();
const dx=(ev.clientX-panning.sx)/ctm.a,dy=(ev.clientY-panning.sy)/ctm.d;
if(Math.abs(ev.clientX-panning.sx)+Math.abs(ev.clientY-panning.sy)>3)panning.moved=true;
view.x=panning.vx+dx;view.y=panning.vy+dy;applyView();}
function endPan(){const moved=panning&&panning.moved;panning=null;svg.classList.remove('grabbing');
window.removeEventListener('pointermove',onPan);window.removeEventListener('pointerup',endPan);
if(!moved){selected=null;clearFocus();renderInspectorHint();}}
document.getElementById('resetView').addEventListener('click',()=>{view={k:1,x:0,y:0};applyView();});
// ---- node drag ----
let dragging=null;
function startDrag(ev){
const n=nodes.find(x=>x.gEl===ev.currentTarget);if(!n)return;
ev.preventDefault();ev.stopPropagation();dragging=n;n.fixed=true;
ev.currentTarget.setPointerCapture(ev.pointerId);
window.addEventListener('pointermove',onDrag);window.addEventListener('pointerup',endDrag);
}
function onDrag(ev){if(!dragging)return;const w=vbToWorld(screenToVB(ev));
dragging.x=Math.max(30,Math.min(W-30,w.x));dragging.y=Math.max(30,Math.min(H-30,w.y));
dragging.vx=0;dragging.vy=0;reheat(0.25);render();}
function endDrag(){if(dragging)dragging.fixed=false;dragging=null;
window.removeEventListener('pointermove',onDrag);window.removeEventListener('pointerup',endDrag);}
// ---- team overlay ----
function setClusterMembership(){
for(const n of nodes){n._cteam=null;
if(!clusterOn)continue;
for(const t of n.teams){if(enabledTeams.has(t.id)){n._cteam=t;break;}}}
}
function computeTeamCentroids(){
for(const t of TEAMS){if(!enabledTeams.has(t.id))continue;
let sx=0,sy=0,c=0;
for(const n of nodes){if(!n.hidden&&n._cteam===t){sx+=n.x;sy+=n.y;c++;}}
if(c){t.cx=sx/c;t.cy=sy/c;}}
}
function updateHalos(){
for(const n of nodes){
const t=n.teams.find(tt=>enabledTeams.has(tt.id));
if(t){n.haloEl.setAttribute('stroke',t.color);n.haloEl.style.opacity='0.9';}
else n.haloEl.style.opacity='0';}
}
function convexHull(pts){
pts=pts.slice().sort((a,b)=>a.x-b.x||a.y-b.y);
const n=pts.length;if(n<3)return pts;
const cross=(o,a,b)=>(a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x);
const lo=[];for(const p of pts){while(lo.length>=2&&cross(lo[lo.length-2],lo[lo.length-1],p)<=0)lo.pop();lo.push(p);}
const up=[];for(let i=n-1;i>=0;i--){const p=pts[i];while(up.length>=2&&cross(up[up.length-2],up[up.length-1],p)<=0)up.pop();up.push(p);}
lo.pop();up.pop();return lo.concat(up);
}
function smoothPath(p){
const n=p.length;if(n<3)return '';
const mid=(a,b)=>({x:(a.x+b.x)/2,y:(a.y+b.y)/2});const s=mid(p[n-1],p[0]);
let d=`M ${s.x.toFixed(1)} ${s.y.toFixed(1)}`;
for(let i=0;i<n;i++){const cur=p[i],nx=p[(i+1)%n],m=mid(cur,nx);
d+=` Q ${cur.x.toFixed(1)} ${cur.y.toFixed(1)} ${m.x.toFixed(1)} ${m.y.toFixed(1)}`;}
return d+' Z';
}
function renderTeamOverlay(){
for(const t of TEAMS){
if(!t._hullEl){
t._hullEl=document.createElementNS(SVGNS,'path');t._hullEl.setAttribute('class','hull');
t._hullEl.setAttribute('fill',t.color);t._hullEl.setAttribute('stroke',t.color);gHulls.appendChild(t._hullEl);
t._labelEl=document.createElementNS(SVGNS,'text');t._labelEl.setAttribute('class','hull-label');
t._labelEl.setAttribute('fill',t.color);t._labelEl.setAttribute('text-anchor','middle');gHulls.appendChild(t._labelEl);
}
if(!enabledTeams.has(t.id)){t._hullEl.setAttribute('d','');t._labelEl.textContent='';continue;}
const mem=nodes.filter(n=>!n.hidden&&n.teams.includes(t));
if(!mem.length){t._hullEl.setAttribute('d','');t._labelEl.textContent='';continue;}
if(mem.length<3){
let sx=0,sy=0,my=Infinity;mem.forEach(n=>{sx+=n.x;sy+=n.y;if(n.y<my)my=n.y;});
t._hullEl.setAttribute('d','');t._labelEl.setAttribute('x',sx/mem.length);t._labelEl.setAttribute('y',my-14);t._labelEl.textContent=t.name;continue;}
const hull=convexHull(mem.map(n=>({x:n.x,y:n.y})));
let cx=0,cy=0;hull.forEach(p=>{cx+=p.x;cy+=p.y;});cx/=hull.length;cy/=hull.length;
const ex=hull.map(p=>{const dx=p.x-cx,dy=p.y-cy,d=Math.hypot(dx,dy)||1;const pad=32;return {x:p.x+dx/d*pad,y:p.y+dy/d*pad};});
t._hullEl.setAttribute('d',smoothPath(ex));
let miny=Infinity;ex.forEach(p=>{if(p.y<miny)miny=p.y;});
t._labelEl.setAttribute('x',cx);t._labelEl.setAttribute('y',miny-8);t._labelEl.textContent=t.name;
}
}
// ---- controls ----
const search=document.getElementById('search');
search.addEventListener('input',runSearch);
function runSearch(){
const q=search.value.trim().toLowerCase();
if(btnInv.classList.contains('active'))toggleInverted(false);
selected=null;
if(!q){clearFocus();renderInspectorHint();return;}
const matches=new Set(nodes.filter(n=>!n.hidden&&n.id.toLowerCase().includes(q)).map(n=>n.id));
edges.forEach(e=>{setEdge(e,false);
if(!e.s.hidden&&!e.t.hidden)e.el.style.strokeOpacity=(matches.has(e.s.id)&&matches.has(e.t.id))?'0.7':'0.03';});
edges.forEach(e=>{if(matches.has(e.s.id)&&matches.has(e.t.id))setEdge(e,true);});
if(matches.size)dimAll(matches);else clearFocus();
}
function recomputeHidden(){
const showF=togF.classList.contains('on'),showD=togD.classList.contains('on'),showData=togData.classList.contains('on');
const hideHubs=togHubs.classList.contains('on'),apiOnly=togApi.classList.contains('on');
for(const n of nodes){let h=false;
if(n.layer==='features'&&!showF)h=true;
if(n.layer==='domain'&&!showD)h=true;
if(n.layer==='data'&&!showData)h=true;
if(hideHubs&&HUBS.has(n.id))h=true;
n.hidden=h;n.gEl.style.display=h?'none':'';}
for(const e of edges){let h=e.s.hidden||e.t.hidden;if(apiOnly&&!e.api)h=true;
e.el.style.display=h?'none':'';}
if(selected&&!byId.get(selected).hidden)focusNode(selected);
else{selected=null;if(search.value.trim())runSearch();else clearFocus();}
reheat(0.15);
}
function bindTog(el){el.addEventListener('click',()=>{el.classList.toggle('on');recomputeHidden();});}
const togF=document.querySelector('.tog[data-layer="features"]');
const togD=document.querySelector('.tog[data-layer="domain"]');
const togData=document.querySelector('.tog[data-layer="data"]');
const togHubs=document.getElementById('togHubs');
const togApi=document.getElementById('togApi');
[togF,togD,togData,togHubs,togApi].forEach(bindTog);
// team toggles (built from TEAMS config)
const teamList=document.getElementById('teamList');
const togCluster=document.getElementById('togCluster');
TEAMS.forEach(t=>{
const el=document.createElement('label');el.className='tog';el.dataset.team=t.id;
el.innerHTML=`<span class="box"></span><span class="dot" style="background:${t.color}"></span>${t.name}<span class="meta" id="teamCnt_${t.id}"></span>`;
el.addEventListener('click',()=>{el.classList.toggle('on');syncTeams();});
teamList.appendChild(el);
});
function syncTeams(){
enabledTeams.clear();
teamList.querySelectorAll('.tog.on').forEach(el=>enabledTeams.add(el.dataset.team));
setClusterMembership();updateHalos();reheat(0.35);render();
}
togCluster.addEventListener('click',()=>{
togCluster.classList.toggle('on');clusterOn=togCluster.classList.contains('on');
setClusterMembership();reheat(0.45);render();
});
const btnInv=document.getElementById('btnInv');
function toggleInverted(force){
const on=force!==undefined?force:!btnInv.classList.contains('active');
btnInv.classList.toggle('active',on);
if(!on){selected=null;clearFocus();renderInspectorHint();return;}
selected=null;search.value='';
const invE=edges.filter(e=>e.inv&&!e.s.hidden&&!e.t.hidden);
const bright=new Set();invE.forEach(e=>{bright.add(e.s.id);bright.add(e.t.id);});
edges.forEach(e=>{setEdge(e,false);if(!e.s.hidden&&!e.t.hidden)e.el.style.strokeOpacity='0.025';});
invE.forEach(e=>setEdge(e,true));dimAll(bright);
insp.innerHTML='<div class="insp-id" style="color:var(--inverted)">inverted deps</div>'+
'<p class="hint" style="margin-top:10px">Edges where a lower-layer <b style="color:var(--domain)">domain</b> or <b style="color:var(--data)">data</b> module imports a <b style="color:var(--features)">feature</b> <code>api</code> — the dependency arrow points the "wrong" way across the layer boundary.</p>';
const ul=document.createElement('ul');ul.style.cssText='list-style:none;padding:0;margin:12px 0 0;display:flex;flex-direction:column;gap:1px';
invE.sort((a,b)=>a.s.id.localeCompare(b.s.id)).forEach(e=>{
const li=document.createElement('li');
li.style.cssText='font-family:var(--mono);font-size:11px;padding:5px 7px;border-radius:5px;color:var(--inverted);cursor:pointer;word-break:break-all';
li.textContent=`${e.s.id} → ${e.t.id}`;
li.addEventListener('click',ev=>{ev.stopPropagation();toggleInverted(false);selectNode(e.s.id);});
li.addEventListener('mouseenter',()=>li.style.background='var(--panel-2)');
li.addEventListener('mouseleave',()=>li.style.background='');
ul.appendChild(li);});
insp.appendChild(ul);
}
btnInv.addEventListener('click',()=>toggleInverted());
// ---- header / hub text ----
function updateChrome(){
document.getElementById('statNodes').textContent=nodes.length;
document.getElementById('statNodesLbl').textContent=VIEWCFG[CURRENT].kind;
document.getElementById('statEdges').textContent=edges.length;
document.getElementById('invCount').textContent=edges.filter(e=>e.inv).length;
document.getElementById('cntF').textContent=nodes.filter(n=>n.layer==='features').length;
document.getElementById('cntD').textContent=nodes.filter(n=>n.layer==='domain').length;
const nData=nodes.filter(n=>n.layer==='data').length, hasData=nData>0;
document.getElementById('cntData').textContent=nData;
document.getElementById('togDataRow').style.display=hasData?'':'none';
document.getElementById('legendData').style.display=hasData?'':'none';
document.getElementById('hubCount').textContent=HUBS.size;
document.getElementById('hubList').textContent=[...HUBS].map(id=>byId.get(id).label).join(', ');
TEAMS.forEach(t=>{const el=document.getElementById('teamCnt_'+t.id);
if(el)el.textContent=nodes.filter(n=>n.teams.includes(t)).length;});
document.getElementById('statEdgesLbl').textContent=CURRENT==='screens'?'nav links':'dep links';
if(CURRENT==='screens'&&groupListBuilt)Object.keys(GROUP_LABELS).forEach(g=>{
const el=document.getElementById('grpCnt_'+g);if(el)el.textContent=nodes.filter(n=>n.layer===g).length;});
}
// ---- screens-view chrome ----
let groupListBuilt=false;
function buildGroupList(){
groupListBuilt=true;const gl=document.getElementById('groupList');gl.innerHTML='';
Object.keys(GROUP_LABELS).forEach(g=>{
const el=document.createElement('label');el.className='tog';el.dataset.group=g;
el.innerHTML=`<span style="background:${GROUP_COLORS[g]};width:10px;height:10px;border-radius:50%;flex:0 0 auto;display:inline-block"></span>${GROUP_LABELS[g]}<span class="meta" id="grpCnt_${g}"></span>`;
el.addEventListener('click',()=>{
const was=el.classList.contains('act');
gl.querySelectorAll('.tog').forEach(x=>x.classList.remove('act'));
if(was)clearFocus();else{el.classList.add('act');isolateGroup(g);}
});
gl.appendChild(el);
});
}
function isolateGroup(g){
selected=null;
const set=new Set(nodes.filter(n=>!n.hidden&&n.layer===g).map(n=>n.id));
const bright=new Set(set);
edges.forEach(e=>{if(set.has(e.s.id))bright.add(e.t.id);if(set.has(e.t.id))bright.add(e.s.id);});
edges.forEach(e=>{setEdge(e,false);if(!e.s.hidden&&!e.t.hidden)e.el.style.strokeOpacity='0.02';});
edges.forEach(e=>{if(set.has(e.s.id)||set.has(e.t.id))setEdge(e,true);});
dimAll(bright);
}
function applyViewChrome(name){
const isS=name==='screens';
['grpLayers','grpDeclutter','grpLayering'].forEach(id=>document.getElementById(id).style.display=isS?'none':'');
document.getElementById('grpGroups').style.display=isS?'':'none';
document.getElementById('legendBox').style.display=isS?'none':'';
document.querySelector('.stat.warn').style.display=isS?'none':'';
document.getElementById('eyebrowKind').textContent=isS?'AppRoute navigation map':'gradle dependency graph';
document.getElementById('hud').innerHTML=isS
?'screens grouped by function<br>arrow = navigates to<br><b>scroll</b> zoom · <b>drag</b> pan'
:'consumers <span style="color:var(--features)">left</span> · foundations <span style="color:var(--domain)">right</span><br>arrow points to the dependency<br><b>scroll</b> zoom · <b>drag</b> pan';
if(isS&&!groupListBuilt)buildGroupList();
if(groupListBuilt)document.getElementById('groupList').querySelectorAll('.tog').forEach(x=>x.classList.remove('act'));
}
// ---- view switch ----
function loadView(name){
if(raf){cancelAnimationFrame(raf);raf=null;}
CURRENT=name;selected=null;search.value='';
btnInv.classList.remove('active');
applyViewChrome(name);
view={k:1,x:0,y:0};applyView();
buildModel(name);setClusterMembership();initLayout();buildDOM();updateHalos();updateChrome();
recomputeHidden();render();applyBaseLabels();
if(!reduced){alpha=0.16;raf=requestAnimationFrame(animate);}
}
const vs=document.getElementById('viewswitch');
vs.addEventListener('click',ev=>{const b=ev.target.closest('button');if(!b)return;
[...vs.children].forEach(x=>x.classList.toggle('on',x===b));
loadView(b.dataset.view);});
loadView('area');
</script>

View file

@ -0,0 +1,277 @@
#!/usr/bin/env python3
"""
build_graph.py scan the live codebase and refresh the managed regions of
.claude/docs/navigation-graph.md (the source of truth for module-connectivity.html).
What it extracts from code:
- features/domain/data Gradle project dependencies -> area graph + module graph
- AppRoute screens + every `AppRoute.X` reference -> screen navigation graph
What it preserves:
- all hand-written prose ABOVE the <!-- NAVGRAPH:BEGIN --> marker
- the curated CONFIG block (groups / owners / teams) inside the managed region
Run from anywhere inside the repo: python3 build_graph.py
Then render the HTML: python3 render_html.py
"""
import os, re, json, sys
from collections import defaultdict
# ---------------------------------------------------------------- paths
def find_root(start):
d = os.path.abspath(start)
while d != os.path.dirname(d):
if os.path.exists(os.path.join(d, "settings.gradle.kts")):
return d
d = os.path.dirname(d)
sys.exit("ERROR: could not locate repo root (settings.gradle.kts not found).")
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT = find_root(os.getcwd())
SKILL = os.path.dirname(SCRIPT_DIR)
DOCS = os.path.join(ROOT, ".claude", "docs")
MD = os.path.join(DOCS, "navigation-graph.md")
SEED = os.path.join(SKILL, "assets", "config.seed.json")
APPROUTE = os.path.join(ROOT, "common/routing/src/main/kotlin/com/tangem/common/routing/AppRoute.kt")
# ---------------------------------------------------------------- managed-region helpers
BEGIN = "<!-- NAVGRAPH:BEGIN — managed by the navigation-graph skill. Edit only the CONFIG json; the rest is generated from code. -->"
END = "<!-- NAVGRAPH:END -->"
def block(text, key):
"""Return the JSON string inside the <!-- NAVGRAPH:key:BEGIN/END --> markers, or None."""
m = re.search(r"<!-- NAVGRAPH:%s:BEGIN -->\s*```json\s*(.*?)\s*```\s*<!-- NAVGRAPH:%s:END -->"
% (re.escape(key), re.escape(key)), text, re.S)
return m.group(1) if m else None
def wrap(key, payload):
return f"<!-- NAVGRAPH:{key}:BEGIN -->\n```json\n{payload}\n```\n<!-- NAVGRAPH:{key}:END -->"
# ---------------------------------------------------------------- gradle dependency scan
def camel_to_kebab(s): return re.sub(r'(?<!^)(?=[A-Z])', '-', s).lower()
def accessor_to_path(acc): return ':' + ':'.join(camel_to_kebab(p) for p in acc.split('.'))
def dir_to_path(d): return ':' + os.path.relpath(d, ROOT).replace(os.sep, ':')
PROJ_RE = re.compile(r'(api|implementation|testImplementation|androidTestImplementation|'
r'compileOnly|kapt|ksp|debugImplementation)\s*\(\s*projects\.([A-Za-z0-9_.]+)\s*\)')
def scan_modules():
modules = {}
edges = []
for dp, _, fns in os.walk(ROOT):
if '/build/' in dp or '/.git' in dp or '/.gradle' in dp: continue
if 'build.gradle.kts' not in fns: continue
if dp == ROOT: continue
modules[dir_to_path(dp)] = dp
for path, dp in modules.items():
txt = open(os.path.join(dp, 'build.gradle.kts'), encoding='utf-8', errors='ignore').read()
for m in PROJ_RE.finditer(txt):
edges.append((path, accessor_to_path(m.group(2)), m.group(1)))
return modules, edges
SCOPED_LAYERS = ('features', 'domain', 'data')
def is_scoped(m): return any(m.startswith(':' + layer) for layer in SCOPED_LAYERS)
def area_of(m):
p = m.split(':')[1:]
return f"{p[0]}:{p[1]}" if len(p) > 1 and p[0] in SCOPED_LAYERS else None
def build_area_graph(modules, edges):
agg = defaultdict(lambda: {"w": 0, "api": False})
for s, d, c in edges:
if not (is_scoped(s) and is_scoped(d)): continue
sa, da = area_of(s), area_of(d)
if not sa or not da or sa == da: continue
agg[(sa, da)]["w"] += 1
if c == 'api': agg[(sa, da)]["api"] = True
indeg, outdeg = defaultdict(int), defaultdict(int)
for (s, d) in agg: outdeg[s] += 1; indeg[d] += 1
nodes = sorted({n for e in agg for n in e})
N = [[n, n.split(':')[1], n.split(':')[0], indeg[n], outdeg[n]] for n in nodes]
E = [[s, d, v["w"], 1 if v["api"] else 0] for (s, d), v in agg.items()]
return {"n": N, "e": E}
def build_module_graph(modules, edges):
agg = defaultdict(lambda: {"w": 0, "api": False})
for s, d, c in edges:
if not (is_scoped(s) and is_scoped(d)) or s == d: continue
agg[(s, d)]["w"] += 1
if c == 'api': agg[(s, d)]["api"] = True
indeg, outdeg = defaultdict(int), defaultdict(int)
for (s, d) in agg: outdeg[s] += 1; indeg[d] += 1
conn = {n for e in agg for n in e}
N = [[m, ':'.join(m.split(':')[2:]), m.split(':')[1], indeg[m], outdeg[m]]
for m in sorted(conn)]
E = [[s, d, v["w"], 1 if v["api"] else 0] for (s, d), v in agg.items()]
return {"n": N, "e": E}
# ---------------------------------------------------------------- AppRoute scan
REF_RE = re.compile(r'AppRoute\.([A-Z][A-Za-z0-9]+)')
DECL_RE = re.compile(r'^ (?:data )?(?:object|class) (\w+)', re.M)
def read_kotlin_string(text, i):
"""text[i] must be '"'. Return (content, index_after_closing_quote), handling \\"
escapes and ${...} template expressions (nested braces/strings copied verbatim) so a
path with string templates isn't truncated at the first inner quote."""
out, j = [], i + 1
while j < len(text):
c = text[j]
if c == '\\':
out.append(text[j:j + 2]); j += 2; continue
if c == '"':
return ''.join(out), j + 1
if c == '$' and j + 1 < len(text) and text[j + 1] == '{':
out.append('${'); j += 2; depth = 1
while j < len(text) and depth > 0:
ck = text[j]
if ck == '"':
s, j = read_kotlin_string(text, j); out.append('"' + s + '"'); continue
if ck == '{': depth += 1
elif ck == '}': depth -= 1
if depth > 0: out.append(ck)
j += 1
out.append('}'); continue
out.append(c); j += 1
return ''.join(out), j
def extract_path(block):
"""First string literal of the `path = …` argument within one screen's source block.
Block-scoped (so multi-line `AppRoute(` blocks resolve) and template-aware (so paths
aren't truncated); for a non-literal RHS (e.g. `path = when {…}`) it takes the first
branch literal. Returns None when the block has no `path =`."""
m = re.search(r'\bpath\s*=\s*', block)
if not m: return None
i = m.end()
while i < len(block) and block[i] in ' \t\r\n': i += 1
if i < len(block) and block[i] == '"':
return read_kotlin_string(block, i)[0]
q = block.find('"', i)
return read_kotlin_string(block, q)[0] if q != -1 else None
def scan_routes():
src = open(APPROUTE, encoding='utf-8').read()
decls = [(m.group(1), m.start()) for m in DECL_RE.finditer(src)]
screens = {name for name, _ in decls}
paths = {}
for idx, (name, start) in enumerate(decls):
end = decls[idx + 1][1] if idx + 1 < len(decls) else len(src)
p = extract_path(src[start:end])
if p is not None: paths.setdefault(name, p)
usage = defaultdict(lambda: defaultdict(int))
nav = defaultdict(int)
def area(fp):
parts = os.path.relpath(fp, ROOT).split(os.sep)
top = parts[0]
return f"{top}:{parts[1]}" if top in ('features','domain','data','core','common','libs') and len(parts) > 1 else top
for dp, _, fns in os.walk(ROOT):
if '/build/' in dp or '/.git' in dp or '/.gradle' in dp: continue
for fn in fns:
if not fn.endswith('.kt'): continue
fp = os.path.join(dp, fn)
if os.path.samefile(fp, APPROUTE) if os.path.exists(APPROUTE) else False: continue
try: txt = open(fp, encoding='utf-8', errors='ignore').read()
except Exception: continue
if 'AppRoute.' not in txt: continue
a = area(fp)
for m in REF_RE.finditer(txt):
if m.group(1) in screens: usage[m.group(1)][a] += 1
for nm in re.finditer(r'\b(push|replaceCurrent|replaceAll|popTo)\s*\(', txt):
r2 = REF_RE.search(txt[nm.end():nm.end()+160])
if r2 and r2.group(1) in screens: nav[(a, r2.group(1))] += 1
return screens, paths, usage, nav
def build_screen_graph(screens, paths, usage, nav, cfg):
total = {s: sum(usage[s].values()) for s in screens}
sg, so = cfg["screenGroups"], cfg["screenOwners"]
owned = defaultdict(list)
for s in sorted(screens): owned[so.get(s, cfg["defaultOwner"])].append(s)
def fnorm(a): return a.split(':')[-1].replace('-', '').lower()
def main_of(a, ss):
epon = [s for s in ss if s.lower() == fnorm(a)]
return epon[0] if epon else max(ss, key=lambda x: (total[x], x)) # deterministic tie-break
main = {a: main_of(a, ss) for a, ss in owned.items()}
APPSHELL = 'AppShell'
edge = defaultdict(int)
for (a, t), c in nav.items():
src = main.get(a, APPSHELL)
if src == t: continue
edge[(src, t)] += c
use_shell = any(s == APPSHELL for s, _ in edge)
indeg, outdeg = defaultdict(int), defaultdict(int)
for (s, t) in edge: outdeg[s] += 1; indeg[t] += 1
N = [[s, s, sg.get(s, cfg["defaultGroup"]), indeg[s], outdeg[s]] for s in sorted(screens)]
if use_shell: N.append([APPSHELL, 'App shell', 'shell', indeg[APPSHELL], outdeg[APPSHELL]])
E = [[s, t, w, 0] for (s, t), w in edge.items()]
meta = {}
for s in sorted(screens):
meta[s] = {"path": paths.get(s, ""), "owner": so.get(s, cfg["defaultOwner"]),
"group": sg.get(s, cfg["defaultGroup"]), "total": total[s],
"refs": sorted(usage[s].items(), key=lambda kv: -kv[1])}
return {"n": N, "e": E}, meta
# ---------------------------------------------------------------- main
def main():
if not os.path.exists(APPROUTE):
sys.exit(f"ERROR: AppRoute.kt not found at {APPROUTE}")
old = open(MD, encoding='utf-8').read() if os.path.exists(MD) else ""
# config: prefer the one already in the doc (human edits win), else seed
cfg_str = block(old, "config")
cfg = json.loads(cfg_str) if cfg_str else json.load(open(SEED))
modules, dep_edges = scan_modules()
area_g = build_area_graph(modules, dep_edges)
mod_g = build_module_graph(modules, dep_edges)
screens, paths, usage, nav = scan_routes()
# reconcile config with the screens actually present in code
warns = []
for s in sorted(screens):
if s not in cfg["screenGroups"]:
cfg["screenGroups"][s] = cfg["defaultGroup"]; warns.append(f"NEW screen '{s}': group defaulted to '{cfg['defaultGroup']}' — set it in CONFIG")
if s not in cfg["screenOwners"]:
cfg["screenOwners"][s] = cfg["defaultOwner"]; warns.append(f"NEW screen '{s}': owner defaulted to '{cfg['defaultOwner']}' — set it in CONFIG")
stale = [s for s in cfg["screenGroups"] if s not in screens]
screen_g, screen_meta = build_screen_graph(screens, paths, usage, nav, cfg)
inv_area = sum(1 for s, t, w, a in area_g["e"] if t.startswith('features:') and not s.startswith('features:'))
cj = lambda o: json.dumps(o, separators=(',', ':'))
summary = (
f"_Auto-generated from code by the `navigation-graph` skill. Edit only the CONFIG block below._\n\n"
f"- **Screens (AppRoute):** {len(screens)} · screen-nav edges {len(screen_g['e'])}\n"
f"- **Area graph:** {len(area_g['n'])} feature/domain/data areas · {len(area_g['e'])} dependency edges · {inv_area} inverted (domain/data→features)\n"
f"- **Module graph:** {len(mod_g['n'])} modules · {len(mod_g['e'])} edges\n"
)
if warns: summary += "\n**Action needed:**\n" + "\n".join(f"- {w}" for w in warns) + "\n"
if stale: summary += f"\n_Config has {len(stale)} screen(s) no longer in code (kept, harmless): {', '.join(stale)}_\n"
managed = "\n\n".join([
BEGIN,
"## Connectivity data (generated)\n\n" + summary,
"### Curated config (editable — preserved across refreshes)\n\n" + wrap("config", json.dumps(cfg, indent=2)),
"### Graph data (auto — overwritten every refresh; do not hand-edit)\n\n" +
wrap("areaGraph", cj(area_g)) + "\n\n" + wrap("moduleGraph", cj(mod_g)) + "\n\n" +
wrap("screensGraph", cj(screen_g)) + "\n\n" + wrap("screensMeta", cj(screen_meta)),
END,
])
if BEGIN in old and END in old:
head = old[:old.index(BEGIN)].rstrip() + "\n\n"
tail = old[old.index(END) + len(END):]
new = head + managed + tail
elif old.strip():
new = old.rstrip() + "\n\n" + managed + "\n"
else:
new = "# Navigation Graph\n\n" + managed + "\n"
os.makedirs(DOCS, exist_ok=True)
open(MD, "w", encoding='utf-8').write(new)
print(f"✓ updated {os.path.relpath(MD, ROOT)}")
print(f" screens={len(screens)} screen-edges={len(screen_g['e'])} | "
f"areas={len(area_g['n'])}/{len(area_g['e'])} | modules={len(mod_g['n'])}/{len(mod_g['e'])}")
for w in warns: print("" + w)
print("Next: python3 " + os.path.join(SCRIPT_DIR, "render_html.py"))
if __name__ == "__main__":
main()

View file

@ -0,0 +1,73 @@
#!/usr/bin/env python3
"""
render_html.py build .claude/docs/module-connectivity.html from the data blocks
in .claude/docs/navigation-graph.md (which build_graph.py refreshes from code).
Run AFTER build_graph.py: python3 render_html.py
"""
import os, re, json, sys
def find_root(start):
d = os.path.abspath(start)
while d != os.path.dirname(d):
if os.path.exists(os.path.join(d, "settings.gradle.kts")):
return d
d = os.path.dirname(d)
sys.exit("ERROR: could not locate repo root (settings.gradle.kts not found).")
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT = find_root(os.getcwd())
SKILL = os.path.dirname(SCRIPT_DIR)
MD = os.path.join(ROOT, ".claude", "docs", "navigation-graph.md")
TEMPLATE = os.path.join(SKILL, "assets", "template.html")
OUT = os.path.join(ROOT, ".claude", "docs", "module-connectivity.html")
def block(text, key):
m = re.search(r"<!-- NAVGRAPH:%s:BEGIN -->\s*```json\s*(.*?)\s*```\s*<!-- NAVGRAPH:%s:END -->"
% (re.escape(key), re.escape(key)), text, re.S)
if not m:
sys.exit(f"ERROR: data block '{key}' not found in {MD}. Run build_graph.py first.")
return json.loads(m.group(1))
def main():
if not os.path.exists(MD): sys.exit(f"ERROR: {MD} not found. Run build_graph.py first.")
if not os.path.exists(TEMPLATE): sys.exit(f"ERROR: template missing at {TEMPLATE}")
text = open(MD, encoding='utf-8').read()
cfg = block(text, "config")
area = block(text, "areaGraph")
mod = block(text, "moduleGraph")
screens = block(text, "screensGraph")
smeta = block(text, "screensMeta")
groups = cfg["groups"]
group_colors = {g: groups[g]["color"] for g in groups}
group_labels = {g: groups[g]["label"] for g in groups}
group_anchors = {g: groups[g]["anchor"] for g in groups}
cj = lambda o: json.dumps(o, separators=(',', ':'))
tpl = open(TEMPLATE, encoding='utf-8').read()
repl = {
"/*__AREA_DATA__*/null": cj(area),
"/*__MODULE_DATA__*/null": cj(mod),
"/*__SCREENS_DATA__*/null": cj(screens),
"/*__SCREENS_META__*/null": cj(smeta),
"/*__TEAMS__*/[]": cj(cfg["teams"]),
"/*__GROUP_COLORS__*/{}": cj(group_colors),
"/*__GROUP_LABELS__*/{}": cj(group_labels),
"/*__GROUP_ANCHORS__*/{}": cj(group_anchors),
}
out = tpl
for k, v in repl.items():
if k not in out: sys.exit(f"ERROR: placeholder '{k}' missing in template — template/skill version mismatch.")
out = out.replace(k, v)
for ph in ("__AREA_DATA__", "__MODULE_DATA__", "__SCREENS_DATA__", "__SCREENS_META__",
"__TEAMS__", "__GROUP_COLORS__", "__GROUP_LABELS__", "__GROUP_ANCHORS__"):
if "/*" + ph + "*/" in out: sys.exit(f"ERROR: placeholder {ph} left unreplaced.")
open(OUT, "w", encoding='utf-8').write(out)
print(f"✓ wrote {os.path.relpath(OUT, ROOT)} ({len(out)//1024} KB, self-contained)")
print(f" area {len(area['n'])}n/{len(area['e'])}e · module {len(mod['n'])}n/{len(mod['e'])}e · "
f"screens {len(screens['n'])}n/{len(screens['e'])}e · teams {len(cfg['teams'])}")
print(f" open: {OUT}")
if __name__ == "__main__":
main()

View file

@ -32,6 +32,34 @@ different setup.
5. **Write the test** per Conventions below.
6. **Build BOTH APKs, install, run, and classify the result** correctly — Allure post-run hook
failures are not test failures (see `reference/running-and-debugging.md`).
7. **Final cleanup pass — remove what you no longer use.** Before declaring done, review every file you
touched for leftovers from iteration (see "Final cleanup" below). This is a required step, not optional.
## Final cleanup (required before done)
Iterating on a test typically leaves dead code behind — an import for a helper you swapped out, an
`@OptIn` for an API you stopped calling directly, a matcher you replaced. Reviewers flag these, and a
stray `@OptIn` reads as "this code needs an experimental API" when it doesn't. For **every file you
added or edited** (production `testTag` files included), check and remove:
- **Unused imports.** Any leftover after swapping an approach (e.g. `performTextReplacement`
`performTextInputInChunks`, `onDialog` after extracting a scenario). Diff-check each import against
the body: `for f in <changed .kt>; do grep '^import' "$f" | while read -r i; do n=${i##*.}; n=${n%% *};
grep -q "\b$n\b" <(grep -v '^import' "$f") || echo "$f: unused? $i"; done; done`
(heuristic — `foundation.layout.*` wildcards and `getValue`/`setValue` used only by `by` delegates
are false positives; verify before deleting).
- **Redundant `@OptIn(ExperimentalTestApi::class)`.** Needed **only** where you call an experimental
API *directly* (`performScrollToNode`, `waitUntilAtLeastOneExists`, `waitUntilDoesNotExist`, …).
It is **not** needed just to call your own helper that is already annotated (e.g. a page-object
`scrollToNetwork` that wraps `performScrollToNode`), nor for the stable `composeTestRule.waitUntil(timeoutMillis, condition)`.
A `BaseTestCase`-extension scenario that only calls annotated page-object methods + stable `waitUntil`
needs no `@OptIn` — drop it (and its `import androidx.compose.ui.test.ExperimentalTestApi`).
- **Dead vals / matchers / page-object members** you introduced and then stopped referencing.
Then recompile the changed module(s) to confirm the removals are valid — the androidTest APK
(`:app:assembleGoogleMockedAndroidTest`) for test-side edits, or the touched production module
(e.g. `:core:ui:compileDebugKotlin`) for `testTag` edits. A clean compile with no opt-in / unused-symbol
warnings is the pass criterion. Behavior-only-neutral cleanups don't need a re-run of the suite.
## Porting a test from iOS
@ -101,6 +129,47 @@ When the user asks to **port** an iOS test to Android:
Scenario files orchestrate flows; they must not define page objects or duplicate generic helpers.
### Page-object matchers: exhaust the native Kakao API before dropping to raw Compose
**Reviewers reject raw `composeTestRule` / `semanticsProvider.onNode(...)` / `onAllNodes(...)[i]` and
deep nested matchers when a native Kakao-Compose mechanism does the same thing.** Before writing any
such construct, look for the built-in KNode / `ViewBuilder` / `KLazyListNode` API — it almost always
exists. The raw form is a last resort, and even then it stays **inside the page object**, never in the
test body (the test only calls page-object members and scenarios — no `composeTestRule`, no test tags,
no `onNode`/`onAllNodes`, no bare matchers leak into it).
Native first, by need:
- **N-th of several identical nodes**`child { … ; hasPosition(index) }` (Kakao maps
`NodeMatcher.position``onAllNodes(matcher)[index]` for you). Do **not** hand-roll
`semanticsProvider.onAllNodes(matcher)[index]`.
- **Scroll to index / matcher / key** → inside a KNode block: `knode { performScrollToIndex(index) }`,
`knode { performScrollToNode(matcher) }`, `knode { performScrollToKey(key) }` (mirror
`MarketsPageObject.scrollToListedOnBlock`). These wrappers are `@ExperimentalTestApi`, so annotate the
page-object method `@OptIn(ExperimentalTestApi::class)` — that opt-in is expected, not a smell.
- **Relationship filters**`ViewBuilder` DSL inside `child { }`: `hasAnyChild`, `hasAnySibling`,
`hasAnyAncestor`, `hasAnyDescendant`, `addSemanticsMatcher(matcher)`, `useUnmergedTree = true`.
- **Lazy list / pager item (esp. below the fold)**`KLazyListNode` + `childWith { … }` / `childAt(index)`
(see `AddFundsBottomSheetPageObject`, `BuyTokenPageObject`), not a manual scroll + `onAllNodes`.
- **A raw Compose-Test op with no KNode wrapper** (e.g. `captureToImage()`, and any other
`SemanticsNodeInteraction` extension Kakao doesn't surface) → do **not** fall back to
`composeTestRule.onNode(hasTestTag(...))` in the scenario. Every KNode exposes a public `delegate`, and
the built-in actions/assertions are all just `delegate.perform(type) { <this: SemanticsNodeInteraction> }`
/ `delegate.check(type) { … }`. `ComposeOperationType` is an open interface, so declare a tiny private
`enum class Xxx : ComposeOperationType { … }` and reach the underlying `SemanticsNodeInteraction` from a
**page-object method** — reusing an existing KNode (its testTag + `useUnmergedTree`). Capture a return
value via a `lateinit var` written inside the lambda. Example (`TokenReceiveQrCodeBottomSheetPageObject.captureQrCodeBitmap`):
```kotlin
fun captureQrCodeBitmap(): Bitmap {
lateinit var bitmap: Bitmap
qrCode.delegate.perform(QrCodeAction.CAPTURE) { bitmap = captureToImage().asAndroidBitmap() }
return bitmap
}
private enum class QrCodeAction : ComposeOperationType { CAPTURE }
```
This keeps `composeTestRule` / test tags out of the scenario — the scenario just calls the page-object method.
- **Only if truly nothing fits**`semanticsProvider.onNode(...)` / `onAllNodes(...)` (the escape hatch
used by `MainScreenPageObject`), wrapped in a named page-object method with a one-line WHY comment.
### Strings
- **No hardcoded UI text** in matchers. Use `getResourceString(R.string.foo)` from
@ -136,9 +205,19 @@ Scenario files orchestrate flows; they must not define page objects or duplicate
that a screen "never idles", **cold-boot a fresh emulator** (`emulator -avd … -no-snapshot -wipe-data
-memory 4096 -cores 2`) and re-run. A suite that flaked across runs on a tired emulator can be a clean
10/10 on a fresh one (verified on this exact suite). Don't rewrite waits to work around emulator rot.
- **In scenario / `BaseTestCase`-extension code, `flakySafely` is NOT available** regardless — use the
same `composeTestRule.waitUntil` fallback (or `waitUntilAtLeastOneExists(matcher, timeout)` to wait for
appearance, `{ a exists || b exists }` for either/or).
- **In scenario / `BaseTestCase`-extension code, `flakySafely` is NOT available** regardless — use
`BaseTestCase.awaitSuccess(timeoutMillis = WAIT_UNTIL_TIMEOUT) { … }` (a shared member on `BaseTestCase`,
no import needed) which wraps `composeTestRule.waitUntil { runCatching(block).isSuccess }`. Each async step
reads `awaitSuccess { onXxxScreen { field.assertExists() } }` before the action. For appearance-only waits
`composeTestRule.waitUntilAtLeastOneExists(matcher, timeout)` (or `{ a exists || b exists }` for either/or)
is also fine.
**Do not re-declare a private `awaitSuccess` in a scenario file** — the shared `BaseTestCase.awaitSuccess`
already exists; older files may still have a private copy, don't copy that pattern.
- **Right-size the timeout — don't stamp `WAIT_UNTIL_TIMEOUT_LONG` on every step.** The timeout is a
*ceiling*, not a sleep (`waitUntil` returns the moment the condition holds), but the default
`WAIT_UNTIL_TIMEOUT` (20 s) already dwarfs a normal async transition. Reserve `…_LONG` / `…_VERY_LONG`
for steps that are genuinely slow (a real network round-trip + debounce that can approach 20 s);
using LONG uniformly is lazy and hides which step is actually the slow one.
### Comment hygiene
@ -157,4 +236,8 @@ Delete anything explaining WHAT a step does.
- **`reference/running-and-debugging.md`** — read when building, installing, running tests (orchestrator
vs. raw `am instrument`), running against a local WireMock, interpreting CLI/Allure output, using
`@Ignore`, or driving WireMock scenarios. Includes how to find app-side root causes when the UI fails
silently (the app log in `files/log.txt`, and the WireMock journal).
silently (the app log in `files/log.txt`, and the WireMock journal).
- **`reference/yield-mode.md`** — read before writing any **Yield Mode (yield-supply / "Earning")** test.
Covers the hot-wallet activation flow, why Ethereum (not Polygon — gasless), the full mock set +
scenarios, the `isActive`-semantics / lowercase-address / hold-timing / Pill-testTag gotchas, and the
production testTags already added. Mirror `tests/yield/YieldModeTest.kt`.

View file

@ -0,0 +1,96 @@
# Yield Mode (yield-supply) UI tests
Hard-won specifics for testing the Yield Mode feature (`features/yield-supply`, analytics category
"Earning"). The first test (`app/.../tests/yield/YieldModeTest.kt`, case #4938 "first-time landing
activation") is the reference — mirror it. Read this before writing any yield test.
## What the feature is
Depositing a stablecoin (USDC/USDT) into a DeFi protocol (Aave) from the app to earn APY. Distinct from
Staking (`domain/staking`) but both render the shared `EarnBlock` (`common/ui/.../earn/`) on token
details. Activation = a **real signed transaction** (approve + enter), so it needs a **hot wallet**
(mock card can't sign). Use `openMainScreenWithExistingHotWallet(SVS_SEED_PHRASE_12)`.
## Network: use Ethereum, NOT Polygon
- **Ethereum USDC** activation is a **native ETH** transaction → the standard send path works.
- **Polygon USDC** activation routes through the **gasless** flow (`GASLESS_APPROVAL_ENABLED=true` +
Polygon USDC is gasless-eligible) → `gaslessTransaction()`; the SDK's `EthereumTransactionValidator`
throws `FailedToSendException` synchronously and the send never completes. Avoid Polygon for yield
send/activation tests unless you specifically mock the whole gasless-v2 stack.
- Wallet (SVS_SEED_PHRASE_12) EVM address: `0x3369554b994908d249d307b105f8e5e3115615c2`.
- Ethereum USDC contract: `0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48` (chainId 1, decimals 6).
## Running (same as the general doc, repeated because it bit us)
Run **via the orchestrator**, never raw `am instrument` (with `am instrument` the fresh-wallet portfolio
silently never loads):
```bash
curl -s -X POST http://localhost:8081/__admin/mappings/reset # after editing mocks
./gradlew :app:connectedGoogleMockedAndroidTest \
-Pandroid.testInstrumentationRunnerArguments.class=com.tangem.tests.yield.YieldModeTest \
-Pandroid.testInstrumentationRunnerArguments.wiremockBaseUrl=http://10.0.2.2:8081
```
WireMock on 8081 is a docker container bind-mounting the `tangem-api-mocks` working tree — `mappings/reset`
reloads from disk, no rebuild. App-side logs (`TangemLogger`) also reach logcat; the failure semantics
tree is dumped to logcat (`ComposeTree`).
## Mock set (in tangem-api-mocks, branch `feature/AND-16082_yield_mode_mocks`)
- **Yield API** (`mappings/yield-api/api/v1/`): `yield/markets`, `yield/token/1/{usdc}` (+ `/chart`),
`module/activate`, `module/deactivate`. Base URL is `wiremock.tests-d.com` (see infra fix below) so the
path is `/api/v1/yield/...`.
- **On-chain eth_call** (`mappings/providers/ethereum/eth-call-yield.json`, priority 1 to beat the generic
`eth-call.json`): factory `getModule` (to=`0xd8972a45...`), processor service-fee (to=`0x4ff6178b...`),
yield status `0xf8e8be9c` + balances `0x16a398f7`/`0x5002bb7e` (to = module `0x1111…`), allowance
`0xdd62ed3e` (to = USDC) → 0. Status/balances gated by scenario `yield_supply_status` (NotActive=zeros,
Active=`…01`,`…01`,`…8ac7230489e80000`).
- **History** (`mappings/eth-blockbook.nownodes.io/`): NowNodes BlockBook v2. Ethereum mainnet tx history
is **NowNodes eth-blockbook**, NOT Etherscan and NOT `/v2/transaction-events` (the latter is a
push-dedup POST). The host is redirected by the interceptor (infra fix below).
- **Portfolio**: scenario `user_tokens_api` state `YieldUSDCEthereum` (accounts API; native ETH + USDC),
balances via `moralis_evm_token_balances_api=NonZeroEvmBalances`.
## Scenarios the test drives
`user_tokens_api=YieldUSDCEthereum`, `moralis_evm_token_balances_api=NonZeroEvmBalances`, and
`yield_supply_status` **NotActive → (after activation) Active**. The Active flip is what turns the
EarnBlock from "available" into the active "Yield Mode enabled / Average APY" state AND surfaces the
history row.
## Gotchas that cost real time
1. **`isActive` in `yield/markets` & `yield/token` means "market is available", not "user activated".**
It MUST be `true` or `YieldSupplyTokenStatusSuccessTransformer` returns `Unavailable` and the block
never renders. User activation is tracked separately by the on-chain `eth_call` status flip.
2. **`yieldSupplyKey` matching is case-sensitive string equality** (`"${backendId}_$tokenAddress"` vs
`"${network.rawId}_$contractAddress"`). All addresses in mocks must be **lowercase** — every existing
mock is. A checksummed address yields `yieldSupplyApy size=0` and no available block.
3. **Active vs available is driven by `CryptoCurrencyStatus.value.yieldSupplyStatus.isActive`** (on-chain
eth_call `0xf8e8be9c`), not the API `isActive`. Flip the `yield_supply_status` scenario + pull-to-refresh.
4. **Infra fix (production, already applied):** `YieldSupply` ApiConfig MOCK base URL was `yield.tests-d.com`
(NOT redirected by `WireMockRedirectInterceptor`) → fixed to `wiremock.tests-d.com`. And
`eth-blockbook.nownodes.io` was added to `REDIRECTABLE_THIRD_PARTY_HOSTS`. Without these the yield/history
requests bypass WireMock entirely.
5. **Hold-to-confirm must wait for the fee.** The "Start earning" `HoldToConfirmButton` is disabled
(`holdToConfirmGestures(enabled=false)` swallows the gesture) until the fee is calculated. Don't gate on
the high-fee notification (it's absent on cheap chains) — use the fee-agnostic retry: a single step that
`flakySafely`-retries `longClick(HOLD_DURATION_MS)` then asserts the sheet closed
(`startEarningButton.assertIsNotDisplayed()`). `state.isConfirmed` makes re-holds no-ops, so no double-send.
A hold step that finishes in ~270 ms instead of ~2 s = the gesture was swallowed (button disabled).
6. **The yield-enter history row is a `TransactionItemUM.Pill`** (converter maps `YieldSupply.Enter`
Pill, like Approve/Staking), rendered by `TransactionStatusPill`. It now carries
`TransactionHistoryItemTestTags.ITEM` (added for parity with `ContentItem`) so `transactionItem(title)`
finds it. Title string = `yield_module_transaction_enter` ("Yield Mode enabled" / "Режим доходности
подключен"). The row opens the explorer on click.
7. **"Nothing to add to TxHistory"** in logs is NOT an error — it refers to recent/pending txs, separate
from the API history.
## testTags added to production (reuse, don't re-add)
`TokenDetailsScreenTestTags.YIELD_SUPPLY_BLOCK` / `YIELD_SUPPLY_AVAILABLE_BLOCK`; `YieldSupplyTestTags`
(`PROMO_CONTINUE_BUTTON`, `START_EARNING_BUTTON`); `TransactionHistoryItemTestTags.ITEM` now on
`TransactionStatusPill`. Page objects: yield locators in `TokenDetailsPageObject`,
`YieldSupplyPromoPageObject`, `YieldSupplyStartEarningPageObject`.

36
.gitattributes vendored Normal file
View file

@ -0,0 +1,36 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Normalize all text files to LF in the repository and the working tree on
# every OS, regardless of the contributor's core.autocrlf setting.
* text=auto eol=lf
# Windows script files must stay CRLF.
*.bat text eol=crlf
*.cmd text eol=crlf
# Unix scripts and the Gradle wrapper must stay LF.
*.sh text eol=lf
gradlew text eol=lf
# Binary files must be left untouched (never EOL-normalized or diffed as text).
# Images
*.png binary
*.webp binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
# Fonts
*.ttf binary
*.otf binary
# JVM / Android artifacts
*.jar binary
*.aar binary
*.so binary
# Signing keys & keystores
*.jks binary
*.keystore binary
# Archives & databases
*.zip binary
*.db binary

1
.gitignore vendored
View file

@ -48,4 +48,5 @@ find-latest-release-branch.output
# Claude
/.claude/worktrees/
/.claude/settings.local.json
CLAUDE.local.md

View file

@ -5,15 +5,10 @@
"command": "npx",
"args": ["-y", "firebase-tools@latest", "mcp"]
},
"atlassian": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.atlassian.com/v1/sse"]
},
"notion": {
"type": "stdio",
"command": "npx",
"args": ["-y", "mcp-remote", "https://mcp.notion.com/mcp"]
}
}
}
}

5
.worktreeinclude Normal file
View file

@ -0,0 +1,5 @@
# Gitignored files copied into new Claude Code worktrees.
# Syntax: .gitignore patterns. Only gitignored matches are copied.
.claude/settings.local.json
app/google-services.json
local.properties

View file

@ -78,6 +78,19 @@ The app uses [Decompose](https://github.com/arkivanov/Decompose) for lifecycle-a
- Exposes `StateFlow<{Name}UM>` (UM = UI Model, state class in `ui/state/` subpackage)
- Has `modelScope` (SupervisorJob + mainImmediate), auto-cancelled on destroy
**State exposure (preferred pattern):** expose a public read-only `StateFlow` backed by a Kotlin
**explicit backing field** rather than a separate `private val _state` + `asStateFlow()`. The project
enables the `ExplicitBackingFields` compiler feature, so write:
```kotlin
val uiState: StateFlow<FooUM>
field = MutableStateFlow(FooUM())
// inside the class, mutate via uiState.update { … }; callers see StateFlow<FooUM>
```
This applies to both Decompose `Model`s and Android `ViewModel`s. Avoid the `_uiState`/`asStateFlow()`
duplication for new code. References: `ScanFailsModel`, `AppSettingsModel`.
**Child navigation within features:**
- `childStack()` — stacked screen navigation (back stack)
- `childSlot()` — optional overlays/bottom sheets (single or no child)
@ -102,7 +115,7 @@ The app uses [Decompose](https://github.com/arkivanov/Decompose) for lifecycle-a
- **Async:** Kotlin Coroutines + Flow. Inject `CoroutineDispatcherProvider` (from `core/utils`) instead of using `Dispatchers.*` directly — provides `main`, `mainImmediate`, `io`, `default`, `single`
- **Error handling:** Arrow's `Either<Error, Success>` pattern throughout domain/data layers. `DataError` sealed hierarchy for domain errors. See `domain/core/CLAUDE.md` for the LCE pattern
- **Analytics:** `AnalyticsEvent(category, event, params)` in `core/analytics/models/`. Feature events are sealed class hierarchies extending `AnalyticsEvent`. Send via injected `AnalyticsEventHandler`
- **Feature toggles:** `FeatureTogglesManager` in `core/config-toggles/`. Toggles are defined in `core/config-toggles/src/main/assets/configs/feature_toggles_config.json` and auto-generated into a `FeatureToggles` enum by the convention plugin at build time. Each feature module exposes its own `XxxFeatureToggles` interface (in `api/`) with a `DefaultXxxFeatureToggles` implementation (in `impl/`) that delegates to `FeatureTogglesManager`
- **Feature toggles:** `FeatureTogglesManager` in `core/config-toggles/`. See `core/config-toggles/CLAUDE.md`.
- **Supported languages:** `SupportedLanguages` in `core/utils/` defines the app's supported locales: en, ru, de, fr, it, ja, uk, zh, es. `getCurrentSupportedLanguageCode()` returns the device locale if supported, otherwise falls back to English. Used by API calls that accept a language parameter
### Build System

View file

@ -125,6 +125,7 @@ dependencies {
implementation(projects.domain.wallets)
implementation(projects.domain.wallets.models)
implementation(projects.domain.settings)
implementation(projects.domain.appUpdate)
implementation(projects.domain.tokens)
implementation(projects.domain.tokens.models)
implementation(projects.domain.txhistory)
@ -166,6 +167,7 @@ dependencies {
implementation(projects.domain.walletManager)
implementation(projects.domain.walletManager.models)
implementation(projects.domain.yieldSupply)
implementation(projects.domain.polymarket)
implementation(projects.domain.promo)
implementation(projects.domain.blockaid)
implementation(projects.domain.hotWallet)
@ -195,6 +197,7 @@ dependencies {
implementation(projects.libs.tangemSdkApi)
implementation(projects.data.account)
implementation(projects.data.addressBook)
implementation(projects.data.appCurrency)
implementation(projects.data.appTheme)
implementation(projects.data.balanceHiding)
@ -202,6 +205,7 @@ dependencies {
implementation(projects.data.card)
implementation(projects.data.common)
implementation(projects.data.settings)
implementation(projects.data.appUpdate)
implementation(projects.data.tokens)
implementation(projects.data.assetsdiscovery)
implementation(projects.data.txhistory)
@ -229,6 +233,7 @@ dependencies {
implementation(projects.data.swap)
implementation(projects.data.walletManager)
implementation(projects.data.yieldSupply)
implementation(projects.data.polymarket)
implementation(projects.data.promo)
implementation(projects.data.hotWallet)
implementation(projects.data.news)
@ -271,6 +276,8 @@ dependencies {
implementation(projects.features.details.impl)
implementation(projects.features.disclaimer.api)
implementation(projects.features.disclaimer.impl)
implementation(projects.features.forceUpdate.api)
implementation(projects.features.forceUpdate.impl)
implementation(projects.features.pushNotifications.api)
implementation(projects.features.pushNotifications.impl)
implementation(projects.features.pushNotificationSettings.api)
@ -337,8 +344,12 @@ dependencies {
implementation(projects.features.tokenRecieve.impl)
implementation(projects.features.yieldSupply.api)
implementation(projects.features.yieldSupply.impl)
implementation(projects.features.polymarket.api)
implementation(projects.features.polymarket.impl)
implementation(projects.features.approval.api)
implementation(projects.features.approval.impl)
implementation(projects.features.forYou.api)
implementation(projects.features.forYou.impl)
/** AndroidX libraries */
implementation(deps.androidx.core.ktx)
@ -398,6 +409,7 @@ dependencies {
kapt(deps.hilt.compilerx)
/** Other libraries */
implementation(deps.arrow.fx)
implementation(deps.kotlin.immutable.collections)
implementation(deps.material)
implementation(deps.googlePlay.review)

View file

@ -18,6 +18,7 @@ import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import com.tangem.common.allure.FailedStepScreenshotInterceptor
import com.tangem.common.constants.TestConstants.ALLURE_LABEL_NAME
import com.tangem.common.constants.TestConstants.ALLURE_LABEL_VALUE
import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT
import com.tangem.common.rules.ApiEnvironmentRule
import com.tangem.datasource.api.common.config.managers.ApiConfigsManager
import com.tangem.datasource.local.preferences.AppPreferencesStore
@ -179,50 +180,29 @@ abstract class BaseTestCase : TestCase(
fun waitForIdle() = composeTestRule.waitForIdle()
/**
* Waits until [block] stops throwing (or [timeoutMillis] elapses). Use in scenario (BaseTestCase extension)
* code where flakySafely is unavailable; in test bodies prefer flakySafely.
*/
fun awaitSuccess(timeoutMillis: Long = WAIT_UNTIL_TIMEOUT, block: () -> Unit) {
composeTestRule.waitUntil(timeoutMillis = timeoutMillis) { runCatching(block).isSuccess }
}
private fun applicationInjectionRule(): ApplicationInjectionExecutionRule {
return ApplicationInjectionExecutionRule(
toggleStates = mapOf(
"SWAP_REDESIGN_ENABLED" to false,
"ACCOUNTS_FEATURE_ENABLED" to true,
"GASLESS_APPROVAL_ENABLED" to true,
"MAIN_SCREEN_QR_SCANNING_ENABLED" to true,
"ADD_AND_MANAGE_TOKENS_ENABLED" to true,
"ASSETS_DISCOVERY_ENABLED" to true,
"VISA_ONBOARDING_ENABLED" to true,
// Version-gated toggles released in versions <= 6.0 — forced on so tests run against the actual
// build even when the app version resolves to 1.0.0-SNAPSHOT on CI (then 1.0.0 < x.xx would
// disable them). On the releases/6.0 branch every toggle with version <= 6.0 ships enabled.
// 5.37
"HEDERA_ERC20_ENABLED" to true,
// 5.39
"STAKING_ETH_ENABLED" to true,
"DYNAMIC_ADDRESSES_ENABLED" to true,
"SOLANA_TX_HISTORY_ENABLED" to true,
"SOLANA_SCALED_UI_AMOUNT_ENABLED" to true,
"SWAP_AB_ENABLED" to true,
"AND_15310_ADD_FUNDS_STAGE1" to true,
"AND_15009_SWAP_PROVIDER_FILTER_ENABLED" to true,
"AND_15101_TANGEM_PAY_HOT_WALLET_ONBOARDING" to true,
"AND_15402_ADI_MAIN_SCREEN_DEFAULT_ENABLED" to true,
"AND_15103_SWAP_RATE_EXPERIENCE_ENABLED" to true,
"AND_15122_SWAP_PREDEFINED_BUTTONS_ENABLED" to true,
"TWI_1512_HIDE_STORIES_FOR_REFERRAL_ENABLED" to true,
// 5.39.2
"AND_15154_YIELD_PROMO_ENABLED" to true,
// 5.40
"TWI_1377_MANAGE_FUNDS" to true,
// 6.0
"APP_REDESIGN_ENABLED" to true,
"TWI_1326_YIELD_MODE_SWAP_ENABLED" to true,
"AND_15207_SWAP_SWITCH_TO_TRANSFER_ENABLED" to true,
"AND_15120_SWAP_INTEGRATED_APPROVE" to true,
"AND_15596_ONBOARDING_PUSH_NOTIFICATION_DOUBLE_ASK_AB_ENABLED" to true,
"AND_15258_QUICK_TOP_UP_ENABLED" to true,
"AND_15368_VISA_PAY_REDESIGN" to true,
"AND_15364_VISA_PAY_CARD_CLOSE" to true,
"AND_15489_EXPRESS_SHARE_BUTTON_ENABLED" to true,
"AND_15235_VISA_MULTIPLE_CARDS" to true,
"AND_15715_SWAP_BEST_DEX_RATE_ENABLED" to true,
// 6.1
"TWI_1638_VA_MVP0_ENABLED" to true,
"TWI_1403_ONBOARDING_PUSH_NOTIFICATION_DOUBLE_ASK_AB_ENABLED" to true,
)
)
}

View file

@ -46,6 +46,7 @@ object TestConstants {
const val ALLURE_LABEL_VALUE = "Kaspresso"
const val USER_TOKENS_API_SCENARIO = "user_tokens_api"
const val COINS_API_SCENARIO = "coins_api"
const val REFERRAL_API_SCENARIO = "referral_api"
const val QUOTES_API_SCENARIO = "quotes_api"
const val CREATE_USER_WALLET_API_SCENARIO = "create_user_wallet_api"
@ -68,5 +69,7 @@ object TestConstants {
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
const val TANGEM_PAY_ELIGIBILITY_SCENARIO = "tangem_pay_eligibility"
const val TANGEM_PAY_ELIGIBILITY_CHANNELS_SCENARIO = "tangem_pay_eligibility_channels"
const val TANGEM_PAY_KYC_STATUS_SCENARIO = "tangem_pay_kyc_status"
const val TANGEM_PAY_ACCESS_CODE = "517384"
}

View file

@ -0,0 +1,20 @@
package com.tangem.common.extensions
import androidx.compose.ui.test.hasTestTag
import androidx.compose.ui.test.performClick
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.AppSettingsScreenTestTags
import com.tangem.core.ui.test.TokenDetailsTopBarTestTags
import com.tangem.core.ui.test.TopAppBarTestTags
import com.tangem.core.ui.test.TopNavigationTestTags
fun BaseTestCase.tapBackButton() {
waitForIdle()
composeTestRule.onNode(
hasTestTag(TopNavigationTestTags.BACK_BUTTON)
or hasTestTag(TopAppBarTestTags.CLOSE_BUTTON)
or hasTestTag(TokenDetailsTopBarTestTags.BACK_BUTTON)
or hasTestTag(AppSettingsScreenTestTags.BACK_BUTTON),
useUnmergedTree = true,
).performClick()
}

View file

@ -0,0 +1,34 @@
package com.tangem.common.extensions
import androidx.compose.ui.semantics.SemanticsNode
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.semantics.getOrNull
import androidx.compose.ui.test.SemanticsNodeInteractionCollection
import androidx.compose.ui.test.assertIsDisplayed
/** Returns the first non-blank text found in this node or its subtree (unmerged tree). */
fun SemanticsNode.firstTextOrNull(): String? {
config.getOrNull(SemanticsProperties.Text)
?.firstOrNull()?.text?.takeIf { it.isNotBlank() }
?.let { return it }
children.forEach { child -> child.firstTextOrNull()?.let { return it } }
return null
}
/**
* Reads the first text of every currently displayed node in this collection, in visual order
* (top-to-bottom, then left-to-right). Non-displayed nodes and nodes without text are skipped.
*/
fun SemanticsNodeInteractionCollection.displayedTextsInVisualOrder(): List<String> {
val count = fetchSemanticsNodes().size
return (0 until count)
.mapNotNull { index ->
val interaction = get(index)
if (runCatching { interaction.assertIsDisplayed() }.isFailure) return@mapNotNull null
val node = interaction.fetchSemanticsNode()
val text = node.firstTextOrNull() ?: return@mapNotNull null
node.boundsInRoot to text
}
.sortedWith(compareBy({ it.first.top }, { it.first.left }))
.map { it.second }
}

View file

@ -42,6 +42,17 @@ object AddressComparisonHelper {
assertTrue(report, false)
}
fun derivationPathForBlockchain(json: String, blockchain: String): String {
val array = JSONArray(json)
for (i in 0 until array.length()) {
val entry = array.getJSONObject(i)
if (entry.getString("blockchain").equals(blockchain, ignoreCase = true)) {
return entry.getString("derivationPath").trim()
}
}
error("No entry with blockchain '$blockchain' found in addresses JSON")
}
private fun parseAndNormalize(json: String): List<AddressEntry> {
val array = JSONArray(json)
val entries = mutableListOf<AddressEntry>()

View file

@ -4,6 +4,8 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
fun getClipboardText(context: Context): String? {
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
@ -27,12 +29,15 @@ fun clearClipboard(
clipboard.clearPrimaryClip()
}
// Kotlin's assert() is a no-op on device (JVM assertions disabled) — use JUnit asserts here.
fun assertClipboardTextEquals(
expected: String,
context: Context = ApplicationProvider.getApplicationContext()
) {
assertEquals("Clipboard text mismatch", expected, getClipboardText(context))
}
fun assertClipboardIsEmpty(context: Context = ApplicationProvider.getApplicationContext()) {
val actual = getClipboardText(context)
assert(actual == expected) {
"Clipboard text mismatch.\nExpected: '$expected'\nActual: '$actual'"
}
assertTrue("Expected empty clipboard but was: '$actual'", actual.isNullOrEmpty())
}

View file

@ -1,10 +1,16 @@
package com.tangem.common.utils
import okhttp3.Call
import okhttp3.EventListener
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.json.JSONObject
import com.tangem.utils.logging.TangemLogger
import java.io.IOException
import java.net.InetSocketAddress
import java.net.Proxy
import java.util.concurrent.TimeUnit
// WC URIs embed a session symKey that lets anyone join/hijack the session — strip it before logging.
@ -13,6 +19,79 @@ private val WC_SECRET_REGEX = Regex("(symKey(?:=|%3D))[^&\\s\"']+", RegexOption.
private fun redactWcSecrets(text: String): String =
WC_SECRET_REGEX.replace(text) { "${it.groupValues[1]}<redacted>" }
private const val DEFAULT_MAX_ATTEMPTS = 4
private const val INITIAL_BACKOFF_MS = 500L
/**
* Runs [block] with exponential backoff. Retries ONLY when [block] throws (transient failure:
* network error, non-2xx, malformed body). A `null` return is treated as terminal (e.g. "200 but no
* data for this key") and is NOT retried. Returns the block result, or null if all attempts failed.
*/
private fun <T> retryWithBackoff(
maxAttempts: Int = DEFAULT_MAX_ATTEMPTS,
initialDelayMs: Long = INITIAL_BACKOFF_MS,
block: (attempt: Int) -> T,
): T? {
var delayMs = initialDelayMs
var lastError: Throwable? = null
repeat(maxAttempts) { i ->
val attempt = i + 1
try {
return block(attempt)
} catch (e: Exception) {
lastError = e
TangemLogger.w("Attempt $attempt/$maxAttempts failed: ${e.message}")
if (attempt < maxAttempts) {
try {
Thread.sleep(delayMs)
} catch (ie: InterruptedException) {
Thread.currentThread().interrupt()
TangemLogger.w("Retry backoff sleep interrupted; aborting retries")
return null
}
delayMs *= 2
}
}
}
TangemLogger.e("All $maxAttempts attempts failed", lastError)
return null
}
/**
* Logs the actual connected endpoint (IPv4/IPv6) and whether a proxy is in the path. Lets CI logs
* distinguish "went out via the wrong egress / IPv6 / through a local proxy" from other failures.
*/
private val diagnosticEventListener = object : EventListener() {
override fun connectStart(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy) {
TangemLogger.i("Connecting to ${inetSocketAddress.address?.hostAddress} (proxy=$proxy)")
}
}
private fun diagnosticClient(connectSec: Long, readSec: Long, callSec: Long): OkHttpClient =
OkHttpClient.Builder()
.connectTimeout(connectSec, TimeUnit.SECONDS)
.readTimeout(readSec, TimeUnit.SECONDS)
.callTimeout(callSec, TimeUnit.SECONDS)
// Don't follow redirects: a Cloudflare Access 302 must stay visible (its `location` points at
// cloudflareaccess.com) so logHttpFailure can flag "egress IP not allow-listed". /health and
// /addresses have no legitimate redirects.
.followRedirects(false)
.followSslRedirects(false)
.eventListener(diagnosticEventListener)
.build()
/**
* Logs enough to classify a failed response at a glance: `cf-ray`/`location`/`server` reveal a
* Cloudflare Access 302 (egress IP not allow-listed) vs an origin 5xx vs anything else.
*/
private fun logHttpFailure(tag: String, response: Response, body: String) {
TangemLogger.e(
"$tag failed: code=${response.code} cf-ray=${response.header("cf-ray") ?: "-"} " +
"server=${response.header("server") ?: "-"} location=${response.header("location") ?: "-"} " +
"body=${body.take(200)}",
)
}
/**
* Requests a WalletConnect URI from the qa-tools service.
*
@ -142,50 +221,40 @@ fun getAddressesFromApi(
): String? {
TangemLogger.i("Getting addresses for seed key: $seedKey")
val client = OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.callTimeout(90, TimeUnit.SECONDS)
.build()
val client = diagnosticClient(connectSec = 30, readSec = 60, callSec = 90)
val request = Request.Builder()
.url("$baseUrl/addresses")
.get()
.build()
return try {
return retryWithBackoff { attempt ->
TangemLogger.i("Getting addresses for '$seedKey', attempt $attempt")
client.newCall(request).execute().use { response ->
TangemLogger.i("Response code: ${response.code}")
if (!response.isSuccessful) {
// Transient (network/Access 302/5xx) — throw so retryWithBackoff retries.
logHttpFailure("getAddressesFromApi", response, response.body?.string() ?: "")
throw IOException("getAddressesFromApi: HTTP ${response.code}")
}
if (response.isSuccessful) {
val body = response.body?.string() ?: ""
val body = response.body?.string() ?: ""
val contentType = response.header("Content-Type") ?: ""
if (!contentType.contains("application/json") && !body.trimStart().startsWith("{")) {
logHttpFailure("getAddressesFromApi (not JSON)", response, body)
throw IOException("getAddressesFromApi: unexpected non-JSON response")
}
val contentType = response.header("Content-Type") ?: ""
if (!contentType.contains("application/json") && !body.trimStart().startsWith("{")) {
TangemLogger.e("Unexpected response (not JSON), Content-Type: $contentType, body: $body")
return null
}
val jsonObject = JSONObject(body)
val data = jsonObject.optJSONObject("data") ?: jsonObject
val seedData = data.optJSONArray(seedKey)
if (seedData != null) {
TangemLogger.i("Got addresses for $seedKey: ${seedData.length()} entries")
seedData.toString()
} else {
TangemLogger.e("No data found for seed key: $seedKey")
null
}
val jsonObject = JSONObject(body)
val data = jsonObject.optJSONObject("data") ?: jsonObject
val seedData = data.optJSONArray(seedKey)
if (seedData != null) {
TangemLogger.i("Got addresses for $seedKey: ${seedData.length()} entries")
seedData.toString()
} else {
val errorBody = response.body?.string() ?: "No error body"
TangemLogger.e("Request failed: ${response.code}, body: $errorBody")
// Terminal: server responded fine but has no data for this key — retrying won't help.
TangemLogger.e("No data found for seed key: $seedKey")
null
}
}
} catch (e: Exception) {
TangemLogger.e("Error getting addresses", e)
null
}
}
@ -194,43 +263,31 @@ fun checkServiceHealth(
): String? {
TangemLogger.i("Checking service health")
val client = OkHttpClient()
val client = diagnosticClient(connectSec = 15, readSec = 30, callSec = 45)
val request = Request.Builder()
.url("$baseUrl/health")
.get()
.build()
return try {
return retryWithBackoff { attempt ->
TangemLogger.i("Checking service health, attempt $attempt")
client.newCall(request).execute().use { response ->
TangemLogger.i("Response code: ${response.code}")
if (!response.isSuccessful) {
// Transient (network/Access 302/5xx) — throw so retryWithBackoff retries.
logHttpFailure("checkServiceHealth", response, response.body?.string() ?: "")
throw IOException("checkServiceHealth: HTTP ${response.code}")
}
if (response.isSuccessful) {
val body = response.body?.string() ?: ""
TangemLogger.i("Response body: $body")
if (body.isEmpty()) {
TangemLogger.e("Response body is empty")
return null
}
val jsonObject = JSONObject(body)
val status = jsonObject.optString("status", "")
if (status.isNotEmpty()) {
TangemLogger.i("Got status successfully: $status")
status
} else {
TangemLogger.e("Status field is missing or empty")
null
}
val body = response.body?.string() ?: ""
val status = if (body.isEmpty()) "" else JSONObject(body).optString("status", "")
if (status.isNotEmpty()) {
TangemLogger.i("Got status successfully: $status")
status
} else {
val errorBody = response.body?.string() ?: "No error body"
TangemLogger.e("Request failed: ${response.code}, body: $errorBody")
null
// Empty/malformed body from a 2xx — treat as transient and retry.
logHttpFailure("checkServiceHealth (empty status)", response, body)
throw IOException("checkServiceHealth: missing 'status' field")
}
}
} catch (e: Exception) {
TangemLogger.e("Error checking health", e)
null
}
}

View file

@ -0,0 +1,22 @@
package com.tangem.common.utils
import android.graphics.Bitmap
import com.google.zxing.BinaryBitmap
import com.google.zxing.DecodeHintType
import com.google.zxing.RGBLuminanceSource
import com.google.zxing.common.HybridBinarizer
import com.google.zxing.qrcode.QRCodeReader
/** Decodes the text encoded in a QR-code [bitmap] (e.g. captured from a Compose node via captureToImage). */
fun decodeQrCode(bitmap: Bitmap): String {
val width = bitmap.width
val height = bitmap.height
val pixels = IntArray(width * height)
bitmap.getPixels(pixels, 0, width, 0, 0, width, height)
val source = RGBLuminanceSource(width, height, pixels)
val binaryBitmap = BinaryBitmap(HybridBinarizer(source))
val hints = mapOf(DecodeHintType.TRY_HARDER to true)
return QRCodeReader().decode(binaryBitmap, hints).text
}

View file

@ -1,6 +1,5 @@
package com.tangem.scenarios
import android.view.KeyEvent
import androidx.test.core.app.ApplicationProvider
import com.tangem.common.BaseTestCase
import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT_VERY_LONG
@ -57,31 +56,6 @@ fun BaseTestCase.verifyAddresses(seedPhrase: String, apiAddressesJson: String) {
}
}
private const val TESTER_MENU_MAX_ATTEMPTS = 3
/**
* Presses 'Volume Down' twice to open tester menu.
* Retries up to [TESTER_MENU_MAX_ATTEMPTS] times if the menu doesn't appear.
*/
private fun BaseTestCase.openTesterMenu() {
repeat(TESTER_MENU_MAX_ATTEMPTS) { attempt ->
waitForIdle()
device.uiDevice.pressKeyCode(KeyEvent.KEYCODE_VOLUME_DOWN)
device.uiDevice.pressKeyCode(KeyEvent.KEYCODE_VOLUME_DOWN)
val opened = runCatching {
onTesterMenuScreen { addressesInfoButton.assertIsDisplayed() }
}.isSuccess
if (opened) {
TangemLogger.i("Tester menu opened on attempt ${attempt + 1}")
return
}
TangemLogger.w("Tester menu not opened on attempt ${attempt + 1}, retrying...")
}
error("Failed to open tester menu after $TESTER_MENU_MAX_ATTEMPTS attempts")
}
/**
* Polls [walletManagersStore] until the wallet manager count stops growing for [WALLET_MANAGERS_SETTLE_MS].

View file

@ -61,6 +61,19 @@ fun BaseTestCase.openMainScreen(
}
}
/** Opens the main screen, synchronizes addresses, and opens the details of the token with [tokenName]. */
fun BaseTestCase.openTokenDetails(tokenName: String) {
step("Open 'Main Screen'") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Click on token with name: '$tokenName'") {
onMainScreen { tokenWithTitleAndAddress(tokenName).clickWithAssertion() }
}
}
@OptIn(ExperimentalTestApi::class)
fun BaseTestCase.openMainScreenWithExistingHotWallet(seedPhrase: String, accessCode: String = "") {
step("Click on 'Get started' button") {

View file

@ -42,7 +42,14 @@ fun BaseTestCase.enterAmountAndOpenSendConfirm(amount: String, recipientAddress:
* On the 'Send confirm' screen, open the network-fee selector and switch the fee token from the
* native coin to the given (stablecoin) token the core gasless action repeated across the suite.
*/
fun BaseTestCase.selectStablecoinAsFeeToken(coinName: String, tokenName: String) {
fun BaseTestCase.selectStablecoinAsFeeToken(
coinName: String,
tokenName: String,
// Positive flows wait until 'Apply' is enabled (fee is computed & payable). Negative flows
// (insufficient balance) must NOT wait for that — 'Apply' stays disabled — so pass false and let
// the caller assert the disabled/error state itself.
expectApplyEnabled: Boolean = true,
) {
step("Click on 'Network fee' block") {
onSendConfirmScreen {
feeSelectorBlock.assertIsDisplayed()
@ -57,6 +64,17 @@ fun BaseTestCase.selectStablecoinAsFeeToken(coinName: String, tokenName: String)
step("Select '$tokenName' as the fee-paying token") {
onSendFeeSelectorBottomSheet { feeTokenItem(tokenName).performClick() }
}
step("Wait until the '$tokenName' fee is loaded") {
composeTestRule.waitUntil(timeoutMillis = WAIT_UNTIL_TIMEOUT_LONG) {
runCatching {
onSendFeeSelectorBottomSheet {
networkFeeTitle.assertIsDisplayed()
feeTokenItem(tokenName).assertIsDisplayed()
if (expectApplyEnabled) applyButton.assertIsEnabled()
}
}.isSuccess
}
}
}
/**

View file

@ -1,12 +1,15 @@
package com.tangem.scenarios
import com.tangem.common.BaseTestCase
import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT_LONG
import com.tangem.common.extensions.SwipeDirection
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.common.extensions.swipeVertical
import com.tangem.screens.onAddAndManageBottomSheet
import com.tangem.screens.onMainScreen
import com.tangem.screens.onOrganizeTokensScreen
import io.qameta.allure.kotlin.Allure.step
import org.junit.Assert.assertEquals
fun BaseTestCase.openOrganizeTokensScreen() {
step("Swipe to 'Add & Manage' button") {
@ -19,4 +22,30 @@ fun BaseTestCase.openOrganizeTokensScreen() {
step("Click on 'Organize tokens' button in bottom sheet") {
onAddAndManageBottomSheet { organizeTokensButton.clickWithAssertion() }
}
}
fun BaseTestCase.getMainScreenTokensOrder(): List<String> {
var tokens: List<String> = emptyList()
step("Read displayed token titles from 'Main' screen") {
awaitSuccess(timeoutMillis = WAIT_UNTIL_TIMEOUT_LONG) {
onMainScreen { tokens = getDisplayedTokenTitles() }
require(tokens.isNotEmpty()) { "No token titles found on the main screen" }
}
}
return tokens
}
fun BaseTestCase.assertOrganizeTokensMatch(expectedTokens: List<String>) {
step("Open 'Organize tokens' bottom-sheet") {
onMainScreen { clickDisplayedAddAndManageButton() }
onAddAndManageBottomSheet { organizeTokensButton.clickWithAssertion() }
}
step("Assert 'Organize tokens' list matches the main screen order") {
onOrganizeTokensScreen {
assertEquals(expectedTokens, getDisplayedTokenTitles())
}
}
step("Return to 'Main' screen") {
onOrganizeTokensScreen { cancelButton.clickWithAssertion() }
}
}

View file

@ -0,0 +1,112 @@
package com.tangem.scenarios
import com.tangem.common.BaseTestCase
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.common.extensions.performTextInputInChunks
import com.tangem.screens.accounts.onAccountDetailsScreen
import com.tangem.screens.onAddCustomTokenScreen
import com.tangem.screens.onDetailsScreen
import com.tangem.screens.onDialog
import com.tangem.screens.onManageTokensScreen
import com.tangem.screens.onWalletSettingsScreen
import io.github.kakaocup.kakao.common.utilities.getResourceString
import io.qameta.allure.kotlin.Allure.step
import com.tangem.core.res.R as CoreResR
private fun mainAccountName(): String = getResourceString(CoreResR.string.account_main_account_title)
fun BaseTestCase.openManageTokens(accountName: String = mainAccountName()) {
openWalletSettingsScreen()
openAccountDetails(accountName)
step("Click on 'Manage tokens' button") {
onAccountDetailsScreen { manageTokensButton.clickWithAssertion() }
}
}
fun BaseTestCase.openAddCustomToken(accountName: String = mainAccountName()) {
openManageTokens(accountName)
step("Click on 'Add custom token' button") {
onManageTokensScreen { addCustomTokenButton.clickWithAssertion() }
}
}
fun BaseTestCase.addCustomTokenWithCustomDerivation(network: String, contract: String, derivationPath: String) {
step("Click on network: '$network'") {
awaitSuccess { onAddCustomTokenScreen { scrollToNetwork(network) } }
onAddCustomTokenScreen { networkRow(network).performClick() }
}
step("Enter contract address: '$contract'") {
awaitSuccess { onAddCustomTokenScreen { contractAddressField.assertExists() } }
onAddCustomTokenScreen { contractAddressField.performTextInputInChunks(contract) }
}
step("Click on 'Derivation path' field") {
awaitSuccess { onAddCustomTokenScreen { derivationSelectorField.assertExists() } }
onAddCustomTokenScreen { derivationSelectorField.performClick() }
}
step("Click on 'Custom derivation' button") {
awaitSuccess { onAddCustomTokenScreen { customDerivationButton.assertIsDisplayed() } }
onAddCustomTokenScreen { customDerivationButton.performClick() }
}
step("Enter custom derivation path: '$derivationPath'") {
awaitSuccess { onDialog { inputField.assertIsDisplayed() } }
onDialog { inputField.performTextInputInChunks(derivationPath) }
awaitSuccess { onDialog { okButton.assertIsEnabled() } }
onDialog { okButton.performClick() }
}
step("Click on 'Add token' button") {
awaitSuccess { onAddCustomTokenScreen { addTokenButton.assertIsEnabled() } }
onAddCustomTokenScreen { addTokenButton.performClick() }
}
navigateBackToMainFromManageTokens()
}
private fun BaseTestCase.navigateBackToWalletSettings() {
step("Click on 'Manage tokens' screen 'Back' button") {
waitForIdle()
onManageTokensScreen { topAppBarBackButton.performClick() }
}
step("Click on 'Account details' screen 'Back' button") {
waitForIdle()
onAccountDetailsScreen { topAppBarBackButton.performClick() }
}
}
fun BaseTestCase.assertDerivationPathsInSelector(networkToOpen: String, vararg expectedPaths: Pair<String, String>) {
step("Click on network: '$networkToOpen'") {
awaitSuccess { onAddCustomTokenScreen { scrollToNetwork(networkToOpen) } }
onAddCustomTokenScreen { networkRow(networkToOpen).performClick() }
}
step("Click on 'Derivation path' field") {
awaitSuccess { onAddCustomTokenScreen { derivationSelectorField.assertExists() } }
onAddCustomTokenScreen { derivationSelectorField.performClick() }
}
expectedPaths.forEach { (networkId, path) ->
step("Assert '$networkId' derivation path is '$path'") {
awaitSuccess { onAddCustomTokenScreen { scrollToDerivationRow(networkId) } }
onAddCustomTokenScreen { derivationPath(networkId, path).assertIsDisplayed() }
}
}
}
fun BaseTestCase.toggleTokenNetworkInManageTokens(tokenTitle: String, networkTitle: String) {
step("Click on token: '$tokenTitle'") {
awaitSuccess { onManageTokensScreen { tokenItem(tokenTitle).assertIsDisplayed() } }
onManageTokensScreen { tokenItem(tokenTitle).performClick() }
}
step("Click on '$networkTitle' switch") {
awaitSuccess { onManageTokensScreen { networkSwitch(networkTitle).assertIsDisplayed() } }
onManageTokensScreen { networkSwitch(networkTitle).performClick() }
}
}
fun BaseTestCase.navigateBackToMainFromManageTokens() {
navigateBackToWalletSettings()
step("Click on 'Wallet settings' screen 'Back' button") {
waitForIdle()
onWalletSettingsScreen { topAppBarBackButton.performClick() }
}
step("Click on 'Details' screen 'Back' button") {
waitForIdle()
onDetailsScreen { topAppBarBackButton.performClick() }
}
}

View file

@ -45,6 +45,21 @@ fun BaseTestCase.addNewCardWallet(mockContent: MockContent) {
}
}
fun BaseTestCase.addNewCardWalletWithoutSync(mockContent: MockContent) {
step("Click 'More' button on TopBar") {
onMainScreenTopBar { moreButton.clickWithAssertion() }
}
MockProvider.setMocks(mockContent)
step("Click on 'Add Wallet' button (scans a new hardware wallet)") {
onDetailsScreen { addWalletButton.clickWithAssertion() }
}
step("Assert 'Main' screen is displayed with the new wallet") {
composeTestRule.waitUntil(timeoutMillis = WAIT_UNTIL_TIMEOUT_VERY_LONG) {
runCatching { onMainScreenTopBar { moreButton.assertIsDisplayed() } }.isSuccess
}
}
}
fun BaseTestCase.clickDisplayedTokenOnMain(tokenName: String) {
step("Click on token '$tokenName' on the visible wallet") {
onMainScreen { clickDisplayedToken(tokenName) }
@ -86,13 +101,23 @@ fun BaseTestCase.addMissingReceiveTokenToWallet(token: String, recipientWalletNa
runCatching { onSwapSelectTokenScreen { marketsTokenWithName(token).performClick() } }.isSuccess
}
}
// The 'Add token' sheet pre-selects the recipient (the only wallet missing the token, since the source already holds it).
step("Assert recipient wallet '$recipientWalletName' is selected") {
step("Select recipient wallet '$recipientWalletName'") {
composeTestRule.waitUntil(timeoutMillis = WAIT_UNTIL_TIMEOUT_LONG) {
runCatching { onAddToPortfolioScreen { walletName(recipientWalletName).assertIsDisplayed() } }.isSuccess
runCatching { onAddToPortfolioScreen { selectedWalletRow.performClick() } }.isSuccess
}
composeTestRule.waitUntil(timeoutMillis = WAIT_UNTIL_TIMEOUT_LONG) {
runCatching { onAddToPortfolioScreen { walletOption(recipientWalletName).performClick() } }.isSuccess
}
}
step("Click on 'Add' button") {
onAddToPortfolioScreen { addButton.performClick() }
step("Select network '$token'") {
composeTestRule.waitUntil(timeoutMillis = WAIT_UNTIL_TIMEOUT_LONG) {
runCatching { onAddToPortfolioScreen { networkRow.performClick() } }.isSuccess
}
composeTestRule.waitUntil(timeoutMillis = WAIT_UNTIL_TIMEOUT_LONG) {
runCatching { onAddToPortfolioScreen { networkOption(token).performClick() } }.isSuccess
}
}
step("Click on 'Confirm' button") {
onAddToPortfolioScreen { confirmButton.performClick() }
}
}

View file

@ -1,11 +1,58 @@
package com.tangem.scenarios
import com.tangem.common.BaseTestCase
import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT_LONG
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.common.extensions.extractText
import com.tangem.common.utils.decodeQrCode
import com.tangem.screens.onAddFundsBottomSheet
import com.tangem.screens.onReceiveAssetsBottomSheet
import com.tangem.screens.onTokenDetailsScreen
import com.tangem.screens.onTokenReceiveQrCodeBottomSheet
import com.tangem.screens.onTokenReceiveWarningBottomSheet
import io.qameta.allure.kotlin.Allure.step
import org.junit.Assert
/** Opens the receive flow from a funded token's details via 'Add funds' → 'Receive'. */
fun BaseTestCase.openReceiveViaAddFunds() {
step("Click on 'Add funds' button") {
onTokenDetailsScreen { addFundsButton.clickWithAssertion() }
}
step("Click on 'Receive' button in bottom sheet") {
onAddFundsBottomSheet { receiveButton.clickWithAssertion() }
}
}
/**
* Asserts the QR code encodes the displayed address for both address types of a two-address-type coin,
* and that the two addresses differ.
*/
fun BaseTestCase.assertQrCodesMatchForBothAddressTypes() {
step("Go to QR code bottom sheet for the first address type") {
goToQrCodeBottomSheet()
}
var firstAddress = ""
step("Assert QR code encodes the first displayed address") {
firstAddress = assertQrCodeEncodesDisplayedAddress()
}
step("Go back to the receive addresses") {
device.uiDevice.pressBack()
}
step("Switch to the second address type") {
awaitSuccess(WAIT_UNTIL_TIMEOUT_LONG) { onReceiveAssetsBottomSheet { addressesPager.assertIsDisplayed() } }
onReceiveAssetsBottomSheet { scrollToAddress(1) }
}
step("Click on 'Show QR code' button for the second address type") {
onReceiveAssetsBottomSheet { showQrCodeButton(1).clickWithAssertion() }
}
var secondAddress = ""
step("Assert QR code encodes the second displayed address") {
secondAddress = assertQrCodeEncodesDisplayedAddress()
}
step("Assert the two address types are different") {
Assert.assertNotEquals(firstAddress, secondAddress)
}
}
fun BaseTestCase.goToQrCodeBottomSheet() {
step("Assert 'Token receive warning' bottom sheet is displayed") {
@ -15,7 +62,7 @@ fun BaseTestCase.goToQrCodeBottomSheet() {
onTokenReceiveWarningBottomSheet { gotItButton.performClick() }
}
step("Click on 'Show QR code' button") {
onReceiveAssetsBottomSheet { showQrCodeButton.clickWithAssertion() }
onReceiveAssetsBottomSheet { showQrCodeButton().clickWithAssertion() }
}
}
@ -39,3 +86,16 @@ fun BaseTestCase.checkQrCodeBottomSheetScenario() {
onTokenReceiveQrCodeBottomSheet { shareButton.assertIsDisplayed() }
}
}
/** Decodes the QR code on the receive bottom sheet and asserts it encodes the displayed address; returns that address. */
fun BaseTestCase.assertQrCodeEncodesDisplayedAddress(): String {
var displayedAddress = ""
step("Assert QR code encodes the displayed address") {
onTokenReceiveQrCodeBottomSheet {
displayedAddress = address.extractText()
val decoded = decodeQrCode(captureQrCodeBitmap())
Assert.assertEquals(displayedAddress, decoded)
}
}
return displayedAddress
}

View file

@ -0,0 +1,27 @@
package com.tangem.scenarios
import com.tangem.common.BaseTestCase
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.screens.onDetailsScreen
import com.tangem.screens.onMainScreenTopBar
import com.tangem.screens.onReferralProgramScreen
import com.tangem.screens.onWalletSettingsScreen
import io.qameta.allure.kotlin.Allure.step
fun BaseTestCase.referralTakeParticipate() {
step("Open 'Details' screen") {
onMainScreenTopBar { moreButton.clickWithAssertion() }
}
step("Open 'Wallet settings' screen") {
onDetailsScreen { walletNameButton.clickWithAssertion() }
}
step("Open 'Referral program' screen") {
onWalletSettingsScreen { referralProgramButton.clickWithAssertion() }
}
step("Tap 'Participate'") {
onReferralProgramScreen { participateButton.clickWithAssertion() }
}
step("Verify referral code is displayed") {
onReferralProgramScreen { personalCodeCard.assertIsDisplayed() }
}
}

View file

@ -13,24 +13,37 @@ fun BaseTestCase.checkSendWarning(
) {
val assertDisplay = if (isDisplayed) "displayed" else "not displayed"
// When we expect the warning to be absent, it may still be finishing its disappear animation right after the
// Confirm screen opens (e.g. after re-entering a valid address), so poll the Compose tree until it is actually
// gone instead of asserting once. When we expect it to be present, assert straight away.
fun assertWarning(block: () -> Unit) {
if (isDisplayed) block() else awaitSuccess(block = block)
}
step("Assert 'Send confirm screen' is displayed") {
onSendConfirmScreen {
appBarTitle.assertIsDisplayed()
}
}
step("Assert warning title is $assertDisplay") {
onSendConfirmScreen {
warningTitle(title).assertVisibility(isDisplayed)
assertWarning {
onSendConfirmScreen {
warningTitle(title).assertVisibility(isDisplayed)
}
}
}
step("Assert warning icon is $assertDisplay") {
onSendConfirmScreen {
sendWarningIcon(message).assertVisibility(isDisplayed)
assertWarning {
onSendConfirmScreen {
sendWarningIcon(message).assertVisibility(isDisplayed)
}
}
}
step("Assert warning message is $assertDisplay") {
onSendConfirmScreen {
sendWarningMessage(message).assertVisibility(isDisplayed)
assertWarning {
onSendConfirmScreen {
sendWarningMessage(message).assertVisibility(isDisplayed)
}
}
}
if (sendButtonIsDisabled)
@ -41,8 +54,10 @@ fun BaseTestCase.checkSendWarning(
}
else
step("Assert 'Send' button is enabled") {
onSendConfirmScreen {
sendButton.assertIsEnabled()
awaitSuccess {
onSendConfirmScreen {
sendButton.assertIsEnabled()
}
}
}
}

View file

@ -164,6 +164,16 @@ fun BaseTestCase.checkStoriesChanges() {
}
}
fun BaseTestCase.skipSwapStories() {
step("Skip 'Swap stories' screen if displayed") {
onSwapStoriesScreen {
if (closeButton.isDisplayedSafely()) {
closeButton.performClick()
}
}
}
}
fun BaseTestCase.selectFeeType(feeType: FeeType, selectedFeeAmount: String) {
step("Click on 'Select fee' icon") {
onSwapTokenScreen { selectFeeIcon.performClick() }
@ -317,6 +327,9 @@ fun BaseTestCase.openSwapInTransferModeWithHotWallet(
}
private fun BaseTestCase.navigateToSwapForToken(tokenName: String, fromAccountName: String) {
step("Collapse header") {
onMainScreen { collapseHeader() }
}
step("Scroll '$fromAccountName' into view (semantics, not touch — avoids the Markets sheet)") {
onMainScreen { scrollToAccount(fromAccountName) }
}

View file

@ -12,6 +12,8 @@ import com.tangem.screens.tangempay.*
import io.qameta.allure.kotlin.Allure.step
fun BaseTestCase.openTangemPay() {
// Existing customer: callers set the `tangem_pay_eligibility` scenario to PaeraCustomer (in
// additionalBeforeSection, before this runs), which drives the checkCustomerWalletId mock -> Payment account.
step("Import hot wallet from Tangem Pay seed phrase (with access code)") {
openMainScreenWithExistingHotWallet(SVS_SEED_PHRASE_12, accessCode = TANGEM_PAY_ACCESS_CODE)
}
@ -23,6 +25,44 @@ fun BaseTestCase.openTangemPay() {
}
}
/** Opens Tangem Pay and taps the card to reach the card management page. */
fun BaseTestCase.openTangemPayCardPage() {
openTangemPay()
step("Click on 'Card' button") {
onTangemPayMainScreen { cardButton.clickWithAssertion() }
}
step("Assert card page 'More' button is displayed") {
awaitSuccess { onTangemPayCardPageScreen { moreButton.assertIsDisplayed() } }
}
}
/** Opens the card page and taps 'Change' on the daily limit block to reach the limit setup screen. */
fun BaseTestCase.openTangemPayDailyLimitSetup() {
openTangemPayCardPage()
step("Click on 'Change' daily limit button") {
awaitSuccess { onTangemPayCardPageScreen { dailyLimitChangeButton.assertIsDisplayed() } }
onTangemPayCardPageScreen { dailyLimitChangeButton.performClick() }
}
step("Assert daily limit setup screen is displayed") {
awaitSuccess { onTangemPayDailyLimitScreen { amountField.assertIsDisplayed() } }
onTangemPayDailyLimitScreen { setLimitsButton.assertIsDisplayed() }
}
}
/** From the card page, opens the 'Replace card' reissue bottom sheet via the 'More' menu. */
fun BaseTestCase.openReissueSheet() {
step("Click on 'More' button") {
onTangemPayCardPageScreen { moreButton.clickWithAssertion() }
}
step("Click on 'Replace card' menu item") {
awaitSuccess { onTangemPayCardPageScreen { replaceCardMenuItem.assertIsDisplayed() } }
onTangemPayCardPageScreen { replaceCardMenuItem.performClick() }
}
step("Assert reissue bottom sheet is displayed") {
awaitSuccess { onTangemPayReissueSheet { confirmButton.assertIsDisplayed() } }
}
}
// Compose Test gesture — UiAutomator swipe doesn't reach Material3 PullToRefreshBox's NestedScrollConnection.
fun BaseTestCase.pullToRefreshTangemPay() {
val balance = composeTestRule.onNode(hasTestTag(TangemPayTestTags.PAYMENT_ACCOUNT_BALANCE))

View file

@ -0,0 +1,33 @@
package com.tangem.scenarios
import android.view.KeyEvent
import com.tangem.common.BaseTestCase
import com.tangem.screens.onTesterMenuScreen
import com.tangem.utils.logging.TangemLogger
private const val TESTER_MENU_MAX_ATTEMPTS = 3
/**
* Opens the tester menu by sending two 'Volume Down' key events in a single shell command.
* VolumeButtonDoublePressObserver needs two ACTION_DOWN within 300ms; two separate pressKeyCode
* calls are too slow, but both events in one `input keyevent` invocation arrive back-to-back within
* the window. Retries up to [TESTER_MENU_MAX_ATTEMPTS] times if it doesn't appear.
*/
fun BaseTestCase.openTesterMenu() {
repeat(TESTER_MENU_MAX_ATTEMPTS) { attempt ->
waitForIdle()
val volumeDown = KeyEvent.KEYCODE_VOLUME_DOWN
device.uiDevice.executeShellCommand("input keyevent $volumeDown $volumeDown")
val opened = runCatching {
onTesterMenuScreen { addressesInfoButton.assertIsDisplayed() }
}.isSuccess
if (opened) {
TangemLogger.i("Tester menu opened on attempt ${attempt + 1}")
return
}
TangemLogger.w("Tester menu not opened on attempt ${attempt + 1}, retrying...")
}
error("Failed to open tester menu after $TESTER_MENU_MAX_ATTEMPTS attempts")
}

View file

@ -0,0 +1,67 @@
package com.tangem.screens
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import androidx.compose.ui.test.performScrollToNode
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.AddCustomTokenScreenTestTags
import com.tangem.core.ui.test.BaseButtonTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
import androidx.compose.ui.test.hasTestTag as withTestTag
import androidx.compose.ui.test.hasText as withText
import com.tangem.core.res.R as CoreResR
class AddCustomTokenPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<AddCustomTokenPageObject>(semanticsProvider = semanticsProvider) {
val selectorList: KNode = child {
hasTestTag(AddCustomTokenScreenTestTags.SELECTOR_LIST)
}
fun networkRow(networkName: String): KNode = child {
hasTestTag(AddCustomTokenScreenTestTags.networkRow(networkName))
}
@OptIn(ExperimentalTestApi::class)
fun scrollToNetwork(networkName: String) = selectorList {
performScrollToNode(withTestTag(AddCustomTokenScreenTestTags.networkRow(networkName)))
}
@OptIn(ExperimentalTestApi::class)
fun scrollToDerivationRow(networkId: String) = selectorList {
performScrollToNode(withTestTag(AddCustomTokenScreenTestTags.derivationRow(networkId)))
}
fun derivationPath(networkId: String, path: String): KNode = child {
useUnmergedTree = true
hasTestTag(AddCustomTokenScreenTestTags.derivationRow(networkId))
hasAnyDescendant(withText(path))
}
val contractAddressField: KNode = child {
hasTestTag(AddCustomTokenScreenTestTags.CONTRACT_ADDRESS_FIELD)
}
val derivationSelectorField: KNode = child {
hasTestTag(AddCustomTokenScreenTestTags.DERIVATION_SELECTOR_FIELD)
}
val customDerivationButton: KNode = child {
hasTestTag(AddCustomTokenScreenTestTags.CUSTOM_DERIVATION_BUTTON)
}
val warningNotification: KNode = child {
hasTestTag(AddCustomTokenScreenTestTags.WARNING_NOTIFICATION)
}
val addTokenButton: KNode = child {
hasTestTag(BaseButtonTestTags.BUTTON)
hasText(getResourceString(CoreResR.string.common_add_token))
}
}
internal fun BaseTestCase.onAddCustomTokenScreen(function: AddCustomTokenPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -51,6 +51,11 @@ class AddFundsBottomSheetPageObject(semanticsProvider: SemanticsNodeInteractions
useUnmergedTree = true
}
fun titleWithTokenName(tokenTitle: String): KNode = child {
hasText(getResourceString(R.string.get_token_title, tokenTitle))
useUnmergedTree = true
}
fun userTokenWithTitle(tokenTitle: String): KNode = child {
hasTestTag(BuyTokenScreenTestTags.LAZY_LIST_ITEM)
hasAnyDescendant(withTestTag(TokenElementsTestTags.TOKEN_TITLE))

View file

@ -1,24 +1,53 @@
package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import androidx.compose.ui.test.hasClickAction
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.BaseBottomSheetTestTags
import com.tangem.wallet.R
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
// Scoped to the bottom-sheet container: the swap token-search screen stays behind the sheet and
// would otherwise make text matches (wallet tabs, market 'Ethereum' item) ambiguous.
class AddToPortfolioPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<AddToPortfolioPageObject>(semanticsProvider = semanticsProvider) {
ComposeScreen<AddToPortfolioPageObject>(
semanticsProvider = semanticsProvider,
viewBuilderAction = { hasTestTag(BaseBottomSheetTestTags.CONTAINER) },
) {
fun walletName(walletName: String): KNode = child {
hasText(walletName)
useUnmergedTree = true
}
val addButton: KNode = child {
hasText(getResourceString(R.string.common_add))
/** The wallet row on the 'Add token' screen (label + selected value); tap to open the wallet selector. */
val selectedWalletRow: KNode = child {
hasText(getResourceString(R.string.wc_common_wallet))
hasClickAction()
}
/** A wallet item inside the portfolio selector screen. */
fun walletOption(walletName: String): KNode = child {
hasText(walletName)
hasClickAction()
}
/** The network row on the 'Add token' screen; tap to open the 'Choose network' selector. */
val networkRow: KNode = child {
hasText(getResourceString(R.string.wc_common_network))
hasClickAction()
}
/** A network item inside the 'Choose network' selector. */
fun networkOption(networkName: String): KNode = child {
hasText(networkName)
hasClickAction()
}
val confirmButton: KNode = child {
hasText(getResourceString(R.string.common_confirm))
hasClickAction()
}
}

View file

@ -26,9 +26,9 @@ class AddTokenBottomSheetPageObject(semanticsProvider: SemanticsNodeInteractions
useUnmergedTree = true
}
val addButton: KNode = child {
val confirmButton: KNode = child {
hasTestTag(BaseButtonTestTags.TEXT)
hasText(getResourceString(R.string.common_add))
hasText(getResourceString(R.string.common_confirm))
useUnmergedTree = true
}

View file

@ -14,6 +14,10 @@ class AppSettingsPageObject(semanticsProvider: SemanticsNodeInteractionsProvider
hasTestTag(AppSettingsScreenTestTags.CURRENCY_BUTTON)
useUnmergedTree = true
}
val backButton: KNode = child {
hasTestTag(AppSettingsScreenTestTags.BACK_BUTTON)
}
}
internal fun BaseTestCase.onAppSettingsScreen(function: AppSettingsPageObject.() -> Unit) =

View file

@ -10,10 +10,15 @@ import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onCompose
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
import androidx.compose.ui.test.hasText as withText
import com.tangem.core.res.R as CoreResR
class DetailsPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<DetailsPageObject>(semanticsProvider = semanticsProvider) {
val screenContainer: KNode = child {
hasTestTag(DetailsScreenTestTags.SCREEN_CONTAINER)
}
val topAppBarBackButton: KNode = child {
hasTestTag(TopAppBarTestTags.CLOSE_BUTTON)
}
@ -61,6 +66,12 @@ class DetailsPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
hasAnyDescendant(withText(name))
useUnmergedTree = true
}
val getTangemPayRow: KNode = child {
hasTestTag(DetailsScreenTestTags.SCREEN_ITEM)
hasAnyDescendant(withText(getResourceString(CoreResR.string.tangempay_get_tangem_pay)))
useUnmergedTree = true
}
}
internal fun BaseTestCase.onDetailsScreen(function: DetailsPageObject.() -> Unit) =

View file

@ -2,6 +2,7 @@ package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.res.R as CoreResR
import com.tangem.core.ui.R
import com.tangem.core.ui.test.BaseButtonTestTags
import com.tangem.core.ui.test.BaseDialogTestTags
@ -10,6 +11,7 @@ import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onCompose
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
import androidx.compose.ui.test.hasTestTag as withTestTag
import androidx.compose.ui.test.hasText as withText
class DialogPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<DialogPageObject>(semanticsProvider = semanticsProvider) {
@ -18,6 +20,12 @@ class DialogPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
hasTestTag(BaseDialogTestTags.CONTAINER)
}
fun containerWithText(text: String): KNode = child {
hasTestTag(BaseDialogTestTags.CONTAINER)
hasAnyDescendant(withText(text = text, substring = true))
useUnmergedTree = true
}
val title: KNode = child {
hasTestTag(BaseDialogTestTags.TITLE)
}
@ -87,6 +95,11 @@ class DialogPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
hasText(getResourceString(R.string.common_ok))
}
val forgetButton: KNode = child {
hasTestTag(BaseButtonTestTags.BUTTON)
hasText(getResourceString(CoreResR.string.common_forget))
}
val changeButton: KNode = child {
hasTestTag(BaseButtonTestTags.BUTTON)
hasText(getResourceString(R.string.common_change))

View file

@ -1,8 +1,11 @@
package com.tangem.screens
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.semantics.SemanticsProperties
import androidx.compose.ui.test.*
import com.tangem.common.BaseTestCase
import com.tangem.common.extensions.displayedTextsInVisualOrder
import com.tangem.common.extensions.firstTextOrNull
import com.tangem.common.extensions.getQuantityString
import com.tangem.common.extensions.hasLazyListItemPosition
import com.tangem.common.utils.LazyListItemNode
@ -14,6 +17,7 @@ import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onCompose
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.compose.node.element.lazylist.KLazyListNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
import kotlin.math.abs
import androidx.compose.ui.test.hasTestTag as withTestTag
import androidx.compose.ui.test.hasText as withText
import com.tangem.core.res.R as CoreResR
@ -96,7 +100,7 @@ class MainScreenPageObject(private val semanticsProvider: SemanticsNodeInteracti
* Required because TangemCollapsingTopBar places the body at y=collapsingHeight, which
* pushes lower list items off-screen when the header is expanded.
*/
private fun collapseHeader() {
fun collapseHeader() {
screenContainer {
performTouchInput { swipeUp(startY = visibleSize.height * 0.6f, endY = visibleSize.height * 0.1f) }
}
@ -121,16 +125,75 @@ class MainScreenPageObject(private val semanticsProvider: SemanticsNodeInteracti
error("Token '$tokenName' is not displayed on the current wallet page")
}
// Adjacent pager pages stay mounted; swipe the wallet card that's actually on-screen.
/**
* Switches to the previous/next wallet in the pager. A horizontal swipe is a silent no-op unless
* the collapsing balance header is fully expanded and pinned to the top, so we retry: swipe, and
* whenever the wallet identity doesn't change, expand the header and try again.
*/
fun swipeToAdjacentWallet(toPrevious: Boolean) {
val nodes = semanticsProvider.onAllNodes(withTestTag(MainScreenTestTags.WALLET_LIST_ITEM))
for (i in 0 until nodes.fetchSemanticsNodes().size) {
val swiped = runCatching {
nodes[i].assertIsDisplayed()
nodes[i].performTouchInput { if (toPrevious) swipeRight() else swipeLeft() }
}.isSuccess
if (swiped) return
val before = displayedWalletIdentity()
repeat(times = WALLET_SWITCH_ATTEMPTS) {
swipeCurrentPage(toPrevious)
val now = displayedWalletIdentity()
if (now != null && now != before) return
expandCollapsingHeader()
}
error("Wallet did not switch from '$before' after $WALLET_SWITCH_ATTEMPTS attempts")
}
// Expand only *after* a swipe that didn't page: if the header is already pinned, a swipe-down here
// would trigger pull-to-refresh and un-pin it, breaking the horizontal swipe.
private fun expandCollapsingHeader() {
onScreenPage()?.performTouchInput {
swipeDown(startY = visibleSize.height * 0.3f, endY = visibleSize.height * 0.8f)
}
}
private fun swipeCurrentPage(toPrevious: Boolean) {
onScreenPage()?.performTouchInput { if (toPrevious) swipeRight() else swipeLeft() }
}
// Identity = title + balance: a still-restoring wallet has no CARD_TITLE but always a WALLET_BALANCE.
private fun displayedWalletIdentity(): String? {
val title = onScreenPageChild(withTestTag(MainScreenTestTags.CARD_TITLE))?.firstText()
val balance = onScreenPageChild(withTestTag(MainScreenTestTags.WALLET_BALANCE))?.firstText()
return listOfNotNull(title, balance).joinToString(separator = "|").ifBlank { null }
}
/**
* The full-width pager-page container currently on-screen. The pager keeps adjacent pages composed
* off-screen at ±pageWidth (so [assertIsDisplayed] can't tell them apart), hence selection by
* geometry: the on-screen page is the only one whose left edge is within half a page of x=0.
*/
private fun onScreenPage(): SemanticsNodeInteraction? =
firstNodeMatching(withTestTag(MainScreenTestTags.SCREEN_CONTAINER), useUnmergedTree = false) {
abs(it.left) < it.width / 2f
}
/** A node matching [matcher] whose centre lies within the on-screen page (skips zero-size off-screen copies). */
private fun onScreenPageChild(matcher: SemanticsMatcher): SemanticsNodeInteraction? {
val page = onScreenPage()?.fetchSemanticsNode()?.boundsInRoot ?: return null
return firstNodeMatching(matcher) {
it.width > 0f && it.height > 0f && it.center.x >= page.left && it.center.x < page.right
}
}
private fun SemanticsNodeInteraction.firstText(): String? = fetchSemanticsNode().firstTextOrNull()
// Single geometry primitive behind the pager helpers: the first node matching [matcher] whose
// bounds satisfy [predicate]. Replaces the per-caller onAllNodes(...)[i] loops.
private fun firstNodeMatching(
matcher: SemanticsMatcher,
useUnmergedTree: Boolean = true,
predicate: (Rect) -> Boolean,
): SemanticsNodeInteraction? {
val nodes = semanticsProvider.onAllNodes(matcher, useUnmergedTree = useUnmergedTree)
repeat(times = nodes.fetchSemanticsNodes().size) { index ->
val node = nodes[index]
val matches = runCatching { predicate(node.fetchSemanticsNode().boundsInRoot) }.getOrDefault(false)
if (matches) return node
}
return null
}
val restoringProgressText: KNode = child {
@ -139,12 +202,13 @@ class MainScreenPageObject(private val semanticsProvider: SemanticsNodeInteracti
}
val walletImportedBanner: KNode = child {
hasTestTag(WalletNotificationTestTags.ASSETS_DISCOVERY_BANNER)
hasTestTag(NotificationTestTags.TITLE)
hasText(getResourceString(CoreResR.string.initial_wallet_sync_banner_title))
useUnmergedTree = true
}
val walletImportedBannerCheckHereButton: KNode = child {
hasAnyAncestor(withTestTag(WalletNotificationTestTags.ASSETS_DISCOVERY_BANNER))
hasAnyAncestor(withTestTag(NotificationTestTags.CONTAINER))
hasText(getResourceString(CoreResR.string.main_manage_tokens))
useUnmergedTree = true
}
@ -201,6 +265,12 @@ class MainScreenPageObject(private val semanticsProvider: SemanticsNodeInteracti
useUnmergedTree = true
}
val getTangemPayBanner: KNode = child {
hasTestTag(NotificationTestTags.TITLE)
hasText(getResourceString(CoreResR.string.tangempay_onboarding_banner_title))
useUnmergedTree = true
}
val devCardNotificationIcon: KNode = child {
hasAnySibling(withText(getResourceString(R.string.warning_developer_card_title)))
hasTestTag(NotificationTestTags.ICON)
@ -373,6 +443,23 @@ class MainScreenPageObject(private val semanticsProvider: SemanticsNodeInteracti
useUnmergedTree = true
}
/** Collapses the header, scrolls to and clicks the 'Add & manage' button on the on-screen wallet page. */
@OptIn(ExperimentalTestApi::class)
fun clickDisplayedAddAndManageButton() {
val container = onScreenPage() ?: error("No on-screen wallet page found")
// Best-effort: the button is a footer outside the scrollable list, so performScrollToNode can
// throw when it's already visible — that must not abort the click below.
runCatching {
container.performTouchInput {
swipeUp(startY = visibleSize.height * 0.6f, endY = visibleSize.height * 0.1f)
}
container.performScrollToNode(withTestTag(MainScreenTestTags.ADD_AND_MANAGE_BUTTON))
}
val button = onScreenPageChild(withTestTag(MainScreenTestTags.ADD_AND_MANAGE_BUTTON))
?: error("'Add & manage' button is not displayed on the current wallet page")
button.performClick()
}
val searchThroughMarketPlaceholder: KNode = child {
hasText(getResourceString(R.string.markets_search_title_placeholder))
useUnmergedTree = true
@ -478,6 +565,21 @@ class MainScreenPageObject(private val semanticsProvider: SemanticsNodeInteracti
useUnmergedTree = true
}.assertIsDisplayed()
}
/**
* Token titles displayed on the current wallet page, in visual order. Reads the
* [TokenElementsTestTags.TOKEN_TITLE] rows so network group headers (which share the
* TOKEN_LIST_ITEM tag) are excluded, keeping the result symmetric with the 'Organize tokens' reader.
*/
fun getDisplayedTokenTitles(): List<String> =
semanticsProvider.onAllNodes(
withTestTag(TokenElementsTestTags.TOKEN_TITLE),
useUnmergedTree = true,
).displayedTextsInVisualOrder()
private companion object {
const val WALLET_SWITCH_ATTEMPTS = 4
}
}
internal fun BaseTestCase.onMainScreen(function: MainScreenPageObject.() -> Unit) =

View file

@ -6,6 +6,7 @@ import com.tangem.common.R
import com.tangem.core.ui.test.BaseButtonTestTags
import com.tangem.core.ui.test.BaseSearchBarTestTags
import com.tangem.core.ui.test.ManageTokensScreenTestTags
import com.tangem.core.ui.test.SearchBarTestTags
import com.tangem.core.ui.test.SwitchTestTags
import com.tangem.core.ui.test.TopAppBarTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
@ -17,6 +18,7 @@ import androidx.compose.ui.test.hasText as withText
import androidx.compose.ui.test.hasAnySibling as withAnySibling
import androidx.compose.ui.test.hasAnyDescendant as withAnyDescendant
import androidx.compose.ui.test.hasAnyAncestor as withAnyAncestor
import com.tangem.core.res.R as CoreResR
class ManageTokensPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ManageTokensPageObject>(semanticsProvider = semanticsProvider) {
@ -35,11 +37,43 @@ class ManageTokensPageObject(semanticsProvider: SemanticsNodeInteractionsProvide
hasTestTag(BaseSearchBarTestTags.SEARCH_BAR)
}
val searchClearButton: KNode = child {
hasTestTag(SearchBarTestTags.CLEAR_BUTTON)
}
val addCustomTokenButton: KNode = child {
hasTestTag(TopAppBarTestTags.MORE_BUTTON)
}
fun tokenItem(tokenName: String): KNode = child {
hasTestTag(ManageTokensScreenTestTags.TOKEN_ITEM)
hasText(tokenName)
}
fun networkStandard(networkName: String, standard: String): KNode = child {
useUnmergedTree = true
addSemanticsMatcher(
withText(standard).and(
withAnyAncestor(
withTestTag(ManageTokensScreenTestTags.NETWORK_NAME)
.and(withAnyDescendant(withText(networkName, ignoreCase = true))),
),
),
)
}
fun networkName(networkName: String): KNode = child {
useUnmergedTree = true
addSemanticsMatcher(
withTestTag(ManageTokensScreenTestTags.NETWORK_NAME)
.and(withAnyDescendant(withText(networkName))),
)
}
val contractAddressCopiedMessage: KNode = child {
hasText(getResourceString(CoreResR.string.contract_address_copied_message))
}
fun networkSwitch(networkName: String): KNode = child {
useUnmergedTree = true
addSemanticsMatcher(

View file

@ -1,8 +1,12 @@
package com.tangem.screens
import androidx.compose.ui.geometry.lerp
import androidx.compose.ui.test.SemanticsMatcher
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import androidx.compose.ui.test.hasAnyDescendant
import androidx.compose.ui.test.performTouchInput
import com.tangem.common.BaseTestCase
import com.tangem.common.extensions.displayedTextsInVisualOrder
import com.tangem.common.extensions.hasLazyListItemPosition
import com.tangem.common.utils.LazyListItemNode
import com.tangem.core.ui.test.OrganizeTokensScreenTestTags
@ -14,12 +18,13 @@ import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onCompose
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.compose.node.element.lazylist.KLazyListNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
import androidx.compose.ui.test.hasAnyAncestor as withAnyAncestor
import androidx.compose.ui.test.hasAnyChild as withAnyChild
import androidx.compose.ui.test.hasAnySibling as withAnySibling
import androidx.compose.ui.test.hasTestTag as withTestTag
import androidx.compose.ui.test.hasText as withText
class OrganizeTokensPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
class OrganizeTokensPageObject(private val semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<OrganizeTokensPageObject>(semanticsProvider = semanticsProvider) {
// region TopBar
@ -93,6 +98,15 @@ class OrganizeTokensPageObject(semanticsProvider: SemanticsNodeInteractionsProvi
}
}
// Read TOKEN_TITLE nodes, not the outer TOKEN_LIST_ITEM: the item container here doesn't merge its
// descendants, so the nested title Text never surfaces on the item node's semantics.
fun getDisplayedTokenTitles(): List<String> =
semanticsProvider.onAllNodes(
withTestTag(TokenElementsTestTags.TOKEN_TITLE) and
withAnyAncestor(withTestTag(OrganizeTokensScreenTestTags.TOKENS_LAZY_LIST)),
useUnmergedTree = true,
).displayedTextsInVisualOrder()
fun tokenDraggableButton(tokenTitle: String): KNode {
return lazyList.child {
hasTestTag(OrganizeTokensScreenTestTags.DRAGGABLE_IMAGE)
@ -108,6 +122,47 @@ class OrganizeTokensPageObject(semanticsProvider: SemanticsNodeInteractionsProvi
)
}
}
// Reorder by synthesizing a drag on the source row's handle: down, hold, step to the destination
// centre, lift — a single `swipe` won't engage the reorder detector. Only valid within one network
// group (isValidDropTarget), so source and destination must share a group.
fun dragToken(source: String, destination: String) {
val sourceHandle = semanticsProvider.onNode(dragHandleMatcher(source), useUnmergedTree = true)
val sourceNode = sourceHandle.fetchSemanticsNode()
val destinationNode = semanticsProvider
.onNode(tokenItemMatcher(destination), useUnmergedTree = true)
.fetchSemanticsNode()
// performTouchInput coordinates are local to the source node; express both endpoints there.
val origin = sourceNode.positionInRoot
val start = sourceNode.boundsInRoot.center - origin
val end = destinationNode.boundsInRoot.center - origin
sourceHandle.performTouchInput {
down(start)
advanceEventTime(DRAG_HOLD_MS)
repeat(times = DRAG_STEPS) { step ->
moveTo(lerp(start = start, stop = end, fraction = (step + 1).toFloat() / DRAG_STEPS))
advanceEventTime(DRAG_STEP_MS)
}
up()
}
}
// The drag handle sits under an untagged wrapper inside TOKEN_NON_FIAT_BLOCK, so anchor on the
// enclosing TOKEN_LIST_ITEM (one handle + one title per item) instead of the direct parent.
private fun dragHandleMatcher(tokenTitle: String): SemanticsMatcher =
withTestTag(OrganizeTokensScreenTestTags.DRAGGABLE_IMAGE) and
withAnyAncestor(tokenItemMatcher(tokenTitle))
private fun tokenItemMatcher(tokenTitle: String): SemanticsMatcher =
withTestTag(OrganizeTokensScreenTestTags.TOKEN_LIST_ITEM) and hasAnyDescendant(withText(tokenTitle))
private companion object {
const val DRAG_HOLD_MS = 200L
const val DRAG_STEPS = 16
const val DRAG_STEP_MS = 16L
}
}
internal fun BaseTestCase.onOrganizeTokensScreen(function: OrganizeTokensPageObject.() -> Unit) =

View file

@ -1,8 +1,10 @@
package com.tangem.screens
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.R
import com.tangem.core.ui.test.TokenReceiveAssetsBottomSheetTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
@ -11,10 +13,23 @@ import io.github.kakaocup.kakao.common.utilities.getResourceString
class ReceiveAssetsBottomSheetPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<ReceiveAssetsBottomSheetPageObject>(semanticsProvider = semanticsProvider) {
val showQrCodeButton: KNode = child {
/** 'Show QR code' button of the address at [index]; both pager cards stay composed, so match by position. */
fun showQrCodeButton(index: Int = 0): KNode = child {
hasText(getResourceString(R.string.token_receive_show_qr_code_title))
hasPosition(index)
useUnmergedTree = true
}
val addressesPager: KNode = child {
hasTestTag(TokenReceiveAssetsBottomSheetTestTags.ADDRESSES_PAGER)
useUnmergedTree = true
}
/** Pages the addresses carousel to the address of the given [index]. */
@OptIn(ExperimentalTestApi::class)
fun scrollToAddress(index: Int) {
addressesPager { performScrollToIndex(index) }
}
}
internal fun BaseTestCase.onReceiveAssetsBottomSheet(function: ReceiveAssetsBottomSheetPageObject.() -> Unit) =

View file

@ -78,6 +78,11 @@ class ReferralProgramPageObject(semanticsProvider: SemanticsNodeInteractionsProv
hasTestTag(BaseButtonTestTags.TEXT)
useUnmergedTree = true
}
val personalCodeCard: KNode = child {
hasTestTag(ReferralProgramScreenTestTags.PERSONAL_CODE_CARD)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onReferralProgramScreen(function: ReferralProgramPageObject.() -> Unit) =

View file

@ -9,6 +9,7 @@ import com.tangem.core.ui.test.BaseButtonTestTags
import com.tangem.core.ui.test.NotificationTestTags
import com.tangem.core.ui.test.TokenDetailsScreenTestTags
import com.tangem.features.tokendetails.impl.R
import com.tangem.core.res.R as CoreResR
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
@ -62,6 +63,33 @@ class TokenDetailsPageObject(semanticsProvider: SemanticsNodeInteractionsProvide
hasText(getResourceString(R.string.staking_enabled))
}
val yieldSupplyAvailableBlock: KNode = child {
hasTestTag(TokenDetailsScreenTestTags.YIELD_SUPPLY_AVAILABLE_BLOCK)
useUnmergedTree = true
}
val yieldSupplyActiveBlock: KNode = child {
hasTestTag(TokenDetailsScreenTestTags.YIELD_SUPPLY_BLOCK)
useUnmergedTree = true
}
val earnBlockTitleIcon: KNode = child {
hasTestTag(TokenDetailsScreenTestTags.EARN_BLOCK_TITLE_ICON)
useUnmergedTree = true
}
val yieldModeConnectedTitle: KNode = child {
hasAnyAncestor(withTestTag(TokenDetailsScreenTestTags.YIELD_SUPPLY_BLOCK))
hasText(getResourceString(CoreResR.string.yield_module_transaction_enter))
useUnmergedTree = true
}
fun yieldModeApy(apy: String): KNode = child {
hasAnyAncestor(withTestTag(TokenDetailsScreenTestTags.YIELD_SUPPLY_BLOCK))
hasText(getResourceString(CoreResR.string.yield_module_average_apy, apy))
useUnmergedTree = true
}
val title: KNode = child {
hasTestTag(TokenDetailsScreenTestTags.TOKEN_TITLE)
}
@ -90,6 +118,11 @@ class TokenDetailsPageObject(semanticsProvider: SemanticsNodeInteractionsProvide
useUnmergedTree = true
}
/** 'Receive' row of the zero-balance actions block (Buy / Swap / Receive), shown instead of the action buttons. */
val receiveButton: KNode = child {
hasText(getResourceString(R.string.common_receive))
}
fun networkFeeNotificationIcon(feeCurrencyName: String): KNode = child {
hasAnySibling(withText(getResourceString(R.string.warning_send_blocked_funds_for_fee_title, feeCurrencyName)))
hasTestTag(NotificationTestTags.ICON)
@ -114,6 +147,12 @@ class TokenDetailsPageObject(semanticsProvider: SemanticsNodeInteractionsProvide
useUnmergedTree = true
}
fun tokenTitle(name: String): KNode = child {
hasTestTag(TokenDetailsScreenTestTags.TOKEN_TITLE)
hasAnyDescendant(withText(text = name, substring = true))
useUnmergedTree = true
}
fun networkFeeNotificationMessage(
currencyName: String,
networkName: String,

View file

@ -0,0 +1,40 @@
package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.TokenMarketBlockTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
class TokenMarketBlockPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TokenMarketBlockPageObject>(semanticsProvider = semanticsProvider) {
val block: KNode = child {
hasTestTag(TokenMarketBlockTestTags.BLOCK)
useUnmergedTree = true
}
val title: KNode = child {
hasTestTag(TokenMarketBlockTestTags.TITLE)
useUnmergedTree = true
}
val price: KNode = child {
hasTestTag(TokenMarketBlockTestTags.PRICE)
useUnmergedTree = true
}
val priceChange: KNode = child {
hasTestTag(TokenMarketBlockTestTags.PRICE_CHANGE)
useUnmergedTree = true
}
val chart: KNode = child {
hasTestTag(TokenMarketBlockTestTags.CHART)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTokenMarketBlock(function: TokenMarketBlockPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -1,11 +1,14 @@
package com.tangem.screens
import android.graphics.Bitmap
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import androidx.compose.ui.test.captureToImage
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.BaseBottomSheetTestTags
import com.tangem.core.ui.test.BaseButtonTestTags
import com.tangem.core.ui.test.TokenReceiveQrCodeBottomSheetTestTags
import com.tangem.wallet.R
import io.github.kakaocup.compose.intercept.operation.ComposeOperationType
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
@ -40,16 +43,25 @@ class TokenReceiveQrCodeBottomSheetPageObject(semanticsProvider: SemanticsNodeIn
}
val copyButton: KNode = child {
hasTestTag(BaseButtonTestTags.TEXT)
hasText(getResourceString(R.string.common_copy))
useUnmergedTree = true
hasClickAction()
}
val shareButton: KNode = child {
hasTestTag(BaseButtonTestTags.TEXT)
hasText(getResourceString(R.string.common_share))
useUnmergedTree = true
hasClickAction()
}
/** Captures the QR code node as a bitmap via the Kakao node delegate (no raw composeTestRule access). */
fun captureQrCodeBitmap(): Bitmap {
lateinit var bitmap: Bitmap
qrCode.delegate.perform(QrCodeAction.CAPTURE) {
bitmap = captureToImage().asAndroidBitmap()
}
return bitmap
}
private enum class QrCodeAction : ComposeOperationType { CAPTURE }
}
internal fun BaseTestCase.onTokenReceiveQrCodeBottomSheet(function: TokenReceiveQrCodeBottomSheetPageObject.() -> Unit) =

View file

@ -3,7 +3,6 @@ package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.R
import com.tangem.core.ui.test.BaseButtonTestTags
import com.tangem.core.ui.test.TokenReceiveWarningBottomSheetTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
@ -18,8 +17,11 @@ class TokenReceiveWarningBottomSheetPageObject(semanticsProvider: SemanticsNodeI
}
val gotItButton: KNode = child {
hasTestTag(BaseButtonTestTags.TEXT)
hasText(getResourceString(R.string.common_got_it))
}
fun networkName(name: String): KNode = child {
hasText(text = name, substring = true)
useUnmergedTree = true
}
}

View file

@ -31,6 +31,16 @@ class TxHistoryPageObject(semanticsProvider: SemanticsNodeInteractionsProvider)
hasTestTag(TransactionHistoryItemTestTags.STATUS_CONFIRMED)
useUnmergedTree = true
}
fun transactionUnconfirmedStatus(title: String): KNode = transactionItem(title).child {
hasTestTag(TransactionHistoryItemTestTags.STATUS_UNCONFIRMED)
useUnmergedTree = true
}
fun transactionAddress(title: String, address: String): KNode = transactionItem(title).child {
hasText(text = address, substring = true)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTxHistoryScreen(function: TxHistoryPageObject.() -> Unit) =

View file

@ -0,0 +1,36 @@
package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.BaseButtonTestTags
import com.tangem.core.ui.test.NotificationTestTags
import com.tangem.core.ui.test.YieldSupplyTestTags
import com.tangem.core.res.R as CoreResR
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
class YieldSupplyActivePageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<YieldSupplyActivePageObject>(semanticsProvider = semanticsProvider) {
val stopEarningButton: KNode = child {
hasTestTag(YieldSupplyTestTags.STOP_EARNING_BUTTON)
useUnmergedTree = true
}
val approveButton: KNode = child {
hasTestTag(BaseButtonTestTags.TEXT)
hasText(getResourceString(CoreResR.string.yield_module_approve_needed_notification_cta))
useUnmergedTree = true
}
fun notificationTitle(title: String): KNode = child {
hasTestTag(NotificationTestTags.TITLE)
hasText(title)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onYieldSupplyActiveScreen(function: YieldSupplyActivePageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,20 @@
package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.YieldSupplyTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
class YieldSupplyApprovePageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<YieldSupplyApprovePageObject>(semanticsProvider = semanticsProvider) {
val confirmButton: KNode = child {
hasTestTag(YieldSupplyTestTags.APPROVE_CONFIRM_BUTTON)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onYieldSupplyApproveScreen(function: YieldSupplyApprovePageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,20 @@
package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.YieldSupplyTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
class YieldSupplyPromoPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<YieldSupplyPromoPageObject>(semanticsProvider = semanticsProvider) {
val continueButton: KNode = child {
hasTestTag(YieldSupplyTestTags.PROMO_CONTINUE_BUTTON)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onYieldSupplyPromoScreen(function: YieldSupplyPromoPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,20 @@
package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.YieldSupplyTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
class YieldSupplyStartEarningPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<YieldSupplyStartEarningPageObject>(semanticsProvider = semanticsProvider) {
val startEarningButton: KNode = child {
hasTestTag(YieldSupplyTestTags.START_EARNING_BUTTON)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onYieldSupplyStartEarningScreen(function: YieldSupplyStartEarningPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,20 @@
package com.tangem.screens
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.YieldSupplyTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
class YieldSupplyStopEarningPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<YieldSupplyStopEarningPageObject>(semanticsProvider = semanticsProvider) {
val confirmButton: KNode = child {
hasTestTag(YieldSupplyTestTags.STOP_EARNING_CONFIRM_BUTTON)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onYieldSupplyStopEarningScreen(function: YieldSupplyStopEarningPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -17,7 +17,7 @@ class TangemPayAddFundsSheetPageObject(semanticsProvider: SemanticsNodeInteracti
}
val receiveOption: KNode = child {
hasText(getResourceString(CoreResR.string.common_receive))
hasText(getResourceString(CoreResR.string.tangempay_topup_receive_title))
useUnmergedTree = true
}

View file

@ -2,14 +2,39 @@ package com.tangem.screens.tangempay
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.res.R as CoreResR
import com.tangem.core.ui.test.TangemPayTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
class TangemPayCardPagePageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TangemPayCardPagePageObject>(semanticsProvider = semanticsProvider) {
val moreButton: KNode = child {
hasTestTag(TangemPayTestTags.CARD_PAGE_MORE_BUTTON)
useUnmergedTree = true
}
val replaceCardMenuItem: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_card_details_reissue_card))
useUnmergedTree = true
}
val cardNumberShort: KNode = child {
hasTestTag(TangemPayTestTags.CARD_NUMBER_SHORT)
useUnmergedTree = true
}
val reissueInProgressBlock: KNode = child {
hasText(
text = getResourceString(CoreResR.string.tangempay_reissue_card_in_progress),
substring = true,
)
useUnmergedTree = true
}
val changePinRow: KNode = child {
hasTestTag(TangemPayTestTags.CHANGE_PIN_ROW)
useUnmergedTree = true
@ -64,6 +89,16 @@ class TangemPayCardPagePageObject(semanticsProvider: SemanticsNodeInteractionsPr
hasTestTag(TangemPayTestTags.CARD_DETAILS_COPY_CVC)
useUnmergedTree = true
}
val dailyLimitChangeButton: KNode = child {
hasTestTag(TangemPayTestTags.DAILY_LIMIT_CHANGE_BUTTON)
useUnmergedTree = true
}
val dailyLimitValue: KNode = child {
hasTestTag(TangemPayTestTags.DAILY_LIMIT_CURRENT_VALUE)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTangemPayCardPageScreen(function: TangemPayCardPagePageObject.() -> Unit) =

View file

@ -0,0 +1,47 @@
package com.tangem.screens.tangempay
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.SendScreenTestTags
import com.tangem.core.ui.test.TangemPayTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
class TangemPayDailyLimitPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TangemPayDailyLimitPageObject>(semanticsProvider = semanticsProvider) {
// AmountTextField tags its editable field with SendScreenTestTags.INPUT_TEXT_FIELD; it's the only one here.
val amountField: KNode = child {
hasTestTag(SendScreenTestTags.INPUT_TEXT_FIELD)
useUnmergedTree = true
}
val hint: KNode = child {
hasTestTag(TangemPayTestTags.DAILY_LIMIT_HINT)
useUnmergedTree = true
}
val setLimitsButton: KNode = child {
hasTestTag(TangemPayTestTags.DAILY_LIMIT_SET_BUTTON)
useUnmergedTree = true
}
val successTitle: KNode = child {
hasTestTag(TangemPayTestTags.DAILY_LIMIT_SUCCESS_TITLE)
useUnmergedTree = true
}
val doneButton: KNode = child {
hasTestTag(TangemPayTestTags.DAILY_LIMIT_DONE_BUTTON)
useUnmergedTree = true
}
fun presetChip(rawValue: String): KNode = child {
hasTestTag(TangemPayTestTags.dailyLimitPresetChip(rawValue))
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTangemPayDailyLimitScreen(function: TangemPayDailyLimitPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,33 @@
package com.tangem.screens.tangempay
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.WarningBottomSheetTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import androidx.compose.ui.test.hasText as withText
class TangemPayKycSheetPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TangemPayKycSheetPageObject>(semanticsProvider = semanticsProvider) {
fun title(text: String): KNode = child {
hasTestTag(WarningBottomSheetTestTags.TITLE)
hasText(text)
useUnmergedTree = true
}
fun primaryButtonWithText(text: String): KNode = child {
hasTestTag(WarningBottomSheetTestTags.BUTTON_PRIMARY)
hasAnyDescendant(withText(text))
useUnmergedTree = true
}
val closeButton: KNode = child {
hasTestTag(WarningBottomSheetTestTags.CLOSE_BUTTON)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTangemPayKycSheet(function: TangemPayKycSheetPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -4,6 +4,7 @@ import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.BaseActionButtonsBlockTestTags
import com.tangem.core.ui.test.TangemPayTestTags
import com.tangem.core.ui.test.TokenDetailsTopBarTestTags
import com.tangem.core.res.R as CoreResR
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
@ -19,6 +20,12 @@ class TangemPayMainPageObject(semanticsProvider: SemanticsNodeInteractionsProvid
useUnmergedTree = true
}
fun tileWithSubtitle(subtitle: String): KNode = child {
hasTestTag(TangemPayTestTags.MAIN_SCREEN_TILE)
hasAnyDescendant(withText(subtitle))
useUnmergedTree = true
}
val balance: KNode = child {
hasTestTag(TangemPayTestTags.PAYMENT_ACCOUNT_BALANCE)
useUnmergedTree = true
@ -41,10 +48,27 @@ class TangemPayMainPageObject(semanticsProvider: SemanticsNodeInteractionsProvid
useUnmergedTree = true
}
val moreActionsButton: KNode = child {
hasTestTag(TokenDetailsTopBarTestTags.MORE_BUTTON)
useUnmergedTree = true
}
val termsAndFeesMenuItem: KNode = child {
hasText(getResourceString(CoreResR.string.tangem_pay_terms_limits))
}
fun transactionRowWithText(text: String): KNode = child {
hasText(text)
useUnmergedTree = true
}
val reissueInProgressBanner: KNode = child {
hasText(
text = getResourceString(CoreResR.string.tangempay_reissue_card_in_progress),
substring = true,
)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTangemPayMainScreen(function: TangemPayMainPageObject.() -> Unit) =

View file

@ -0,0 +1,21 @@
package com.tangem.screens.tangempay
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.res.R as CoreResR
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
class TangemPayOnboardingPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TangemPayOnboardingPageObject>(semanticsProvider = semanticsProvider) {
val title: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_onboarding_title))
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTangemPayOnboardingScreen(function: TangemPayOnboardingPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,62 @@
package com.tangem.screens.tangempay
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.res.R as CoreResR
import com.tangem.core.ui.test.TangemPayTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
class TangemPayReissueSheetPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TangemPayReissueSheetPageObject>(semanticsProvider = semanticsProvider) {
val title: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_reissue_card_title))
useUnmergedTree = true
}
val description: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_reissue_card_description))
useUnmergedTree = true
}
val feeLabel: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_reissue_card_fee_label))
useUnmergedTree = true
}
val feeValue: KNode = child {
hasTestTag(TangemPayTestTags.REISSUE_SHEET_FEE_VALUE)
useUnmergedTree = true
}
val confirmButton: KNode = child {
hasTestTag(TangemPayTestTags.REISSUE_SHEET_CONFIRM_BUTTON)
useUnmergedTree = true
}
val feeErrorTitle: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_reissue_card_fee_unreachable_error_title))
useUnmergedTree = true
}
val refreshButton: KNode = child {
hasText(getResourceString(CoreResR.string.warning_button_refresh))
useUnmergedTree = true
}
val insufficientFundsTitle: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_reissue_card_insufficient_funds_title))
useUnmergedTree = true
}
val addFundsButton: KNode = child {
hasText(getResourceString(CoreResR.string.tangempay_card_details_add_funds))
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTangemPayReissueSheet(function: TangemPayReissueSheetPageObject.() -> Unit) =
onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,36 @@
package com.tangem.screens.tangempay
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.ui.test.WarningBottomSheetTestTags
import com.tangem.core.res.R as CoreResR
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
class TangemPayServiceUnavailableSheetPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TangemPayServiceUnavailableSheetPageObject>(semanticsProvider = semanticsProvider) {
val title: KNode = child {
hasTestTag(WarningBottomSheetTestTags.TITLE)
hasText(getResourceString(CoreResR.string.tangempay_service_unavailable_title))
useUnmergedTree = true
}
val description: KNode = child {
hasTestTag(WarningBottomSheetTestTags.MESSAGE)
hasText(getResourceString(CoreResR.string.tangempay_service_unavailable_description))
useUnmergedTree = true
}
// Merged tree: BUTTON_PRIMARY tags the button, its label is a child — only the merged node has both.
val gotItButton: KNode = child {
hasTestTag(WarningBottomSheetTestTags.BUTTON_PRIMARY)
hasText(getResourceString(CoreResR.string.common_got_it))
}
}
internal fun BaseTestCase.onTangemPayServiceUnavailableSheet(
function: TangemPayServiceUnavailableSheetPageObject.() -> Unit,
) = onComposeScreen(composeTestRule, function)

View file

@ -0,0 +1,33 @@
package com.tangem.screens.tangempay
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
import com.tangem.common.BaseTestCase
import com.tangem.core.res.R as CoreResR
import com.tangem.core.ui.test.TangemPayTestTags
import io.github.kakaocup.compose.node.element.ComposeScreen
import io.github.kakaocup.compose.node.element.ComposeScreen.Companion.onComposeScreen
import io.github.kakaocup.compose.node.element.KNode
import io.github.kakaocup.kakao.common.utilities.getResourceString
class TangemPayTransactionDetailsSheetPageObject(semanticsProvider: SemanticsNodeInteractionsProvider) :
ComposeScreen<TangemPayTransactionDetailsSheetPageObject>(semanticsProvider = semanticsProvider) {
val feeTitle: KNode = child {
hasText(getResourceString(CoreResR.string.tangem_pay_fee_title))
useUnmergedTree = true
}
val serviceFeesCategory: KNode = child {
hasText(getResourceString(CoreResR.string.tangem_pay_fee_subtitle))
useUnmergedTree = true
}
val amount: KNode = child {
hasTestTag(TangemPayTestTags.TRANSACTION_DETAILS_AMOUNT)
useUnmergedTree = true
}
}
internal fun BaseTestCase.onTangemPayTransactionDetailsSheet(
function: TangemPayTransactionDetailsSheetPageObject.() -> Unit,
) = onComposeScreen(composeTestRule, function)

View file

@ -59,15 +59,15 @@ class AppCurrencyTest : BaseTestCase() {
onAppSettingsScreen { currencyButton.assertIsDisplayed() }
}
}
step("Return to 'Details' screen") {
waitForIdle()
device.uiDevice.pressBack()
step("Return to 'Details' screen via 'Back' button") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) {
onAppSettingsScreen { backButton.clickWithAssertion() }
onDetailsScreen { screenContainer.assertIsDisplayed() }
}
}
step("Return to 'Main' screen via 'Back' button") {
onDetailsScreen { topAppBarBackButton.clickWithAssertion() }
}
step("Assert 'Main' screen is opened") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) {
onDetailsScreen { topAppBarBackButton.clickWithAssertion() }
onMainScreen { screenContainer.assertIsDisplayed() }
}
}

View file

@ -21,11 +21,13 @@ import dagger.hilt.android.testing.HiltAndroidTest
import io.github.kakaocup.kakao.common.utilities.getResourceString
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Ignore
import org.junit.Test
@HiltAndroidTest
class BlockchainTest : BaseTestCase() {
@Ignore("[REDACTED_JIRA]")
@AllureId("3644")
@DisplayName("ADA: Checking the min amount/change = 1ADA")
@Test

View file

@ -9,6 +9,7 @@ import com.tangem.common.extensions.clickAndWaitFor
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.core.analytics.models.AnalyticsParam
import com.tangem.domain.card.ScanFailsRequester
import com.tangem.domain.models.scan.ProductType
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import com.tangem.scenarios.checkFailedTransactionDialog
@ -196,4 +197,68 @@ class FeedbackTest : BaseTestCase() {
}
}
}
@AllureId("3960")
@DisplayName("Send feedback: Failed card scanning on Details screen")
@Test
fun sendFeedbackFailedScanningOnDetails() {
val gmailText = "Welcome to Gmail"
setupHooks(
additionalAfterSection = {
device.uiDevice.pressBack()
MockProvider.resetEmulateError()
}
).run {
step("Open 'Main Screen'") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Open 'Details screen'") {
onMainScreenTopBar { moreButton.clickWithAssertion() }
}
step("Set scanning error (the next card scan will fail with TagLost)") {
MockProvider.setEmulateError(TangemSdkError.TagLost())
}
step("Click 'Add new wallet' button") {
onDetailsScreen { addWalletButton.clickWithAssertion() }
}
step("Force show 'Scan warning' dialog"){
waitForIdle()
runOnUiThread {
MainScope().launch {
scanFailsRequester.show(AnalyticsParam.ScreensSources.Main)
}
}
}
step("Check 'Scan warning' dialog") {
waitForIdle()
checkScanWarningDialog()
}
step("Click on 'Request support' button") {
onScanWarningDialog { requestSupportButton.performClick() }
}
step("Assert 'Gmail' app is open") {
ThirdPartyAppPageObject { assertElementWithTextExists(gmailText) }
}
}
}
@AllureId("3603")
@DisplayName("Send feedback: S2C card has Contact support option")
@Test
fun sendFeedbackForS2CTest() {
setupHooks().run {
step("Open 'Main Screen'") {
openMainScreen(productType = ProductType.Start2Coin)
}
step("Open 'Details screen'") {
onMainScreenTopBar { moreButton.clickWithAssertion() }
}
step("Verify 'Contact support' button is displayed") {
onDetailsScreen { contactSupportButton.assertIsDisplayed() }
}
}
}
}

View file

@ -23,9 +23,9 @@ class SendTest : BaseTestCase() {
val currencyName = "USDC"
val feeCurrencyName = "Solana"
val feeCurrencySymbol = "SOL"
val balanceScenarioName = "solana_balance"
val balanceScenarioName = "solana_get_account_info_recipient"
val tokensScenarioName = "user_tokens_api"
val balanceState = "Empty"
val balanceState = "ZeroBalance"
val tokensState = "SolanaUSDC"
setupHooks(

View file

@ -503,6 +503,9 @@ class MainScreenActionButtonsTest : BaseTestCase() {
step("Click on 'Swap' button") {
onMainScreen { swapButton.performClick() }
}
step("Skip stories if displayed") {
skipSwapStories()
}
step("Check 'Action is unavailable' dialog") {
flakySafely(WAIT_UNTIL_TIMEOUT) {
checkActionIsUnavailableDialog()

View file

@ -1,25 +1,42 @@
package com.tangem.tests.actionButtons
import com.tangem.common.BaseTestCase
import com.tangem.common.constants.TestConstants.QUOTES_API_SCENARIO
import com.tangem.common.constants.TestConstants.SVS_SEED_PHRASE_12
import com.tangem.common.constants.TestConstants.USER_TOKENS_API_SCENARIO
import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT
import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT_LONG
import com.tangem.common.constants.TestConstants.XRP_RECIPIENT_ADDRESS
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.common.extensions.pullToRefresh
import com.tangem.common.utils.resetWireMockScenarioState
import com.tangem.common.utils.setWireMockScenarioState
import com.tangem.core.ui.R
import com.tangem.scenarios.checkQrCodeBottomSheetScenario
import com.tangem.scenarios.enterAmountAndOpenSendConfirm
import com.tangem.scenarios.goToQrCodeBottomSheet
import com.tangem.scenarios.openMainScreen
import com.tangem.scenarios.openSendFromTokenDetails
import com.tangem.scenarios.openSendScreenWithHotWallet
import com.tangem.scenarios.openSendSuccessScreenViaLongClickOnSendButton
import com.tangem.scenarios.readNetworkFeeAmount
import com.tangem.scenarios.synchronizeAddresses
import com.tangem.scenarios.waitUntilNetworkFeeIsStable
import com.tangem.screens.onAddFundsBottomSheet
import com.tangem.screens.onDialog
import com.tangem.screens.onMainScreen
import com.tangem.screens.onSendScreen
import com.tangem.screens.onSendSuccessScreen
import com.tangem.screens.onSwapStoriesScreen
import com.tangem.screens.onSwapTokenScreen
import com.tangem.screens.onTokenDetailsScreen
import com.tangem.screens.onTransferBottomSheet
import com.tangem.screens.onTxHistoryScreen
import dagger.hilt.android.testing.HiltAndroidTest
import io.github.kakaocup.kakao.common.utilities.getResourceString
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Ignore
import org.junit.Test
@HiltAndroidTest
@ -28,6 +45,7 @@ class TokenDetailsScreenActionButtonsTest : BaseTestCase() {
@AllureId("594")
@DisplayName("Action buttons (token details screen): validate UI")
@Test
@Ignore("[REDACTED_JIRA]")
fun actionButtonsValidateUiTest() {
val tokenTitle = "Bitcoin"
@ -110,10 +128,13 @@ class TokenDetailsScreenActionButtonsTest : BaseTestCase() {
step("Click on 'Add funds' button") {
onTokenDetailsScreen { addFundsButton.clickWithAssertion() }
}
step("Assert 'Get $tokenTitle' bottom-sheet is displayed") {
onAddFundsBottomSheet { titleWithTokenName(tokenTitle).assertIsDisplayed() }
}
step("Assert 'Buy' button in bottom sheet is enabled") {
onAddFundsBottomSheet { buyButton.assertIsEnabled() }
}
step("Assert 'Swap' button in bottom sheet is disabled") {
step("Assert 'Swap' button in bottom sheet is not enabled") {
onAddFundsBottomSheet { swapButton.assertIsNotEnabled() }
}
step("Assert 'Receive' button in bottom sheet is enabled") {
@ -257,4 +278,146 @@ class TokenDetailsScreenActionButtonsTest : BaseTestCase() {
}
}
}
@AllureId("4465")
@DisplayName("Action buttons (token details screen): 'Send' blocked while a transaction is active, works after completion")
@Test
fun sendBlockedWhileTransactionActiveTest() {
val tokenName = "XRP Ledger"
val amount = "1"
val userTokensState = "XRPHotWalletSvS"
val quotesState = "Ripple"
val startedState = "Started"
val rippleAccountInfoScenario = "ripple_account_info"
val pendingSendMessagePrefix =
getResourceString(R.string.token_button_unavailability_reason_pending_transaction_send).substringBefore("%")
setupHooks(
additionalAfterSection = {
resetWireMockScenarioState(USER_TOKENS_API_SCENARIO)
resetWireMockScenarioState(QUOTES_API_SCENARIO)
resetWireMockScenarioState(rippleAccountInfoScenario)
},
).run {
step("Set WireMock scenario: '$USER_TOKENS_API_SCENARIO' to state: '$userTokensState'") {
setWireMockScenarioState(scenarioName = USER_TOKENS_API_SCENARIO, state = userTokensState)
}
step("Set WireMock scenario: '$QUOTES_API_SCENARIO' to state: '$quotesState'") {
setWireMockScenarioState(scenarioName = QUOTES_API_SCENARIO, state = quotesState)
}
step("Set WireMock scenario: '$rippleAccountInfoScenario' to state: '$startedState'") {
setWireMockScenarioState(scenarioName = rippleAccountInfoScenario, state = startedState)
}
step("Open the send flow for '$tokenName' on an existing hot wallet") {
openSendScreenWithHotWallet(seedPhrase = SVS_SEED_PHRASE_12, tokenName = tokenName)
}
step("Enter amount '$amount' and open the 'Send confirm' screen") {
enterAmountAndOpenSendConfirm(amount = amount, recipientAddress = XRP_RECIPIENT_ADDRESS)
}
waitUntilNetworkFeeIsStable { readNetworkFeeAmount() }
step("Sign, send and open the 'Transaction sent' screen") {
openSendSuccessScreenViaLongClickOnSendButton()
}
step("Click on 'Close' button") {
onSendSuccessScreen { closeButton.clickWithAssertion() }
}
step("Assert 'Token details' screen is displayed") {
onTokenDetailsScreen { screenContainer.assertIsDisplayed() }
}
step("Open the transfer bottom sheet") {
onTokenDetailsScreen { transferButton.clickWithAssertion() }
}
step("Assert 'Send' button is not enabled while the transaction is active") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) {
onTransferBottomSheet { sendButton.assertIsNotEnabled() }
}
}
step("Click on 'Send' button") {
onTransferBottomSheet { sendButton.performClick() }
}
step("Assert pending-transaction notification dialog is displayed") {
onDialog { containerWithText(pendingSendMessagePrefix).assertIsDisplayed() }
}
step("Assert 'Send' screen is not opened") {
onSendScreen { amountInputTextField.assertDoesNotExist() }
}
// Tapping the 'Send' row dismisses the transfer bottom sheet (onActionDispatched) before the dialog shows.
step("Close the notification dialog") {
onDialog { okButton.clickWithAssertion() }
}
step("Pull to refresh to complete the active transaction") {
pullToRefresh()
}
step("Open the transfer bottom sheet again") {
onTokenDetailsScreen { transferButton.clickWithAssertion() }
}
step("Assert 'Send' button is enabled after the transaction is completed") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) {
onTransferBottomSheet { sendButton.assertIsEnabled() }
}
}
step("Click on 'Send' button") {
onTransferBottomSheet { sendButton.performClick() }
}
step("Assert 'Send' screen is displayed") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) {
onSendScreen { amountInputTextField.assertIsDisplayed() }
}
}
}
}
@AllureId("10209")
@DisplayName("Action buttons (token details screen): 'Send' unavailable for a zero-balance token with an active transaction")
@Test
fun sendUnavailableForZeroBalanceWithActiveTransactionTest() {
val tokenName = "Dogecoin"
val zeroBalanceState = "ZeroBalance"
val activeTxHistoryState = "UnconfirmedOutgoing"
val balanceScenarioName = "dogecoin_balance"
val txHistoryScenarioName = "dogecoin_tx_history"
val sendingTitle = getResourceString(R.string.common_sending)
setupHooks(
additionalAfterSection = {
resetWireMockScenarioState(USER_TOKENS_API_SCENARIO)
resetWireMockScenarioState(QUOTES_API_SCENARIO)
resetWireMockScenarioState(balanceScenarioName)
resetWireMockScenarioState(txHistoryScenarioName)
}
).run {
step("Set WireMock scenario: '$USER_TOKENS_API_SCENARIO' to state: '$tokenName'") {
setWireMockScenarioState(scenarioName = USER_TOKENS_API_SCENARIO, state = tokenName)
}
step("Set WireMock scenario: '$QUOTES_API_SCENARIO' to state: '$tokenName'") {
setWireMockScenarioState(scenarioName = QUOTES_API_SCENARIO, state = tokenName)
}
step("Set WireMock scenario: '$balanceScenarioName' to state: '$zeroBalanceState'") {
setWireMockScenarioState(scenarioName = balanceScenarioName, state = zeroBalanceState)
}
step("Set WireMock scenario: '$txHistoryScenarioName' to state: '$activeTxHistoryState'") {
setWireMockScenarioState(scenarioName = txHistoryScenarioName, state = activeTxHistoryState)
}
step("Open 'Main Screen'") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Click on token with name: '$tokenName'") {
onMainScreen { tokenWithTitleAndAddress(tokenName).clickWithAssertion() }
}
step("Assert 'Token details' screen is displayed") {
onTokenDetailsScreen { screenContainer.assertIsDisplayed() }
}
step("Assert active outgoing '$sendingTitle' transaction block is displayed") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) {
onTxHistoryScreen { transactionItem(sendingTitle).assertIsDisplayed() }
}
}
step("Assert 'Transfer' button is not displayed for the zero-balance token") {
onTokenDetailsScreen { transferButton.assertIsNotDisplayed() }
}
}
}
}

View file

@ -3,6 +3,7 @@ package com.tangem.tests.addFunds
import com.tangem.common.BaseTestCase
import com.tangem.common.extensions.assertTextContainsSafe
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.domain.models.scan.ProductType
import com.tangem.scenarios.openMainScreen
import com.tangem.scenarios.synchronizeAddresses
import com.tangem.screens.onAddTokenBottomSheet
@ -11,6 +12,7 @@ import com.tangem.screens.onBuyTokenDetailsScreen
import com.tangem.screens.onMainScreen
import dagger.hilt.android.testing.HiltAndroidTest
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.Issue
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Test
@ -66,8 +68,8 @@ class BuyTest : BaseTestCase() {
step("Click on $token in Trending list") {
onAddFundsBottomSheet { trendingTokenWithTitle(token).clickWithAssertion() }
}
step("Click on 'Add' button") {
onAddTokenBottomSheet { addButton.clickWithAssertion() }
step("Click on 'Confirm' button") {
onAddTokenBottomSheet { confirmButton.clickWithAssertion() }
}
step("Close 'Get token' screen") {
onAddFundsBottomSheet { closeButton.clickWithAssertion() }
@ -83,4 +85,24 @@ class BuyTest : BaseTestCase() {
}
}
}
@AllureId("3613")
@DisplayName("On-ramp Buy: S2C card doesn't have Buy and Sell options")
@Test
@Issue("[REDACTED_TASK_KEY]")
fun buyAndSellIsNotAvailableForS2CCardTest() {
setupHooks().run {
step("Open 'Main' screen") {
openMainScreen(productType = ProductType.Start2Coin)
}
step("Verify 'Add funds' button is displayed") {
onMainScreen { addFundsButton.assertIsDisplayed() }
}
step("Verify Buy/Sell action buttons are hidden") {
onMainScreen {
buyButton.assertDoesNotExist()
}
}
}
}
}

View file

@ -86,9 +86,9 @@ class TotalBalanceUpdateTest : BaseTestCase() {
step("Click on 'Add' button in 'Markets' bottom sheet") {
onMarketsScreen { addButton.clickWithAssertion() }
}
step("Click on 'Add' button in 'Add token' bottom sheet") {
step("Click on 'Confirm' button in 'Add token' bottom sheet") {
flakySafely(WAIT_UNTIL_TIMEOUT) {
onAddTokenBottomSheet { addButton.performClick() }
onAddTokenBottomSheet { confirmButton.performClick() }
}
}
step("Press 'Back' button") {

View file

@ -0,0 +1,274 @@
package com.tangem.tests.main
import com.tangem.common.BaseTestCase
import com.tangem.common.constants.TestConstants.COINS_API_SCENARIO
import com.tangem.common.constants.TestConstants.WAIT_UNTIL_TIMEOUT_LONG
import com.tangem.common.extensions.performTextInputInChunks
import com.tangem.common.utils.resetWireMockScenarioState
import com.tangem.common.utils.setWireMockScenarioState
import com.tangem.domain.models.scan.ProductType
import com.tangem.scenarios.addCustomTokenWithCustomDerivation
import com.tangem.scenarios.assertDerivationPathsInSelector
import com.tangem.scenarios.navigateBackToMainFromManageTokens
import com.tangem.scenarios.openAddCustomToken
import com.tangem.scenarios.openMainScreen
import com.tangem.scenarios.synchronizeAddresses
import com.tangem.screens.onAddCustomTokenScreen
import com.tangem.screens.onMainScreen
import com.tangem.tap.domain.sdk.mocks.content.Wallet1LegacyDerivationMockContent
import com.tangem.tap.domain.sdk.mocks.content.Wallet2NoEd25519Slip0010MockContent
import dagger.hilt.android.testing.HiltAndroidTest
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Assert.assertFalse
import org.junit.Test
@HiltAndroidTest
class AddCustomTokenTest : BaseTestCase() {
private val richState = "ManageTokensRich"
private val tokenTitle = "Tether"
private val ethereumNetwork = "Ethereum"
private val solanaNetwork = "Solana"
private val bitcoinNetworkId = "bitcoin"
private val ethereumClassicNetworkId = "ethereum-classic"
private val ethContract = "0xdac17f958d2ee523a2206206994597c13d831ec7"
private val solanaContract = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
private val customDerivationPath = "m/44'/60'/0'/0/1"
@AllureId("772")
@DisplayName("Add custom token: added token appears on Main")
@Test
fun addCustomTokenAppearsOnMainTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Synchronize addresses") {
flakySafely { onMainScreen { synchronizeAddressesButton.assertIsDisplayed() } }
synchronizeAddresses(assertBalance = false)
}
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Click on network: '$ethereumNetwork'") {
flakySafely { onAddCustomTokenScreen { scrollToNetwork(ethereumNetwork) } }
onAddCustomTokenScreen { networkRow(ethereumNetwork).performClick() }
}
step("Enter contract address: '$ethContract'") {
flakySafely { onAddCustomTokenScreen { contractAddressField.assertExists() } }
// Chunked input spans several validation ticks — the model drops the first sampled form change.
onAddCustomTokenScreen { contractAddressField.performTextInputInChunks(ethContract) }
}
step("Click on 'Add token' button") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) { onAddCustomTokenScreen { addTokenButton.assertIsEnabled() } }
onAddCustomTokenScreen { addTokenButton.performClick() }
}
step("Navigate back to 'Main Screen'") { navigateBackToMainFromManageTokens() }
step("Assert token: '$tokenTitle' is displayed on Main") {
flakySafely { onMainScreen { tokenWithTitleAndAddress(tokenTitle).assertIsDisplayed() } }
}
}
}
@AllureId("775")
@DisplayName("Add custom token: custom derivation path is accepted")
@Test
fun addCustomTokenWithCustomDerivationTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Synchronize addresses") {
flakySafely { onMainScreen { synchronizeAddressesButton.assertIsDisplayed() } }
synchronizeAddresses(assertBalance = false)
}
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Add custom token with custom derivation on '$ethereumNetwork'") {
addCustomTokenWithCustomDerivation(
network = ethereumNetwork,
contract = ethContract,
derivationPath = customDerivationPath,
)
}
step("Assert token: '$tokenTitle' is displayed on Main") {
flakySafely { onMainScreen { tokenWithTitleAndAddress(tokenTitle).assertIsDisplayed() } }
}
}
}
@AllureId("771")
@DisplayName("Add custom token: custom derivation indicator is shown on Main")
@Test
fun customDerivationIndicatorOnMainTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Synchronize addresses") {
flakySafely { onMainScreen { synchronizeAddressesButton.assertIsDisplayed() } }
synchronizeAddresses(assertBalance = false)
}
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Add custom token with custom derivation on '$ethereumNetwork'") {
addCustomTokenWithCustomDerivation(
network = ethereumNetwork,
contract = ethContract,
derivationPath = customDerivationPath,
)
}
step("Assert custom derivation indicator for '$tokenTitle' is displayed on Main") {
flakySafely { onMainScreen { tokenWithCustomDerivationIcon(tokenTitle).assertIsDisplayed() } }
}
}
}
@AllureId("770")
@DisplayName("Add custom token: derivation field is available for a non-EVM network")
@Test
fun derivationAvailableForNonEvmNetworkTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Click on network: '$solanaNetwork'") {
flakySafely { onAddCustomTokenScreen { scrollToNetwork(solanaNetwork) } }
onAddCustomTokenScreen { networkRow(solanaNetwork).performClick() }
}
step("Assert 'Derivation path' field is available") {
flakySafely { onAddCustomTokenScreen { derivationSelectorField.assertExists() } }
}
}
}
@AllureId("769")
@DisplayName("Add custom token: Solana token on a modern card shows no unsupported warning")
@Test
fun solanaTokenModernCardNoWarningTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Click on network: '$solanaNetwork'") {
flakySafely { onAddCustomTokenScreen { scrollToNetwork(solanaNetwork) } }
onAddCustomTokenScreen { networkRow(solanaNetwork).performClick() }
}
step("Enter contract address: '$solanaContract'") {
flakySafely { onAddCustomTokenScreen { contractAddressField.assertExists() } }
onAddCustomTokenScreen { contractAddressField.performTextInputInChunks(solanaContract) }
}
step("Assert 'Add token' button is enabled") {
flakySafely(WAIT_UNTIL_TIMEOUT_LONG) { onAddCustomTokenScreen { addTokenButton.assertIsEnabled() } }
}
step("Assert unsupported-token warning is not displayed") {
onAddCustomTokenScreen { warningNotification.assertDoesNotExist() }
}
}
}
@AllureId("777")
@DisplayName("Add custom token: network with a missing curve is not offered")
@Test
fun missingCurveNetworkNotOfferedTest() {
val bitcoinNetwork = "Bitcoin"
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen(mockContent = Wallet2NoEd25519Slip0010MockContent) }
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Assert supported network '$bitcoinNetwork' is displayed") {
flakySafely { onAddCustomTokenScreen { scrollToNetwork(bitcoinNetwork) } }
}
step("Assert '$solanaNetwork' network is not displayed for the missing-curve card") {
onAddCustomTokenScreen { selectorList.assertIsDisplayed() }
val solanaOffered = runCatching { onAddCustomTokenScreen { scrollToNetwork(solanaNetwork) } }.isSuccess
assertFalse("'$solanaNetwork' should not be offered for a missing-curve card", solanaOffered)
}
}
}
@AllureId("776")
@DisplayName("Add custom token: derivation paths match a legacy-batch V1 Wallet card")
@Test
fun derivationPathsLegacyBatchWalletTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen(mockContent = Wallet1LegacyDerivationMockContent) }
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Assert V1 derivation paths are displayed in the selector") {
assertDerivationPathsInSelector(
ethereumNetwork,
bitcoinNetworkId to "m/44'/0'/0'/0/0",
ethereumClassicNetworkId to "m/44'/61'/0'/0/0",
)
}
}
}
@AllureId("10204")
@DisplayName("Add custom token: derivation paths match a V2 Wallet card")
@Test
fun derivationPathsWalletTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Assert V2 derivation paths are displayed in the selector") {
assertDerivationPathsInSelector(
ethereumNetwork,
bitcoinNetworkId to "m/44'/0'/0'/0/0",
ethereumClassicNetworkId to "m/44'/60'/0'/0/0",
)
}
}
}
@AllureId("10205")
@DisplayName("Add custom token: derivation paths match a V3 Wallet 2 card")
@Test
fun derivationPathsWallet2Test() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen(productType = ProductType.Wallet2) }
step("Open 'Add custom token' screen") { openAddCustomToken() }
step("Assert V3 derivation paths are displayed in the selector") {
assertDerivationPathsInSelector(
ethereumNetwork,
bitcoinNetworkId to "m/84'/0'/0'/0/0",
ethereumClassicNetworkId to "m/44'/61'/0'/0/0",
)
}
}
}
}

View file

@ -0,0 +1,250 @@
package com.tangem.tests.main
import androidx.compose.ui.test.longClick
import androidx.compose.ui.test.performTextInput
import com.tangem.common.BaseTestCase
import com.tangem.common.constants.TestConstants.COINS_API_SCENARIO
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.common.utils.assertClipboardIsEmpty
import com.tangem.common.utils.assertClipboardTextEquals
import com.tangem.common.utils.clearClipboard
import com.tangem.common.utils.resetWireMockScenarioState
import com.tangem.common.utils.setWireMockScenarioState
import com.tangem.scenarios.openMainScreen
import com.tangem.scenarios.openManageTokens
import com.tangem.scenarios.toggleTokenNetworkInManageTokens
import com.tangem.screens.onDialog
import com.tangem.screens.onManageTokensScreen
import com.tangem.tap.domain.sdk.mocks.content.Firmware451MockContent
import com.tangem.tap.domain.sdk.mocks.content.Wallet2NoEd25519Slip0010MockContent
import dagger.hilt.android.testing.HiltAndroidTest
import io.github.kakaocup.kakao.common.utilities.getResourceString
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Test
import com.tangem.core.res.R as CoreResR
@HiltAndroidTest
class ManageTokensTest : BaseTestCase() {
private val richState = "ManageTokensRich"
private val solanaTokenTitle = "USD Coin"
private val solanaNetworkTitle = "SOLANA"
private val solanaName = "Solana"
@AllureId("765")
@DisplayName("Manage tokens: network standard labels are shown for token networks")
@Test
fun networkStandardLabelsTest() {
val tokenTitle = "Tether"
val ethereum = "Ethereum"
val bnbSmartChain = "BNB Smart Chain"
val tron = "Tron"
val erc20 = "ERC20"
val bep20 = "BEP20"
val trc20 = "TRC20"
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Open 'Manage tokens' screen") { openManageTokens() }
step("Click on token: '$tokenTitle'") {
flakySafely { onManageTokensScreen { tokenItem(tokenTitle).assertIsDisplayed() } }
onManageTokensScreen { tokenItem(tokenTitle).performClick() }
}
step("Assert '$ethereum' network standard '$erc20' is displayed") {
flakySafely {
onManageTokensScreen { networkStandard(networkName = ethereum, standard = erc20).assertIsDisplayed() }
}
}
step("Assert '$bnbSmartChain' network standard '$bep20' is displayed") {
flakySafely {
onManageTokensScreen {
networkStandard(networkName = bnbSmartChain, standard = bep20).assertIsDisplayed()
}
}
}
step("Assert '$tron' network standard '$trc20' is displayed") {
flakySafely {
onManageTokensScreen { networkStandard(networkName = tron, standard = trc20).assertIsDisplayed() }
}
}
}
}
@AllureId("667")
@DisplayName("Manage tokens: search by name and ticker filters the list")
@Test
fun searchByNameAndTickerTest() {
val tokenTitle = "Tether"
val nameQuery = "Tether"
val tickerQuery = "USDT"
val emptyQuery = "Zzqnotoken"
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Open 'Manage tokens' screen") { openManageTokens() }
step("Search by name: '$nameQuery'") {
onManageTokensScreen {
searchField.performClick()
searchField.performTextInput(nameQuery)
}
}
step("Assert token: '$tokenTitle' is displayed") {
flakySafely { onManageTokensScreen { tokenItem(tokenTitle).assertIsDisplayed() } }
}
step("Clear search field") {
onManageTokensScreen { searchClearButton.clickWithAssertion() }
}
step("Search by ticker: '$tickerQuery'") {
onManageTokensScreen { searchField.performTextInput(tickerQuery) }
}
step("Assert token: '$tokenTitle' is displayed") {
flakySafely { onManageTokensScreen { tokenItem(tokenTitle).assertIsDisplayed() } }
}
step("Clear search field") {
onManageTokensScreen { searchClearButton.clickWithAssertion() }
}
step("Search by unknown query: '$emptyQuery'") {
onManageTokensScreen { searchField.performTextInput(emptyQuery) }
}
step("Assert token: '$tokenTitle' is not displayed") {
flakySafely { onManageTokensScreen { tokenItem(tokenTitle).assertDoesNotExist() } }
}
}
}
@AllureId("763")
@DisplayName("Manage tokens: enabling Solana network on a modern card shows no warning")
@Test
fun solanaNetworkNoWarningTest() {
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Open 'Manage tokens' screen") { openManageTokens() }
step("Enable '$solanaNetworkTitle' network for token: '$solanaTokenTitle'") {
toggleTokenNetworkInManageTokens(tokenTitle = solanaTokenTitle, networkTitle = solanaNetworkTitle)
}
step("Assert hide-token alert is not displayed") {
waitForIdle()
onDialog { dialogContainer.assertDoesNotExist() }
}
}
}
@AllureId("719")
@DisplayName("Manage tokens: long tap on a token network copies the contract address, main network does not")
@Test
fun copyContractAddressOnNetworkLongTapTest() {
val tokenTitle = "Tether"
val tokenNetworkTitle = "ETHEREUM"
val coinTitle = "Bitcoin"
val coinNetworkTitle = "BITCOIN"
val contractAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7"
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen() }
step("Open 'Manage tokens' screen") { openManageTokens() }
step("Click on token: '$tokenTitle'") {
flakySafely { onManageTokensScreen { tokenItem(tokenTitle).assertIsDisplayed() } }
onManageTokensScreen { tokenItem(tokenTitle).performClick() }
}
step("Long click on '$tokenNetworkTitle' network row") {
flakySafely { onManageTokensScreen { networkName(tokenNetworkTitle).assertIsDisplayed() } }
onManageTokensScreen {
networkName(tokenNetworkTitle).performTouchInput {
longClick(position = center, durationMillis = 1000L)
}
}
}
step("Assert contract-address-copied message is displayed") {
flakySafely { onManageTokensScreen { contractAddressCopiedMessage.assertIsDisplayed() } }
}
step("Assert clipboard contains '$tokenTitle' contract address") {
assertClipboardTextEquals(contractAddress)
}
step("Clear clipboard") { clearClipboard() }
step("Click on token: '$coinTitle'") {
flakySafely { onManageTokensScreen { tokenItem(coinTitle).assertIsDisplayed() } }
onManageTokensScreen { tokenItem(coinTitle).performClick() }
}
step("Long click on '$coinNetworkTitle' main network row") {
flakySafely { onManageTokensScreen { networkName(coinNetworkTitle).assertIsDisplayed() } }
onManageTokensScreen {
networkName(coinNetworkTitle).performTouchInput {
longClick(position = center, durationMillis = 1000L)
}
}
}
step("Assert clipboard is empty after long click on main network") {
waitForIdle()
assertClipboardIsEmpty()
}
}
}
@AllureId("737")
@DisplayName("Manage tokens: enabling Solana on an old-firmware card shows firmware-limitation warning")
@Test
fun solanaFirmwareLimitationWarningTest() {
val warningMessage = getResourceString(CoreResR.string.alert_manage_tokens_unsupported_message, solanaName)
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen(mockContent = Firmware451MockContent) }
step("Open 'Manage tokens' screen") { openManageTokens() }
step("Enable '$solanaNetworkTitle' network for token: '$solanaTokenTitle'") {
toggleTokenNetworkInManageTokens(tokenTitle = solanaTokenTitle, networkTitle = solanaNetworkTitle)
}
step("Assert firmware-limitation warning is displayed") {
flakySafely { onDialog { containerWithText(warningMessage).assertIsDisplayed() } }
}
}
}
@AllureId("767")
@DisplayName("Manage tokens: enabling Solana on a card missing its curve shows unsupported-curve warning")
@Test
fun solanaUnsupportedCurveWarningTest() {
val warningMessage =
getResourceString(CoreResR.string.alert_manage_tokens_unsupported_curve_message, solanaName)
setupHooks(
additionalAfterSection = { resetWireMockScenarioState(COINS_API_SCENARIO) },
).run {
step("Set WireMock scenario: '$COINS_API_SCENARIO' to state: '$richState'") {
setWireMockScenarioState(COINS_API_SCENARIO, richState)
}
step("Open 'Main Screen'") { openMainScreen(mockContent = Wallet2NoEd25519Slip0010MockContent) }
step("Open 'Manage tokens' screen") { openManageTokens() }
step("Enable '$solanaNetworkTitle' network for token: '$solanaTokenTitle'") {
toggleTokenNetworkInManageTokens(tokenTitle = solanaTokenTitle, networkTitle = solanaNetworkTitle)
}
step("Assert unsupported-curve warning is displayed") {
flakySafely { onDialog { containerWithText(warningMessage).assertIsDisplayed() } }
}
}
}
}

View file

@ -0,0 +1,86 @@
package com.tangem.tests.main
import com.tangem.common.BaseTestCase
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.scenarios.addNewCardWalletWithoutSync
import com.tangem.scenarios.assertOrganizeTokensMatch
import com.tangem.scenarios.getMainScreenTokensOrder
import com.tangem.scenarios.openMainScreen
import com.tangem.scenarios.switchToPreviousWallet
import com.tangem.scenarios.synchronizeAddresses
import com.tangem.screens.onAddAndManageBottomSheet
import com.tangem.screens.onMainScreen
import com.tangem.screens.onOrganizeTokensScreen
import com.tangem.tap.domain.sdk.mocks.content.Wallet2MockContent
import dagger.hilt.android.testing.HiltAndroidTest
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Assert.assertEquals
import org.junit.Test
@HiltAndroidTest
class OrganizeTokensTest : BaseTestCase() {
@AllureId("71")
@DisplayName("Organize tokens: Correct tokens list displaying for current wallet")
@Test
fun organizeTokensCorrectTokensListDisplaying() {
setupHooks().run {
step("Open 'Main Screen'") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Add a second card wallet") {
addNewCardWalletWithoutSync(Wallet2MockContent)
}
step("Switch to first wallet Main screen") {
switchToPreviousWallet()
}
val firstWalletTokens = getMainScreenTokensOrder()
assertOrganizeTokensMatch(firstWalletTokens)
step("Switch to second wallet Main screen") {
onMainScreen { swipeToAdjacentWallet(toPrevious = false) }
}
val secondWalletTokens = getMainScreenTokensOrder()
assertOrganizeTokensMatch(secondWalletTokens)
}
}
@AllureId("2753")
@DisplayName("Organize tokens: Tokens order changing")
@Test
fun organizeTokensOrderChanging() {
setupHooks().run{
step("Open 'Main Screen'") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Open 'Organize tokens' bottom-sheet") {
onMainScreen { clickDisplayedAddAndManageButton() }
onAddAndManageBottomSheet { organizeTokensButton.clickWithAssertion() }
}
step("Drag the 3rd token onto the 2nd position and assert the new order") {
onOrganizeTokensScreen {
val sourceIndex = 2
val destinationIndex = 1
val before = getDisplayedTokenTitles()
require(before.size > sourceIndex && before.size > destinationIndex) {
"Expected at least ${maxOf(sourceIndex, destinationIndex) + 1} tokens to reorder, but got ${before.size}: $before"
}
dragToken(source = before[sourceIndex], destination = before[destinationIndex])
val expected = before.toMutableList().apply {
add(destinationIndex, removeAt(sourceIndex))
}
assertEquals(expected, getDisplayedTokenTitles())
}
}
}
}
}

View file

@ -4,12 +4,17 @@ import com.tangem.common.BaseTestCase
import com.tangem.common.constants.TestConstants.USER_TOKENS_API_SCENARIO
import com.tangem.common.utils.resetWireMockScenarioState
import com.tangem.common.utils.setWireMockScenarioState
import com.tangem.scenarios.addNewCardWalletWithoutSync
import com.tangem.scenarios.getMainScreenTokensOrder
import com.tangem.scenarios.openMainScreen
import com.tangem.scenarios.synchronizeAddresses
import com.tangem.screens.onMainScreen
import com.tangem.tap.domain.sdk.mocks.content.Wallet2MockContent
import dagger.hilt.android.testing.HiltAndroidTest
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertTrue
import org.junit.Test
@HiltAndroidTest
@ -48,4 +53,54 @@ class TokenListTest : BaseTestCase() {
}
}
@AllureId("177")
@DisplayName("Main: token list differs after switching to a second wallet")
@Test
fun tokenListChangedAfterSwitchingWalletTest() {
val userTokensState = "ReducedTokens"
setupHooks(
additionalAfterSection = {
resetWireMockScenarioState(USER_TOKENS_API_SCENARIO)
}
).run {
step("Open 'Main Screen'") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
val firstWalletTokens = getMainScreenTokensOrder()
step("Set WireMock scenario: '$USER_TOKENS_API_SCENARIO' to state: '$userTokensState'") {
setWireMockScenarioState(USER_TOKENS_API_SCENARIO, userTokensState)
}
step("Add a second card wallet") {
addNewCardWalletWithoutSync(Wallet2MockContent)
}
val secondWalletTokens = getMainScreenTokensOrder()
step("Assert both wallets exposed a non-empty token list") {
assertTrue(
"First wallet token list should not be empty",
firstWalletTokens.isNotEmpty(),
)
assertTrue(
"Second wallet token list should not be empty",
secondWalletTokens.isNotEmpty(),
)
}
step("Assert the two wallets show different token lists") {
assertNotEquals(
"Expected the second wallet's token list to differ from the first " +
"(first=$firstWalletTokens, second=$secondWalletTokens)",
firstWalletTokens,
secondWalletTokens,
)
}
}
}
}

View file

@ -27,11 +27,9 @@ class WarningsTest : BaseTestCase() {
resetWireMockScenarioState(USER_TOKENS_API_SCENARIO)
}
).run {
step("Set WireMock scenario: '$USER_TOKENS_API_SCENARIO' to state: '$scenarioState'") {
setWireMockScenarioState(USER_TOKENS_API_SCENARIO, scenarioState)
}
step("Open 'Main Screen'") {
openMainScreen()
}

View file

@ -0,0 +1,178 @@
package com.tangem.tests.referral
import androidx.test.core.app.ApplicationProvider
import com.tangem.common.BaseTestCase
import com.tangem.common.extensions.clickWithAssertion
import com.tangem.common.extensions.tapBackButton
import com.tangem.common.utils.AddressComparisonHelper
import com.tangem.common.utils.getClipboardText
import com.tangem.common.utils.resetWireMockScenarios
import com.tangem.common.utils.setWireMockScenarioState
import com.tangem.domain.models.scan.ProductType
import com.tangem.scenarios.openMainScreen
import com.tangem.scenarios.openTesterMenu
import com.tangem.scenarios.referralTakeParticipate
import com.tangem.scenarios.synchronizeAddresses
import com.tangem.screens.onDetailsScreen
import com.tangem.screens.onMainScreen
import com.tangem.screens.onMainScreenTopBar
import com.tangem.screens.onTesterMenuScreen
import com.tangem.screens.onWalletSettingsScreen
import dagger.hilt.android.testing.HiltAndroidTest
import io.qameta.allure.kotlin.AllureId
import io.qameta.allure.kotlin.junit4.DisplayName
import org.junit.Assert.assertEquals
import org.junit.Test
@HiltAndroidTest
class ReferralTest : BaseTestCase() {
@AllureId("3630")
@DisplayName("Referral program: Token and Blockchain added on Main screen after participation")
@Test
fun referralTokenAndBlockchainAddedAfterParticipationTest() {
val tokenNetwork = "Tron"
val token = "Tether"
setupHooks(
additionalAfterSection = {
resetWireMockScenarios()
}
).run {
step("Open 'Main' screen") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Verify network $tokenNetwork and token $token is not displayed") {
onMainScreen {
assertTokenDoesNotExist(tokenNetwork)
assertTokenDoesNotExist(token)
}
}
step("Take participate in Referral program") {
referralTakeParticipate()
}
step("Return to the 'Main' screen") {
tapBackButton()
onWalletSettingsScreen { screenContainer.assertIsDisplayed() }
tapBackButton()
onDetailsScreen { screenContainer.assertIsDisplayed() }
tapBackButton()
onMainScreen { screenContainer.assertIsDisplayed() }
}
step("Verify network $tokenNetwork and token $token is displayed on 'Main' screen") {
onMainScreen {
tokenWithTitleAndAddress(tokenNetwork)
tokenWithTitleAndAddress(token)
}
}
}
}
@AllureId("10098")
@DisplayName("Referral program: Token added on Main screen after participation")
@Test
fun referralTokenAddedAfterParticipationTest() {
val userWalletScenarioName = "user_tokens_api"
val userWalletState = "Tron"
val tokenNetwork = "Tron"
val token = "Tether"
setupHooks(
additionalAfterSection = {
resetWireMockScenarios()
}
).run {
step("Set wiremock scenario: $userWalletScenarioName to state $userWalletState") {
setWireMockScenarioState(scenarioName = userWalletScenarioName, state = userWalletState)
}
step("Open 'Main' screen") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Verify token $token is not displayed") {
onMainScreen { assertTokenDoesNotExist(token) }
}
step("Verify network $tokenNetwork is displayed") {
onMainScreen { tokenWithTitleAndAddress(tokenNetwork) }
}
step("Take participate in Referral program") {
referralTakeParticipate()
}
step("Return to the 'Main' screen") {
tapBackButton()
onWalletSettingsScreen { screenContainer.assertIsDisplayed() }
tapBackButton()
onDetailsScreen { screenContainer.assertIsDisplayed() }
tapBackButton()
onMainScreen { screenContainer.assertIsDisplayed() }
}
step("Verify $token is displayed on 'Main' screen") {
onMainScreen { tokenWithTitleAndAddress(token) }
}
}
}
@AllureId("3629")
@DisplayName("Referral program: Participating unavailable for No-Wallet cards")
@Test
fun referralUnavailableForNoWalletCardsTest() {
setupHooks().run {
step("Open 'Main' screen") {
openMainScreen(productType = ProductType.Note)
}
step("Open 'Details' screen") {
onMainScreenTopBar { moreButton.clickWithAssertion() }
}
step("Open 'Wallet settings' screen") {
onDetailsScreen { walletNameButton.clickWithAssertion() }
}
step("Verify 'Referral program' button is not displayed") {
onWalletSettingsScreen { referralProgramButton.assertDoesNotExist() }
}
}
}
@AllureId("3636")
@DisplayName("Referral program: Verify wallet derivation")
@Test
fun referralVerifyWalletDerivationTest() {
val tokenNetwork = "Tron"
val expectedDerivationPath = "m/44'/195'/0'/0/0"
setupHooks(
additionalAfterSection = {
resetWireMockScenarios()
}
).run {
step("Open 'Main' screen") {
openMainScreen()
}
step("Synchronize addresses") {
synchronizeAddresses()
}
step("Take participate in Referral program") {
referralTakeParticipate()
}
step("Open Debug menu") {
openTesterMenu()
}
step("Open 'Addresses info' screen") {
onTesterMenuScreen { addressesInfoButton.clickWithAssertion() }
}
step("Verify $tokenNetwork derivation path is '$expectedDerivationPath'") {
onTesterMenuScreen { jsonTab.clickWithAssertion() }
onTesterMenuScreen { copyButton.clickWithAssertion() }
val addressesJson = getClipboardText(ApplicationProvider.getApplicationContext())
?: error("Clipboard is empty after copying addresses")
val actualDerivationPath =
AddressComparisonHelper.derivationPathForBlockchain(addressesJson, tokenNetwork)
assertEquals(expectedDerivationPath, actualDerivationPath)
}
}
}
}

Some files were not shown because too many files have changed in this diff Show more