Commit Graph
68 Commits
Author SHA1 Message Date
QiuSW bc9c637522 fix(#113): restore hidden PDD spec headings 2026-08-27 17:29:24 +08:00
QiuSW daf7406ec9 fix: expand all whitelisted PDD share links (#109) 2026-08-27 15:32:40 +08:00
QiuSW 20775cc1bf fix: resolve PDD share links on Agent (#108) 2026-08-27 15:04:19 +08:00
QiuSW 28c3cb5138 feat: collect current PDD page from Agent (#101) 2026-08-27 10:53:48 +08:00
QiuSW eec63a0653 feat: sync agent task history (#99) 2026-08-26 16:10:12 +08:00
QiuSW 5f2dd05ebd feat: add safe agent purchase retry (#95) 2026-08-26 14:37:01 +08:00
QiuSW 7b6cc00503 feat(agent): implement #91 controlled recollection 2026-08-26 10:17:45 +08:00
QiuSW b885a4ef66 feat(agent): implement #90 task history 2026-08-26 09:26:38 +08:00
QiuSW ae9a9fef6f fix: add purchaser role permissions (#85) 2026-08-25 14:25:22 +08:00
QiuSW a622d718e0 fix(#84): restore collection selection in locate mode 2026-08-25 11:05:56 +08:00
QiuSW 7b488e2c68 fix(#82): separate PDD linking from mapping 2026-08-25 10:21:10 +08:00
QiuSW 0794dc580b feat(#80): add SYB product process stages 2026-08-25 09:44:02 +08:00
QiuSW af3dd5563b fix(#79): retry transient SYB read failures 2026-08-24 17:31:34 +08:00
QiuSW a2cc9a144f feat(#75): 增加 SYB 每小时自动同步 2026-08-24 16:02:16 +08:00
QiuSW 0fccbc99c1 feat(#74): 优化 SYB 商品筛选和列表布局 2026-08-24 15:10:47 +08:00
QiuSW 634bd46729 fix(#73): speed up SYB purchase preview 2026-08-24 11:48:56 +08:00
QiuSW 166adc6fa8 feat(#70): import cmautobuy product catalog 2026-08-23 23:59:12 +08:00
QiuSW 67d8f32eaf feat(#69): add Shopee PDD specification mapping 2026-08-23 23:23:42 +08:00
QiuSW 9490bddf8f feat(#67): add Shopee order snapshots to purchase tasks 2026-08-22 10:41:05 +08:00
QiuSW 22a024be64 fix(#64): bound purchase spec selection retries 2026-08-22 09:07:13 +08:00
QiuSW ec9f47f2ab fix(#63): keep AI matching out of purchase queries 2026-08-21 18:02:58 +08:00
QiuSW 0e3be46c4c feat(#62): extend AI matching timeout 2026-08-21 17:23:02 +08:00
QiuSW 6181d97f39 feat(#62): add AI specification matching settings 2026-08-21 17:04:49 +08:00
QiuSW aebe80f305 fix(#61): use safe purchase spec entry 2026-08-21 16:08:57 +08:00
QiuSW 01d852011a feat(#58): batch retry failed purchase tasks 2026-08-21 14:20:40 +08:00
QiuSW 7e4f404265 feat(#44): create purchase tasks from SYB products 2026-08-21 10:17:31 +08:00
QiuSW 9ee03ec30f fix(#56): add go-admin success envelope 2026-08-20 23:33:52 +08:00
QiuSW 182ef3940a feat(#55): add purchase admin query APIs 2026-08-20 23:31:23 +08:00
QiuSW b0f33bf679 fix(#54): unify device state across task domains 2026-08-20 22:53:15 +08:00
QiuSW afeb2723ea fix(#53): parameterize purchase rule actions 2026-08-20 17:53:10 +08:00
QiuSW 65ae41fd6f feat(#34): implement purchase task state machine 2026-08-20 17:22:52 +08:00
QiuSW 978f42806a feat(#33): define purchase task data and API contract 2026-08-20 16:49:43 +08:00
QiuSW 903280fada fix(#52): align SYB sync count columns with MySQL 2026-08-20 16:19:54 +08:00
QiuSW 32edb91a31 fix(#52): expose SYB preflight failure stages 2026-08-20 16:09:28 +08:00
QiuSW badb78fa68 feat(#50): run SYB imports asynchronously 2026-08-20 15:24:50 +08:00
QiuSW 6c7a7298e3 feat(#49): complete SYB shop management 2026-08-20 11:54:11 +08:00
QiuSWandClaude Opus 5 1b67495e71 feat(#49): add shop HTTP API, SYB discovery and the import filter
Stage B steps 3 and 4.

The filter runs after loadDailyList has proved the day's snapshot whole,
never before. Filtering first would let drift among other shops' orders
hide a hole in the ones we do want. OrderCount stays the unfiltered total
alongside AcceptedCount and ShopSkipped, so a shop missing from the
allow-list shows up as a number rather than as absent data.

An empty allow-list is a refusal, not "import everything" — the latter
looks exactly like a filter that works. Mutation-tested, along with the
detail-level shop re-check that catches a list and detail response
disagreeing about which shop an order belongs to.

ShopBreakdown counts orders per shop including skipped ones, under the
stored display name rather than SYB's spelling, so one shop cannot appear
under two spellings. #50 renders it.

Discovery lives in sybimport, not sybshop: it needs the SYB client, and
sybimport already depends on sybshop for the filter, so the reverse would
be an import cycle. It reads the list endpoint only and never adds a
shop — widening what gets imported stays an explicit action.

Read and write routes are registered separately. GoAuto inherits
go-admin's per-path permission model, so "配置仅管理员" is expressible but
not enforced in code; the grant is configured in 系统管理.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 11:31:44 +08:00
QiuSWandClaude Opus 5 7bd8166a30 feat(#49): add shop service — CRUD, enable toggle and enabled-name lookup
Stage B step 2 (service layer; HTTP handlers next).

Rename rewrites NormalizedName along with DisplayName. Leaving the key
stale would show the new name while still matching the old one, so the
archive would look correctly configured while importing a different shop.
Mutation-tested: updating only display_name makes the rename test fail.

Duplicates are reported against the name already stored, not the one just
submitted — the two can differ only in case or character width, and
echoing back what was typed reads as the system rejecting a name it does
not have.

Delete is a soft delete carrying the id into DeletedFlag, so the same
name can be added again afterwards while past sync records keep resolving
the old row.

EnabledNames returns an empty map without error. Empty is a legitimate
state that callers must turn into "refuse to sync", never "import
everything".

MarkSeen only updates shops already on the list. A sync must not grow the
allow-list as a side effect; discovery is a separate explicit action.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 11:23:02 +08:00
QiuSWandClaude Opus 5 cda37b4a60 feat(#49): add syb_shop model, migration and name normalization
Stage B step 1. The shop list decides which of a SYB account's shops get
imported.

Matching is by name, so the normalized form is the real key: whitespace
trimmed, full-width ASCII folded, letters lowercased. " ABC店 ", "ABC店"
and "abc店" are one shop. DisplayName is only ever shown to people, and
the unique index sits on the normalized column so a caller that skips
normalization cannot create rows that look identical on screen.

Interior whitespace is deliberately not collapsed: two shops differing
only there are still two shops, and merging them silently would be worse
than the duplicate this prevents.

Soft delete uses the DeletedFlag sentinel rather than a nullable
deleted_at in the unique index, which is silently inert because unique
indexes treat every NULL as distinct. Mutation-tested: dropping the
sentinel from the index makes the recreate-after-delete case fail.

The version-local migration file is included this time — the model alone
would never reach an existing database.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 11:18:32 +08:00
QiuSWandClaude Opus 5 e6f533b71e fix(#48): add the missing version-local migration for syb_session
Adding SYBSession to migrations.Migrate was not enough. Schema reaches an
existing database only through a version-local file; with the previous
version already recorded in sys_migration, Migrate never re-ran and the
table simply never appeared. The unit tests build a fresh database every
time, so they stayed green while the real database was missing a table —
which surfaced as "Error 1146: Table 'goauto.syb_session' doesn't exist"
on the first import attempt.

server/.gitignore was hiding these files. go-admin ignores version-local
because it is where generated local migrations land, but every GoAuto
migration belongs in version control; the existing ones had been forced
in with `git add -f`. Un-ignoring *.go there also recovers four migrations
that were never committed at all — 1786700000000 through 1786700300000,
covering the base schema, device registration, heartbeat and collection
execution. A fresh clone could not have built a working database.

Guard the class of mistake rather than just this instance:

  - migrations.VerifyTables checks every model's table after migrating and
    names what is missing along with the fix.
  - The migrate command runs it, so the failure lands at migrate time
    instead of at the first request that needs the table.
  - initDB no longer discards migrateModel's error. Upstream had
    `_ = migrateModel()` followed by an unconditional "初始化成功", so a
    failed migration reported success and the launcher believed it.

Also records the two-step rule in Common-Changes: a new model needs both
the model registration and a new version file.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 10:10:11 +08:00
QiuSWandClaude Opus 5 bbc5fdba05 fix(#48): replace per-migration noise with a summary, force UTF-8 console
The startup output was dominated by two upstream behaviours. Migrate
printed a bare count for every already-applied migration — a lone "1"
with no version, no explanation — through the standard logger, hence
stderr, which the launcher's `2>&1 |` renders as a red PowerShell error
block that looks like a failed migration. And the version-existence check
echoed one SELECT count(*) per version. Both replaced: a Warn-level
session for the check, and one summary line on stdout.

Console encoding needed more than [Console]::OutputEncoding: PowerShell
5.1 decodes child-process output by the console code page, so chcp 65001
goes with it.

The regression test capture was wrong twice and mutation testing caught
both. It captured only stdout while the bug wrote to stderr, and it
compared lines to "1" when the logger prefixes a timestamp, so the
assertion could never fail. It now captures the standard logger too and
matches with a pattern that allows the prefix — verified by reinstating
the bug and watching the test fail.

Not verified: the PowerShell edits, which need a Windows run.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:53:56 +08:00
QiuSWandClaude Opus 5 d7a15e9525 fix(#48): silence the empty per-request access log line
Every API request logged one bare "info" line with no message: upstream
calls log.WithFields(logData).Info(), and the console formatter does not
render fields, so status, latency, IP, method and URI all went nowhere.
One line of pure noise per request.

Give the line its message and demote it to debug. The payload is worth
having when diagnosing a slow or failing request, so it is recoverable
by setting logger.level back to debug rather than deleted.

settings.yml drops from trace to info accordingly. Nothing else in the
project logs below info: the many .Debug() calls are gorm SQL echo, which
is unaffected by logger level.

This patches upstream go-admin middleware, marked as such in a comment.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:47:45 +08:00
QiuSWandClaude Opus 5 72ecf25291 fix(#48): find config.yaml from server/ and stop diagnostics looking like errors
The startup log proved config.yaml was not being found during migrate.
Lookup covered the working directory and the executable's directory, but
the server runs from server/ while config.yaml sits at the repository
root — so it was found only when a launcher happened to export
GOAUTO_CONFIG. Anyone running `go run .` by hand got no local config at
all. Search the parent directory too, with the working directory still
winning.

The diagnostics also wrote to stderr, and the launcher pipes the server
through `2>&1 | Tee-Object`, which turns every stderr write into a
PowerShell NativeCommandError. The informational line I added to make
this debuggable was itself rendering as a red error block. They go to
stdout now.

Launchers set the console to UTF-8: Go writes UTF-8 while the console
decodes as the ANSI code page, which turned every Chinese log line into
mojibake.

Verified by running the built binary from server/ with no GOAUTO_CONFIG
set: it loads ../config.yaml and the lines survive 2>/dev/null.

Not verified: the two PowerShell edits, which need a Windows run.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:44:03 +08:00
QiuSWandClaude Opus 5 8001c03abd fix(#48): make configuration resolution visible at startup and in errors
Diagnosing "credential not configured" required reading the source: the
local config layer was a silent no-op when it found no file, and the
import error named only environment variables even though config.yaml is
now the normal place to configure this — sending operators to look in a
file that was never the problem.

Startup now logs which config.yaml was loaded, or that none was found and
where it looked, followed by whether SYB credentials resolved and from
which layer. Presence only, never values: server logs get pasted into
tickets.

The import error now names the file that was actually consulted and
distinguishes "no config.yaml found" from "found it, but it has no syb
credentials" — two problems with different fixes that previously produced
identical text.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:37:58 +08:00
QiuSWandClaude Opus 5 bf0c978794 revert(#48): undo out-of-scope reformatting of go-admin router files
Running gofmt over the whole router directory added a trailing newline to
six upstream files that this ticket does not touch. Harmless, but the
repo rule is to leave unrelated changes alone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:29:40 +08:00
QiuSWandClaude Opus 5 c86e98d0cb feat(#48): make one config work for both development and deployment
The repo already layered file defaults under environment overrides, on
both the backend (settings.yml < GOAUTO_*) and the frontend
(.env.production < process.env). What was missing was a translator for
production: config.yaml only ever existed for the PowerShell launchers,
so a packaged binary read none of it and had no database credentials
either — SYB was inheriting an existing gap, not creating one.

The server now reads config.yaml itself, between settings.yml and the
environment. Lookup is GOAUTO_CONFIG, then ./config.yaml, then beside the
executable, so a packaged binary works wherever it is started. An absent
file is not an error: containers supply everything through the
environment. Scalars are read by YAML type and coerced, so an unquoted
all-digit password cannot take startup down over a quoting detail.

This removed the need for a Read-SybConfig in PowerShell: the launcher
just hands over the path it already knows, rather than reimplementing a
YAML parser.

The server also serves the built frontend when dist is present, which is
what .env.production's empty VUE_APP_BASE_API already assumes. The
history fallback is restricted to non-API GETs, and is not installed at
all without dist, so development 404s stay 404s.

Precedence is mutation-tested: applying the local file after the
environment instead of before makes the layering test fail.

Not verified: the PowerShell change and any Windows deployment — both
need a run on the Windows side.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:28:45 +08:00
QiuSWandClaude Opus 5 7d07fa52b7 test(#48): add opt-in end-to-end import verification
Runs the whole path against the live API: login, page a day's shipment
orders, fold every detail into the archive, reuse the cached session, and
re-import to prove idempotency. Tagged syblive and gated on E2E_DB, so it
never runs by accident and never picks its own database.

Verified on real data for 2026-08-19: 986 orders, 1524 detail lines,
1056 shopee archives, parse success 1395 / uncertain 125 / failed 4. The
4 failures are all empty productSpec at the source — marked failed rather
than filled in. Re-import created 0 and overwrote 1524, leaving the row
count unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:02:49 +08:00
QiuSWandClaude Opus 5 4f7f3a612a fix(#48): give SYBSession an explicit singular table name
Every other GoAuto model declares TableName(); SYBSession did not, so
gorm silently created syb_sessions while the rest of the schema is
singular. Migration succeeds either way, which is what makes it easy to
miss — it only surfaces when someone queries the conventional name.

Caught by running a real import, before the MySQL migration had been run
anywhere.

Migrate now takes its model list from MigratedModels(), so the new
convention test asserts over exactly the set that Migrate creates instead
of a hand-copied list that would drift. Mutation-checked: dropping the
TableName method again makes the test fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 09:00:58 +08:00
QiuSWandClaude Opus 5 7edb4e7b9f feat(#48): add SYB sync orchestration, import endpoint and page entry
Stage 2. Completes the path from the SYB API to the archive.

sybimport.Sync pages a date range day by day and folds each detail line
through the existing idempotent ApplyDetail. The paging loop is driven by
listTotal, never by the list response's own total, which live data
confirmed is the page's row count rather than the filtered total. A day
whose completeness cannot be proven — a short page, a total that drifted
while paging, a detail response missing an order — stops the run instead
of reporting a partial import as a whole one. Rows already written stay:
they are idempotent on (order_code, detail_id), so a re-run overwrites.

sybimport.Connect reuses the cached session and only discards it when SYB
explicitly says it is invalid. Caching the numeric user id alongside the
cookies is required, not incidental: session validation calls
/am/user/get?id=, and a wrong id comes back as a business error rather
than a logout, so cookies alone can never be revalidated.

The import endpoint is single-flight and detached from the request
context, so closing the tab cannot abandon a half-finished range. It
reads only; no SYB write endpoint is reachable from GoAuto.

The page swaps its "no import entry" warning for a date-range dialog that
warns when the span is wide — a single week held over 7000 orders — and
reports partial progress when a run fails midway.

Verified: go build, go vet, go test ./... all pass. The drift check was
mutation-tested. Not verified: the MySQL migration for syb_session, and
any browser walkthrough.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 16:56:00 +08:00
QiuSWandClaude Opus 5 4886e0d0a4 test(#48): add opt-in live verification against the real SYB API
Guarded by the syblive build tag, so `go test ./...` still runs entirely
against httptest fakes. Credentials come from the environment; the file
contains none, calls only read endpoints, and logs shapes and counts
rather than order codes, titles or amounts.

Verified against the live API. Confirmed from real data:
  - login via OCR works unattended; session is exactly 24h
  - §3.1 auth is cookie-based: the jar is populated after login
  - §4.3 listTotal is the filtered total (7404 over 7 days) while
    list.total is the current page size (20) — a paging loop that
    treats the latter as the total stops after one page
  - §5.1 productPrice is in yuan, not cents (max observed 403.00)
  - §6.1 one order carries nested items, not repeated rows
  - details[].id was unique across the batch, closing a gap #41
    recorded as unverified

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-19 16:40:04 +08:00