dafuweng / AGENTS.md
HelloSun's picture
Add development handoff docs and Playwright tests
d8c54c4 verified
|
Raw History Blame Contribute Delete
2.66 kB
# AGENTS.md
## 先讀這個
接手這個專案時,請先讀 `DEVELOPMENT.md`。它是完整的架構、狀態機、規則、測試與部署說明。
## 專案定位
- 純靜態 Q 版雙人大富翁,部署在 Hugging Face Static Space。
- Space:`HelloSun/dafuweng`
- Live:`https://hellosun-dafuweng.static.hf.space/`
- 沒有 build step、沒有後端、沒有資料庫。直接開 `index.html` 就能跑。
## 本機啟動
```bash
cd /root/app
python3 -m http.server 8000
```
開啟 `http://127.0.0.1:8000/`。
## 測試
```bash
cd /root/app
npm install
npx playwright install chromium
npm test
npm run test:full
```
若環境已經有 Playwright,也可直接:
```bash
NODE_PATH=/root/.npm/_npx/e41f203b7505f1fb/node_modules node tests/smoke.js
```
測試預設打 `http://127.0.0.1:8000/`;可用 `BASE_URL` 覆寫。
## 部署
不要把 token 寫進任何檔案。使用環境變數:
```bash
HF_TOKEN=... python3 - <<'PY'
from huggingface_hub import HfApi
HfApi(token=__import__('os').environ['HF_TOKEN']).upload_folder(
repo_id='HelloSun/dafuweng',
repo_type='space',
folder_path='.',
commit_message='Update game',
)
PY
```
`hf` CLI 在這台機器會壞掉(`StyledContext` 錯誤),請用 Python `huggingface_hub`。
## 絕對不要破壞的規則
1. `TILES.forEach((tile, index) => { tile.id = index; })` 必須保留。`tile.id` 與陣列索引必須一致。
2. 使用 `renderUI()`,不要再引入 `updateUI()`。
3. `BOARD_SIZE = 32` 與 9×9 棋盤 perimeter 綁定。不要直接 append 第 33 格;那需要重做棋盤幾何。
4. `pay()` 可能會觸發 `bankrupt()` 並把 `state.over` 設為 `true`。每次 `await` 後要檢查 `state.over`。
5. `state.pending` 是 Promise 的 resolver。新增互動時,最後一定要呼叫 `resolvePending()` 或對應的 resolve。
6. 停止自動代玩、重新開始、遊戲結束時都要清掉 auto / modal timers。
7. 不要改掉 `.board { container-type: inline-size; }`;整個棋盤字級依賴 `cqw`。
8. 目前程式明確假設 2 位玩家。新增玩家不是只加 `PLAYER_META` 就會動。
## 檔案
- `index.html`:DOM 骨架與所有固定 id。
- `style.css`:視覺、9×9 棋盤、響應式與 modal。
- `game.js`:全部遊戲邏輯(IIFE,無模組)。
- `assets/`:六張 256×256 生成圖與 favicon。
- `tests/`:Playwright 冒煙、手機、modal、完整對局測試。
- `DEVELOPMENT.md`:詳細接手文件。
## 修改後的最低驗證
```bash
node --check game.js
npm test
```
改到回合、租金、破產、卡片或 auto-play 時,一定要再跑:
```bash
npm run test:full
```