CBQ / EventCommands concurrency test
Checks, against the running daemons and the legacy dev DB, that the commands still work when
fired concurrently: kardex order, idempotency, redelivery, identity per flow, and
that nothing fails in the log. Real HTTP calls from the logged-in session; no Pest.
Rules (do not break)
- Writes only on workshop 103195 (Pruebas TI). Do not touch real pending requests (61543, 61770, 61774).
- Do not edit ids or rows by hand. DB = SELECT + LIMIT only (never UPDATE/DELETE/DDL/SET).
- Leave test data in place, labeled in
comments with QA <tag> (e.g. QA PR140 toolkit-v2).
- Legacy is the source of truth: rules that block (e.g. waste
isAlreadyProcessing → waste_already_exist)
are the expected result, not a bug.
- Do not commit/push. Do not change
.env or restart daemons without asking.
- The legacy dev DB is refreshed daily from prod: yesterday's ids may no longer exist.
Routing (so the results make sense)
| What |
Broker |
Why |
UI calls (sync:true): create, resolve, add waste, cycle count, storage capacity, previews |
Redis (default) |
the CBQ controller picks the broker by command name (handles in config/uxmaltech.php); sync only means "wait for the reply" |
Stock movements (dispatchTo after commit) |
Kafka async |
EventRoute per stream (invt_mgmt, invt_mgmt_adjust_review, invt_production) in config/manufacturing-core.php |
Commands that don't move stock never reach Kafka; an idle Kafka daemon is correct for them.
Only the engines (MgmtAdjustmentEngine, MgmtInventoryEngine, ProductionInventoryEngine) write
current_quantity, and they run only inside the Kafka consumers.
Environment
- Container
ef-manufacturing-frankenphp; package mounted at /manufacturing-core-pkg.
- Daemons:
php artisan uxmaltech:cbq-daemon --broker=kafka and --broker=default. They must have started
after the last code change:docker exec ef-manufacturing-frankenphp sh -c 'ps -o pid,lstart,args -u vscode | grep cbq-daemon | grep -v grep; ls -l --time-style=full-iso /manufacturing-core-pkg/src/EventCommands'
If they are older → ask the user to restart them.
- Scripts in
scripts/ (copy into the container):SK=<this skill's base directory>/scripts
for f in snapshot.php redeliver.php logscan.sh; do docker cp $SK/$f ef-manufacturing-frankenphp:/tmp/$f; done
# run: docker exec ef-manufacturing-frankenphp sh -c 'cd /app && php artisan tinker --execute "$(cat /tmp/snapshot.php)" 2>&1 | tail -60'
# log: docker exec ef-manufacturing-frankenphp sh -c 'cd /app && sh /tmp/logscan.sh'
- "Permissions fetch failed [400]" in the daemon (SSO perm cache) →
php artisan tinker --execute "$(cat /tmp/perm-refresh.php)" and retry.
- 504 at ~30s with a burst of >
12 sync calls: the web tier gives up waiting on the serial Redis
daemon (1.2 s per message); the command still runs. Fire in waves of 3–5, or confirm the uuid
in the log ("processed successfully") before calling it a failure.
Browser (Playwright)
- New context with
ignoreHTTPSErrors:true and open
https://ef-manufacturing.localhost/inventory-adjustments/raw-material/review.
If it lands on SSO login → stop and ask the user to log in.
- Always use the last context:
const ctxs = page.context().browser().contexts(); const p = ctxs[ctxs.length-1].pages()[0];
- Helper for
browser_run_code_unsafe:const token = await p.evaluate(() => document.querySelector('meta[name=csrf-token]')?.content);
const T0 = Date.now();
const post = (label, path, data) => p.request.post('https://ef-manufacturing.localhost'+path,
{data:{...data, sync:true}, headers:{'X-CSRF-TOKEN':token,'Accept':'application/json'}, timeout:120000})
.then(async r => { const ms = Date.now()-T0; const t = await r.text(); try { const j = JSON.parse(t); const d = j.data ?? j;
return label+' → '+r.status()+' '+ms+'ms '+(j.uuid??'')+' '+(d.result??'')+' '+JSON.stringify(d.data??{}).slice(0,150)+(d.errorMsg?' | '+String(d.errorMsg).replace(/<br>/g,' '):''); }
catch { return label+' → '+r.status()+' '+ms+'ms '+t.slice(0,160); } });
// fire in parallel: return await Promise.all([ post(...), post(...) ]);
Test data
invt_mgmt 55792 = Musgo (material 31) on 103195.
invt_production 4832 = Ruscus (material 14), invt_mgmt 17074.
- Legacy actor: user 101470. Session workshop =
usuarios.workshop_id (not 103195 for this user).
Steps
0. Baseline
docker exec ef-manufacturing-frankenphp sh -c 'rm -f /tmp/cc_base.json; cd /app && wc -l < storage/logs/laravel.log > /tmp/logmark && php artisan tinker --execute "$(cat /tmp/snapshot.php)" 2>&1 | tail -5'
Write down the stock for 55792 and 4832.
1. Movements (reach Kafka) — each block in a single Promise.all
| # |
Fire |
Expected |
| 1 |
4× POST /v1/cmd/inventory-adjustments/raw-material/create {workshop_id:103195, invt_mgmt_id:55792, operation:'add'|'subtract', adjust_type_id:9, quantity:N, comments:'QA <tag> Rx', force:false} |
4 ids |
| 2 |
5× POST /v1/cmd/inventory-adjustments/raw-material/review/resolve on the same id {id, status:'accepted', comments, force:false} |
1 ok + 4 "La solicitud ya fue procesada"; 1 kardex row |
| 3 |
3 accepts of different requests (force:true) + 3× POST /v1/cmd/inventory-adjustments/affiliates/create {workshop_id:103195, material_id:31, adjust_type:8, quantity:'1', comments} |
all ok; unbroken chain on 55792 |
| 4 |
3× /v1/cmd/inventory/raw-material-decrease {workshop_id:103195, material_id:31, quantity:1, type:'mgmt', comments} + 1× /raw-material-decrease/batch {…, materials_qty:{'31':1}} + 3× /v1/cmd/inventory/picking-decreases/add {workshop_id:103195, material_id:14, quantity:1, type:'operational', comments} + 1× /picking-decreases/batch {workshop_id:103195, type:'operational', materials_qty:{'14':1}} |
raw-material: 1 ok, the rest waste_already_exist (legacy); picking: 4 ok, in order |
| 5 |
On a new request: reject ×2 + accept ×1 at once; on another: cancel ×2 |
exactly 1 winner each; kardex only if accept wins |
| 6 |
Create subtract with a quantity > stock, force:false |
negative-stock warning, no write |
2. Redelivery (idempotency)
Write the ids of events already applied and re-dispatch them twice each:
docker exec ef-manufacturing-frankenphp sh -c 'echo "{\"mp\":<req_id>,\"mp_qty\":<qty>,\"aff\":<aff_id>,\"mw\":<waste_id>,\"pw\":<picking_waste_id>}" > /tmp/redeliver_ids.json; cd /app && timeout 280 php artisan tinker --execute "$(cat /tmp/redeliver.php)" 2>&1 | tail -8'
(For an MP subtract pass "mp_source":"adjust_exit".) Expected: "movimiento saltado" ×N and 0 new rows.
3. The other commands (Redis only, no movement) — waves of 3–5
| Command |
Payload |
Expected |
/v1/cmd/inventory/picking-decreases/preview-csv |
{workshop_id:103195, materials_qty:{'14':1,'164':2}} |
rows with stock |
/v1/cmd/inventory/raw-material-decreases/preview-csv |
{workshop_id:103195, materials_qty:{'31':1}} |
rows with stock |
/v1/cmd/inventory/cycle-count-config/add ×2, category not yet configured on 103195 |
{workshop_id:103195, material_category_id, frequency:'monthly', weekday:3, full_count:false} |
only 1 row created |
/v1/cmd/inventory/cycle-count-config/add ×2, existing category |
— |
"Ese taller ya está configurado…" |
/v1/cmd/inventory/cycle-count-config/update ×3 |
{id:<config 103195>, same values} |
ok |
/v1/cmd/inventory/cycle-count/reset ×2 on a pending count |
{cycle_count_id} |
"Sólo se puede reiniciar un conteo iniciado…" |
/v1/cmd/inventory/storage-capacity ×3 |
{workshop_id:103195, material_id:14, packages_per_label:<current value>} |
ok, value unchanged |
/v1/cmd/inventory/workshop-picking/adjust |
{invt_mgmt_id, operation, adjust_type_id:<picking type, e.g. 14>, quantity, comments} |
uses the session workshop: if it isn't 103195 only validations are tested — do NOT write to another workshop |
4. Checks
snapshot.php again: chain … breaks=0 for both; total delta = sum of the accepted events;
request_platform = 'ef-manufacturing:<SOURCE_TABLE>' on every new row.
logscan.sh: 0 identity/movement failures; "Sending message to Kafka" only for
*.movement.v1, mgmt-remove.v1, production-remove.v1; any dead-letter → read its exception_message
(don't guess the cause).
- Quick UI: the 5 screens load and show the records (raw-material review and requests,
affiliates, raw-material waste, picking waste).
Report
A table per block: command · what was fired · expected · result (✅/⚠️) · ids · stock before→after.
Separate what was tested live from what was not (e.g. same-id collision across two flows,
rows written before the identity change, StockValidation not ported). Every cause stated must have
evidence in the log or the DB; if a claim was not verified, say so.
1---2name: cbq-concurrency-test3version: 1.0.04description: Concurrent live test (real HTTP calls, NOT Pest) of every command in manufacturing-core-pkg that uses the EventCommands/CBQ toolkit — inventory movements over Kafka, idempotency, redelivery, and the Redis commands. Use when the user asks to "test all the commands", "run the concurrency test", "check the engines still work" after changes to the toolkit or the engines.5metadata:6 source: https://skillmd.com/skills/edgardoacosta/cbq-concurrency-test7---89# CBQ / EventCommands concurrency test1011Checks, against the running daemons and the legacy dev DB, that the commands still work when12fired **concurrently**: kardex order, idempotency, redelivery, identity per flow, and13that nothing fails in the log. Real HTTP calls from the logged-in session; **no Pest**.1415## Rules (do not break)1617- Writes **only on workshop 103195** (Pruebas TI). Do not touch real pending requests (61543, 61770, 61774).18- Do not edit ids or rows by hand. DB = **SELECT + LIMIT** only (never UPDATE/DELETE/DDL/SET).19- Leave test data in place, labeled in `comments` with `QA <tag>` (e.g. `QA PR140 toolkit-v2`).20- Legacy is the source of truth: rules that block (e.g. waste `isAlreadyProcessing` → `waste_already_exist`)21 are the expected result, not a bug.22- Do not commit/push. Do not change `.env` or restart daemons without asking.23- The legacy dev DB is refreshed daily from prod: yesterday's ids may no longer exist.2425## Routing (so the results make sense)2627| What | Broker | Why |28|---|---|---|29| UI calls (`sync:true`): create, resolve, add waste, cycle count, storage capacity, previews | **Redis** (`default`) | the CBQ controller picks the broker by command name (`handles` in `config/uxmaltech.php`); `sync` only means "wait for the reply" |30| Stock movements (`dispatchTo` after commit) | **Kafka** async | `EventRoute` per stream (`invt_mgmt`, `invt_mgmt_adjust_review`, `invt_production`) in `config/manufacturing-core.php` |3132Commands that don't move stock **never** reach Kafka; an idle Kafka daemon is correct for them.33Only the engines (`MgmtAdjustmentEngine`, `MgmtInventoryEngine`, `ProductionInventoryEngine`) write34`current_quantity`, and they run only inside the Kafka consumers.3536## Environment3738- Container `ef-manufacturing-frankenphp`; package mounted at `/manufacturing-core-pkg`.39- Daemons: `php artisan uxmaltech:cbq-daemon --broker=kafka` and `--broker=default`. They must have started40 **after** the last code change:41 ```sh42 docker exec ef-manufacturing-frankenphp sh -c 'ps -o pid,lstart,args -u vscode | grep cbq-daemon | grep -v grep; ls -l --time-style=full-iso /manufacturing-core-pkg/src/EventCommands'43 ```44 If they are older → ask the user to restart them.45- Scripts in `scripts/` (copy into the container):46 ```sh47 SK=<this skill's base directory>/scripts48 for f in snapshot.php redeliver.php logscan.sh; do docker cp $SK/$f ef-manufacturing-frankenphp:/tmp/$f; done49 # run: docker exec ef-manufacturing-frankenphp sh -c 'cd /app && php artisan tinker --execute "$(cat /tmp/snapshot.php)" 2>&1 | tail -60'50 # log: docker exec ef-manufacturing-frankenphp sh -c 'cd /app && sh /tmp/logscan.sh'51 ```52- "Permissions fetch failed [400]" in the daemon (SSO perm cache) →53 `php artisan tinker --execute "$(cat /tmp/perm-refresh.php)"` and retry.54- **504 at ~30s** with a burst of >~12 sync calls: the web tier gives up waiting on the serial Redis55 daemon (~1.2 s per message); **the command still runs**. Fire in waves of 3–5, or confirm the uuid56 in the log ("processed successfully") before calling it a failure.5758## Browser (Playwright)59601. New context with `ignoreHTTPSErrors:true` and open61 `https://ef-manufacturing.localhost/inventory-adjustments/raw-material/review`.62 If it lands on SSO login → **stop and ask the user to log in**.632. Always use the last context:64 `const ctxs = page.context().browser().contexts(); const p = ctxs[ctxs.length-1].pages()[0];`653. Helper for `browser_run_code_unsafe`:66 ```js67 const token = await p.evaluate(() => document.querySelector('meta[name=csrf-token]')?.content);68 const T0 = Date.now();69 const post = (label, path, data) => p.request.post('https://ef-manufacturing.localhost'+path,70 {data:{...data, sync:true}, headers:{'X-CSRF-TOKEN':token,'Accept':'application/json'}, timeout:120000})71 .then(async r => { const ms = Date.now()-T0; const t = await r.text(); try { const j = JSON.parse(t); const d = j.data ?? j;72 return label+' → '+r.status()+' '+ms+'ms '+(j.uuid??'')+' '+(d.result??'')+' '+JSON.stringify(d.data??{}).slice(0,150)+(d.errorMsg?' | '+String(d.errorMsg).replace(/<br>/g,' '):''); }73 catch { return label+' → '+r.status()+' '+ms+'ms '+t.slice(0,160); } });74 // fire in parallel: return await Promise.all([ post(...), post(...) ]);75 ```7677## Test data7879- `invt_mgmt` **55792** = Musgo (material 31) on 103195.80- `invt_production` **4832** = Ruscus (material 14), `invt_mgmt` **17074**.81- Legacy actor: user 101470. Session workshop = `usuarios.workshop_id` (not 103195 for this user).8283## Steps8485### 0. Baseline86```sh87docker exec ef-manufacturing-frankenphp sh -c 'rm -f /tmp/cc_base.json; cd /app && wc -l < storage/logs/laravel.log > /tmp/logmark && php artisan tinker --execute "$(cat /tmp/snapshot.php)" 2>&1 | tail -5'88```89Write down the stock for 55792 and 4832.9091### 1. Movements (reach Kafka) — each block in a single `Promise.all`9293| # | Fire | Expected |94|---|---|---|95| 1 | 4× `POST /v1/cmd/inventory-adjustments/raw-material/create` `{workshop_id:103195, invt_mgmt_id:55792, operation:'add'\|'subtract', adjust_type_id:9, quantity:N, comments:'QA <tag> Rx', force:false}` | 4 ids |96| 2 | 5× `POST /v1/cmd/inventory-adjustments/raw-material/review/resolve` on the **same** id `{id, status:'accepted', comments, force:false}` | 1 ok + 4 "La solicitud ya fue procesada"; 1 kardex row |97| 3 | 3 accepts of **different** requests (`force:true`) + 3× `POST /v1/cmd/inventory-adjustments/affiliates/create` `{workshop_id:103195, material_id:31, adjust_type:8, quantity:'1', comments}` | all ok; unbroken chain on 55792 |98| 4 | 3× `/v1/cmd/inventory/raw-material-decrease` `{workshop_id:103195, material_id:31, quantity:1, type:'mgmt', comments}` + 1× `/raw-material-decrease/batch` `{…, materials_qty:{'31':1}}` + 3× `/v1/cmd/inventory/picking-decreases/add` `{workshop_id:103195, material_id:14, quantity:1, type:'operational', comments}` + 1× `/picking-decreases/batch` `{workshop_id:103195, type:'operational', materials_qty:{'14':1}}` | raw-material: 1 ok, the rest `waste_already_exist` (legacy); picking: 4 ok, in order |99| 5 | On a new request: reject ×2 + accept ×1 at once; on another: cancel ×2 | exactly 1 winner each; kardex only if accept wins |100| 6 | Create `subtract` with a quantity > stock, `force:false` | negative-stock `warning`, no write |101102### 2. Redelivery (idempotency)103Write the ids of events already applied and re-dispatch them twice each:104```sh105docker exec ef-manufacturing-frankenphp sh -c 'echo "{\"mp\":<req_id>,\"mp_qty\":<qty>,\"aff\":<aff_id>,\"mw\":<waste_id>,\"pw\":<picking_waste_id>}" > /tmp/redeliver_ids.json; cd /app && timeout 280 php artisan tinker --execute "$(cat /tmp/redeliver.php)" 2>&1 | tail -8'106```107(For an MP `subtract` pass `"mp_source":"adjust_exit"`.) Expected: "movimiento saltado" ×N and 0 new rows.108109### 3. The other commands (Redis only, no movement) — waves of 3–5110111| Command | Payload | Expected |112|---|---|---|113| `/v1/cmd/inventory/picking-decreases/preview-csv` | `{workshop_id:103195, materials_qty:{'14':1,'164':2}}` | rows with stock |114| `/v1/cmd/inventory/raw-material-decreases/preview-csv` | `{workshop_id:103195, materials_qty:{'31':1}}` | rows with stock |115| `/v1/cmd/inventory/cycle-count-config/add` ×2, category **not** yet configured on 103195 | `{workshop_id:103195, material_category_id, frequency:'monthly', weekday:3, full_count:false}` | **only 1 row** created |116| `/v1/cmd/inventory/cycle-count-config/add` ×2, existing category | — | "Ese taller ya está configurado…" |117| `/v1/cmd/inventory/cycle-count-config/update` ×3 | `{id:<config 103195>, same values}` | ok |118| `/v1/cmd/inventory/cycle-count/reset` ×2 on a `pending` count | `{cycle_count_id}` | "Sólo se puede reiniciar un conteo iniciado…" |119| `/v1/cmd/inventory/storage-capacity` ×3 | `{workshop_id:103195, material_id:14, packages_per_label:<current value>}` | ok, value unchanged |120| `/v1/cmd/inventory/workshop-picking/adjust` | `{invt_mgmt_id, operation, adjust_type_id:<picking type, e.g. 14>, quantity, comments}` | uses the **session** workshop: if it isn't 103195 only validations are tested — do NOT write to another workshop |121122### 4. Checks1231. `snapshot.php` again: `chain … breaks=0` for both; total delta = sum of the accepted events;124 `request_platform = 'ef-manufacturing:<SOURCE_TABLE>'` on every new row.1252. `logscan.sh`: 0 identity/movement failures; "Sending message to Kafka" only for126 `*.movement.v1`, `mgmt-remove.v1`, `production-remove.v1`; any dead-letter → read its `exception_message`127 (don't guess the cause).1283. Quick UI: the 5 screens load and show the records (raw-material review and requests,129 affiliates, raw-material waste, picking waste).130131## Report132133A table per block: command · what was fired · expected · result (✅/⚠️) · ids · stock before→after.134Separate what **was tested live** from what **was not** (e.g. same-id collision across two flows,135rows written before the identity change, `StockValidation` not ported). Every cause stated must have136evidence in the log or the DB; if a claim was not verified, say so.