Buổi 03: Setup Môi Trường QA Pro
Mục tiêu buổi này: Xây dựng một môi trường QA hoàn chỉnh với Vitest, CodyMaster Dashboard, và Working Memory Protocol. Sau buổi này, bạn sẽ có được một "bộ não" kỹ thuật số để ghi nhớ học được và không lặp lại sai lầm.
Phần 1: Lý Thuyết — Unified Brain Architecture
Tại sao cần "Unified Brain"?
Trong QA truyền thống, các học được bị lãng quên:
- Buổi hôm qua tìm bug X, hôm nay lại lặp bug X vì quên
- Team member mới không biết pattern nào đã thử
- Post-mortem report được viết xong rồi... không ai đọc lại
Unified Brain là một hệ thống memory có 5 tầng:
Tier 1: SENSORY MEMORY (giây)
→ Biến trong tool hiện tại, result trung gian
→ Không lưu file — hủy khi action xong
Tier 2: WORKING MEMORY (session đến 7 ngày)
→ CONTINUITY.md — nơi scratchpad hoạt động
→ Max 500 từ / ~400 token
→ Auto-rotate: > 7 ngày promote lên Tier 3
Tier 3: LONG-TERM MEMORY (30+ ngày, nếu được reenforce)
→ .cm/context.db (SQLite + FTS5)
→ learnings table + decisions table
→ Ebbinghaus Decay: không dùng → archive; dùng lại → extend TTL
Tier 4: SEMANTIC SEARCH MEMORY (optional, project lớn)
→ qmd (BM25 + Vector + LLM reranking)
→ Tìm được "async timeout" khi bạn search "network delay"
Tier 5: CODE MEMORY (optional, 50+ source files)
→ CodeGraph (tree-sitter AST → SQLite graph)
→ Hiểu structure code tự độngCONTINUITY.md — Working Memory Protocol
CONTINUITY.md là file magic — đây là "task list + learning journal + decision log" trong một:
Bạn sẽ:
- Đầu mỗi session: Đọc CONTINUITY.md → hiểu state hiện tại
- Trong session: Update "Mistakes & Learnings" khi gặp bug
- Cuối session: Update "Just Completed" + "Next Actions"
Template CONTINUITY.md:
# CodyMaster Working Memory
Last Updated: 2026-04-24T10:30:00Z
Current Phase: executing
Current Iteration: 3
Project: TaskFlow
## Active Goal
Implement 5-layer test gate cho TaskFlow app. Mục tiêu: detect Bug #1 & #2 từ test.
## Current Task
- ID: task-003
- Title: Setup Vitest + write first test
- Status: in-progress
- Skill: cm-tdd
- Started: 2026-04-24T09:00:00Z
## Just Completed
- npm install -D vitest jsdom acorn (task-002)
- Created vitest.config.ts with jsdom environment
- Added test scripts to package.json
## Next Actions (Priority Order)
1. Write first test: "should reject empty title" in src/__tests__/models/task.test.ts
2. Run `npm test` — watch the test FAIL
3. Implement minimal code to pass test
4. Refactor if needed
5. Push to Git + update CONTINUITY.md
## Active Blockers
- None currently
## Key Decisions This Session
- Use Vitest (not Jest): 6x faster for Node.js + ESM support
- Use jsdom for DOM testing (needed for Bug #4 later)
- Keep unit tests in `__tests__/` folder close to source
## Mistakes & Learnings
### Pattern: Test File Structure
- **What Failed:** First test file went to root `__tests__/` folder, but file structure not clear
- **Why It Failed:** Vitest can't auto-discover deep nested test files without explicit pattern
- **How to Prevent:** Always mirror source structure: `src/models/task.js` → `src/__tests__/models/task.test.ts`
- **Timestamp:** 2026-04-24T10:00:00Z
- **Agent:** me
- **Task:** task-001
## Working Context
TaskFlow uses:
- Node.js 18+ (supports ESM natively)
- SQLite (not Postgres) — simpler testing, no Docker needed
- Express middleware pattern for routes
- Validation happens in Model layer, not Route layer (Bug #1, #2 are there)
Current architecture for Task model:Task { id, title, description, completed, createdAt, dueDate } Validation: title required, title max 255 chars Routes: GET /tasks, POST /tasks, PUT /tasks/:id, DELETE /tasks/:id
## Files Currently Being Modified
- package.json: added test scripts
- vitest.config.ts: created from template
- src/__tests__/: placeholder for tests (to be created)The 5 Sections You MUST Know:
| Section | When to Update | Example |
|---|---|---|
| Active Goal | Session start (read), Session end (update if changed) | "Detect Bug #1 via TDD" |
| Current Task | When switching tasks | Task ID, status, which skill you're using |
| Just Completed | End of every 30 min of work | "Wrote test for empty title validation" |
| Mistakes & Learnings | Immediately when you hit an error | Template provided below |
| Working Context | Start of session; update if architecture changes | "Task model has X fields, validation rules Y" |
Phần 2: Thực Hành — Setup Vitest & CONTINUITY.md
Bước 1: Clone TaskFlow (5 phút)
# Nếu chưa có TaskFlow repo
git clone https://github.com/taskflow-qa/taskflow.git
cd taskflow
# Hoặc nếu đã có, update
cd taskflow
git pull origin main
# Check hiện tại
git log --oneline | head -3
node --version # v18+ needed
npm --versionExpected output:
$ node --version
v18.16.0
$ npm --version
9.6.4Bước 2: Install Vitest (5 phút)
# Install Vitest + dependencies
npm install -D vitest jsdom acorn
# Verify installation
npm list vitestExpected output:
taskflow@0.1.0 /Users/you/taskflow
└── vitest@1.2.0Bước 3: Create vitest.config.ts (5 phút)
File: vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
// Test environment: jsdom lets us test DOM code in Node.js
environment: 'jsdom',
// Glob pattern for test files
include: ['src/**/*.test.ts', 'src/**/*.test.js'],
// Coverage options (we'll use this later)
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
exclude: [
'node_modules/',
'src/setupTests.ts',
]
},
// Globals: no need to import describe/it/expect
globals: true,
// Watch mode settings
watch: false,
},
});Bước 4: Update package.json Scripts (5 phút)
File: package.json
{
"name": "taskflow",
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "node src/server.js",
"start": "node src/server.js",
"test": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest --coverage",
"test:watch": "vitest --watch"
},
"dependencies": {
"express": "^4.18.2",
"sqlite3": "^5.1.6"
},
"devDependencies": {
"vitest": "^1.2.0",
"jsdom": "^23.0.0",
"acorn": "^8.10.0"
}
}Test scripts giải thích:
| Command | Dùng khi nào |
|---|---|
npm test | Chạy test một lần (CI/CD) |
npm run test:watch | Chạy test, re-run on file change (development) |
npm run test:ui | Mở UI dashboard để xem test results |
npm run test:coverage | Xem % code coverage |
Bước 5: Chạy Vitest Lần Đầu (5 phút)
# Run tests (sẽ fail vì chưa có test file)
npm test
# Hoặc watch mode (tốt hơn khi dev)
npm run test:watchExpected output:
RUN v1.2.0 /Users/you/taskflow
No test files found, exiting with code 0Phần 3: Setup CodyMaster Dashboard & CONTINUITY.md
Bước 6: Init CONTINUITY.md (5 phút)
# Initialize CodyMaster working memory
cm continuity init
# Check status
cm continuity statusExpected output:
✓ CONTINUITY.md initialized at .cm/CONTINUITY.md
✓ Context bus ready at .cm/context-bus.json
✓ Learnings database ready at .cm/context.dbBước 7: Create CONTINUITY.md Manually (10 phút)
Nếu cm continuity init không chạy được, tạo file tay:
File: .cm/CONTINUITY.md
# CodyMaster Working Memory
Last Updated: 2026-04-24T14:00:00Z
Current Phase: planning
Current Iteration: 1
Project: TaskFlow
## Active Goal
Setup QA environment với Vitest + CodyMaster Dashboard. Checkpoint 1: Vitest working, CONTINUITY.md created.
## Current Task
- ID: onboard-01
- Title: Environment Setup Buổi 03
- Status: in-progress
- Skill: cm-continuity
- Started: 2026-04-24T13:00:00Z
## Just Completed
- npm install vitest jsdom acorn
- vitest.config.ts created
- package.json updated with test scripts
## Next Actions (Priority Order)
1. Create .cm/ directory structure
2. Write CONTINUITY.md (this file)
3. Create .gitignore with .cm/ entries
4. Git init + first commit
5. Test Vitest with dummy test
## Active Blockers
- None
## Key Decisions This Session
- Use Vitest over Jest: faster for Node.js
- Keep CONTINUITY.md in .cm/ folder (not root)
- Test files mirror src/ structure
## Mistakes & Learnings
### Ebbinghaus Decay: Memory Fades, Patterns Emerge
**What Learned:** When same error happens 3x+, extend memory TTL
**Why Matters:** Prevents "forgot we tried this already"
**Prevention:** Use `reinforceCount` field in learnings.json
| Count | TTL | Status |
|-------|-----|--------|
| 0 | 30 days | new learning |
| 1 | 30 days | pattern emerging |
| 2 | 60 days | pattern confirmed |
| 3+ | 90+ days | fundamental knowledge |
### Pattern: Environment Setup Pitfall
- **What Failed:** First attempt: installed vitest globally, can't find config
- **Why It Failed:** Global install ≠ project install; config.ts not found in PATH
- **How to Prevent:** Always `npm install -D` (dev dependency), check node_modules/.bin/
- **Timestamp:** 2026-04-24T13:30:00Z
- **Scope:** global (applies to all projects)
## Working Context
### TaskFlow Stack
- **Framework:** Node.js + Express
- **Database:** SQLite (no Docker needed)
- **Test Framework:** Vitest (v1.2.0+)
- **Test Environment:** jsdom (for DOM testing later)
### Git Workflow
- Main branch: production-ready code
- Feature branches: `feature/task-validation`, `feature/security-scan`, etc.
- PR required before merge
### QA Mindset This Session
- Write test BEFORE code (Red-Green-Refactor cycle)
- Test one thing per test
- Name tests as: `should [expected behavior]`
## Files Currently Being Modified
- .cm/CONTINUITY.md: this working memory
- vitest.config.ts: test runner config
- package.json: added test scripts
- .gitignore: to add .cm/ entries
## Memory Layer Status
- Tier 1 (Sensory): CLI commands in current shell
- Tier 2 (Working): CONTINUITY.md (this file)
- Tier 3 (Long-term): .cm/context.db (SQLite)
- Tier 4 (Semantic): Not yet activated (< 50 docs)
- Tier 5 (Code): Not yet activated (< 50 source files)Bước 8: Create Hardened .gitignore (5 phút)
File: .gitignore
# Node
node_modules/
npm-debug.log
package-lock.json
yarn.lock
# CodyMaster (Do NOT commit working memory!)
.cm/context.db
.cm/context-bus.json
.cm/learnings.json
.cm/decisions.json
.cm/meta-learnings.json
.cm/token-budget.json
# BUT DO commit these (team learnings):
# (Keep CONTINUITY.md in git — it's the team learning log)
# Uncomment if shared with team:
# !.cm/CONTINUITY.md
# !.cm/learnings-index.md
# Environment
.env
.env.local
.env.*.local
# IDE
.vscode/
.idea/
*.swp
*.swo
# OS
.DS_Store
Thumbs.db
# Build & Test
dist/
build/
coverage/
.nyc_output/
# Vitest
.vitest/Giải thích:
| File/Folder | Tại sao ignore? |
|---|---|
.cm/context.db | SQLite database, local-only, confidential learnings |
.cm/context-bus.json | Live state, re-generated each run |
.cm/CONTINUITY.md | Mục tiêu: commit để team chia sẻ learning (tùy chọn) |
.env | API keys, secrets — NEVER commit |
node_modules/ | Generated by npm, huge size |
coverage/ | Generated by test runner, not code |
Bước 9: Git Init & First Commit (5 phút)
# Initialize git (nếu chưa có)
git init
# Add all files
git add -A
# Commit with meaningful message (follow Conventional Commits)
git commit -m "feat(setup): initialize Vitest, CONTINUITY.md, and .gitignore"
# Verify
git log --oneline | head -3
git statusExpected output:
$ git log --oneline | head -3
a1b2c3d (HEAD -> main) feat(setup): initialize Vitest, CONTINUITY.md, and .gitignore
$ git status
On branch main
nothing to commit, working tree cleanBước 10: Test Vitest Works (5 phút)
Create dummy test:
File: src/__tests__/dummy.test.ts
import { describe, it, expect } from 'vitest';
describe('Vitest Setup', () => {
it('should pass a simple assertion', () => {
expect(1 + 1).toBe(2);
});
it('should handle async operations', async () => {
const promise = Promise.resolve('success');
await expect(promise).resolves.toBe('success');
});
});# Run test
npm test
# Run with coverage
npm run test:coverage
# Run in watch mode (auto-rerun on file change)
npm run test:watchExpected output:
RUN v1.2.0 /Users/you/taskflow
✓ src/__tests__/dummy.test.ts (2)
✓ Vitest Setup (2)
✓ should pass a simple assertion
✓ should handle async operations
Test Files 1 passed (1)
Tests 2 passed (2)Phần 4: Dashboard Setup (Optional)
Bước 11: CodyMaster Dashboard (7 phút)
# Start dashboard locally
cm dashboard start
# Open browser (auto or manual)
cm dashboard open
# Or manually: http://localhost:3333Dashboard sẽ hiển thị:
- Active Goals từ CONTINUITY.md
- Skill Chain Progress (buổi sau sẽ dùng)
- Memory Health (Tier 2, Tier 3 status)
- Recent Learnings từ learnings.json
Phần 5: Checkpoint & Validation
✅ Checklist Buổi 03
# 1. Vitest installed
npm list vitest
# ✓ Should show vitest@1.x.x
# 2. vitest.config.ts exists
test -f vitest.config.ts && echo "✓ Config found" || echo "✗ Config missing"
# 3. Test scripts in package.json
npm run test
# ✓ Should say "No test files found" (OK) or show dummy tests passing
# 4. .cm/CONTINUITY.md exists
test -f .cm/CONTINUITY.md && echo "✓ CONTINUITY.md found" || echo "✗ Missing"
# 5. .gitignore has .cm/ entries
grep ".cm/" .gitignore && echo "✓ .gitignore OK" || echo "✗ Missing .cm/ entries"
# 6. Git initialized
test -d .git && echo "✓ Git repo found" || echo "✗ Git not initialized"
# 7. First commit exists
git log --oneline | head -1
# ✓ Should show "feat(setup): ..."Deliverable Buổi 03
# Remove dummy test (no longer needed)
rm src/__tests__/dummy.test.ts
# Final commit
git add -A
git commit -m "test: remove dummy test, ready for real tests"
# Push to remote (if set up)
git push origin mainPhần 6: 5 Câu Quiz
Quiz 1: Memory Architecture
Q: Tier 2 (Working Memory) có TTL bao lâu và tại sao? A: 7 ngày (max). Vì thông tin quá cũ sẽ được auto-promote lên Tier 3 (Long-term), nếu không được dùng lại sẽ bị archive theo Ebbinghaus Decay.
Quiz 2: CONTINUITY.md Protocol
Q: Bạn nên update CONTINUITY.md bao lâu một lần? A:
- Đầu session: Đọc "Mistakes & Learnings" để tránh lặp lại sai lầm
- Mỗi 30 phút: Update "Just Completed" khi hoàn thành milestone
- Cuối session: Update "Next Actions" + "Key Decisions" + "Files Modified"
Quiz 3: Vitest Config
Q: Tại sao phải set environment: 'jsdom' trong vitest.config.ts? A: jsdom cho phép test DOM API (querySelector, addEventListener, v.v.) trong Node.js environment. Cần thiết cho Layer 1 testing (Bug #4 sẽ dùng).
Quiz 4: .gitignore Strategy
Q: Tại sao phải ignore .cm/context.db nhưng KHÔNG ignore .cm/CONTINUITY.md? A:
.cm/context.db= SQLite database chứa confidential learnings, local-only.cm/CONTINUITY.md= team shared learning log, nên commit để cả team đọc được
Quiz 5: Red-Green-Refactor
Q: Vitest là công cụ để implement quy trình nào mà bạn sẽ dùng buổi tới? A: Red-Green-Refactor (TDD). Red = viết failing test, Green = code tối thiểu để pass, Refactor = clean up while test stays green.
Homework Buổi 03
Task 1: Deep Dive vào Memory Decay (20 phút)
Đọc phần "Decay Timeline" trong cm-continuity SKILL.md:
First recorded: TTL = 30 days
Reinforced 1x (count=1): TTL resets to 30 from today
Reinforced 2x (count=2): TTL = 60 days (pattern emerging)
Reinforced 3x+ (count≥3): TTL = 90 days (proven pattern)
Reinforced 5x+ (count≥5): TTL = 180 days (fundamental knowledge)Bài tập: Viết một "learning" giả định vào .cm/CONTINUITY.md về một bug bạn sẽ gặp. Ví dụ:
### Pattern: Task Model Validation
- **What Failed:** Task.create() accepts empty title
- **Why It Failed:** No validation in model layer
- **How to Prevent:** Validate in Task model before insert
- **Timestamp:** 2026-04-24T15:00:00Z
- **Scope:** module:taskTask 2: Setup Vitest Watch Mode Workflow (15 phút)
# Terminal 1: Start Vitest in watch mode
npm run test:watch
# Terminal 2 (trong lúc test:watch chạy):
# - Sửa dummy.test.ts
# - Vitest sẽ auto-rerun
# - Observe test pass/fail in real-timeTập luyện: Thêm 3 test cases trong src/__tests__/dummy.test.ts:
- Test string concatenation
- Test array operations
- Test object equality
Run npm run test:watch và verify all 5 tests pass.
Task 3: Commit & Write Session Notes (10 phút)
# Final cleanup
rm src/__tests__/dummy.test.ts
# Commit
git add -A
git commit -m "setup: complete environment with Vitest, CONTINUITY.md, git config"
# Update CONTINUITY.md with final summary
# Edit .cm/CONTINUITY.md → change "Just Completed" to summary of what was done
# Re-commit
git add .cm/CONTINUITY.md
git commit -m "docs(continuity): session 3 completion notes"Tài Liệu Tham Khảo
- Vitest Official Docs
- CodyMaster cm-continuity
- Ebbinghaus Forgetting Curve — lý thuyết đằng sau memory decay
Key Takeaways
- Unified Brain: 5-tier memory architecture giúp bạn không lặp lại sai lầm
- CONTINUITY.md: Template working memory — đọc đầu session, update cuối session
- Vitest: Test framework cho Node.js, setup lần này dùng cho 7 bug labs tới
- Memory Decay: Learnings tự archive nếu không dùng lại (Ebbinghaus)
- Team Learning: .gitignore strategy = confidential local + shared team logs
Sau buổi 03, bạn sẽ có:
- Vitest running locally ✓
- .cm/CONTINUITY.md template ✓
- Git repo initialized ✓
- Ready for TDD cycle (buổi 05) ✓