greentic-setup 0.4.28

End-to-end bundle setup engine for the Greentic platform — pack discovery, QA-driven configuration, secrets persistence, and bundle lifecycle management
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# Manual Testing Guide

Panduan step-by-step untuk testing semua fitur greentic-setup.

## Prerequisites

```bash
# 1. Install greentic-setup
cd /path/to/greentic-setup
cargo install --path .

# 2. Copy binary ke PATH
cp target/release/greentic-setup ~/.local/bin/

# 3. Verify installation
greentic-setup --version
gtc setup --help
```

---

## Test 1: Bundle Lifecycle (init/add/list/status)

### 1.1 Initialize Bundle

```bash
# Cleanup
rm -rf /tmp/test-bundle

# Initialize
gtc setup bundle init /tmp/test-bundle --name "Test Bundle"
```

**Expected output:**
```
Creating bundle at /tmp/test-bundle...
Bundle created at /tmp/test-bundle

Next steps:
  1. greentic-setup bundle add <pack.gtpack> --bundle /tmp/test-bundle
  2. greentic-setup bundle setup --bundle /tmp/test-bundle --answers answers.yaml
```

**Verify:**
```bash
ls -la /tmp/test-bundle/
# Should see: greentic.bundle.yaml, providers/, config/, etc.
```

### 1.2 Add Pack to Bundle

```bash
# Build a test pack first (if not exists)
cd ../greentic-messaging-providers/packs/messaging-dummy
greentic-pack build --in . --gtpack-out ./dist/messaging-dummy.gtpack

# Add to bundle
gtc setup bundle add \
  ../greentic-messaging-providers/packs/messaging-dummy/dist/messaging-dummy.gtpack \
  --bundle /tmp/test-bundle
```

**Expected output:**
```
Adding pack to bundle...
  Pack ref: .../messaging-dummy.gtpack
  ...
Pack added to bundle successfully.
  Resolved packs: 1
```

### 1.3 List Packs

```bash
gtc setup bundle list --bundle /tmp/test-bundle
```

**Expected output:**
```
Bundle: /tmp/test-bundle
Domain: messaging
Packs found: 1
  - messaging-dummy (messaging)
```

### 1.4 Check Status

```bash
gtc setup bundle status --bundle /tmp/test-bundle
gtc setup bundle status --bundle /tmp/test-bundle --format json
```

**Expected output:**
```
Bundle: /tmp/test-bundle
Valid: yes
Packs: 1 installed
  - providers/messaging/messaging-dummy
Tenants: 2
  - demo
  - default
```

---

## Test 2: Interactive Wizard

### 2.1 Setup Pack with Questions

First, create a pack with QA questions:

```bash
# Modify messaging-dummy to have questions
cat > ../greentic-messaging-providers/packs/messaging-dummy/setup.yaml << 'EOF'
provider_id: dummy
version: 1
title: Dummy Provider Setup
questions:
  - name: api_key
    title: API Key
    kind: string
    required: true
    secret: true
    help: "Enter your API key"
  - name: webhook_url
    title: Webhook URL
    kind: string
    required: true
    help: "Public URL for callbacks"
EOF

# Rebuild pack
cd ../greentic-messaging-providers/packs/messaging-dummy
greentic-pack build --in . --gtpack-out ./dist/messaging-dummy.gtpack

# Re-add to bundle
cd /path/to/greentic-setup
rm -rf /tmp/test-bundle
gtc setup bundle init /tmp/test-bundle --name "Test Bundle"
gtc setup bundle add \
  ../greentic-messaging-providers/packs/messaging-dummy/dist/messaging-dummy.gtpack \
  --bundle /tmp/test-bundle
```

### 2.2 Run Interactive Wizard

```bash
gtc setup /tmp/test-bundle
```

**Expected behavior:**
1. Shows "Found 1 provider(s) to configure"
2. Prompts for "API Key" (masked input)
3. Prompts for "Webhook URL"
4. Completes setup

### 2.3 Dry Run

```bash
gtc setup --dry-run /tmp/test-bundle
```

**Expected output:**
```
wizard plan: mode=create dry_run=true
...
[dry-run] Would setup bundle: /tmp/test-bundle
```

---

## Test 3: Answers File (Non-Interactive)

### 3.1 Generate Answers Template

```bash
gtc setup --dry-run --emit-answers /tmp/answers.json /tmp/test-bundle
cat /tmp/answers.json
```

**Expected output:**
```json
{
  "bundle_source": "/tmp/test-bundle",
  "env": "dev",
  "greentic_setup_version": "1.0.0",
  "setup_answers": {
    "messaging-dummy": {
      "api_key": "",
      "webhook_url": ""
    }
  },
  "team": null,
  "tenant": "demo"
}
```

### 3.2 Fill and Apply Answers

```bash
cat > /tmp/answers.json << 'EOF'
{
  "bundle_source": "/tmp/test-bundle",
  "env": "dev",
  "greentic_setup_version": "1.0.0",
  "setup_answers": {
    "messaging-dummy": {
      "api_key": "sk-test-12345",
      "webhook_url": "https://example.com/webhook"
    }
  },
  "team": null,
  "tenant": "demo"
}
EOF

gtc setup --answers /tmp/answers.json /tmp/test-bundle
```

**Expected output:**
```
Loaded answers from /tmp/answers.json
...
Setup complete: /tmp/test-bundle
```

---

## Test 4: Conditional Questions (visible_if)

### 4.1 Create Pack with Conditional Questions

```bash
cat > ../greentic-messaging-providers/packs/messaging-dummy/setup.yaml << 'EOF'
provider_id: dummy
version: 1
title: Conditional Setup Demo
questions:
  - name: auth_method
    title: Authentication Method
    kind: string
    required: true
    help: "Choose: api_key, oauth, or none"

  - name: api_key
    title: API Key
    kind: string
    required: true
    secret: true
    visible_if:
      field: auth_method
      eq: "api_key"

  - name: oauth_client_id
    title: OAuth Client ID
    kind: string
    required: true
    visible_if:
      field: auth_method
      eq: "oauth"

  - name: oauth_client_secret
    title: OAuth Client Secret
    kind: string
    required: true
    secret: true
    visible_if:
      field: auth_method
      eq: "oauth"

  - name: webhook_url
    title: Webhook URL
    kind: string
    required: true
EOF

# Rebuild and re-add
cd ../greentic-messaging-providers/packs/messaging-dummy
greentic-pack build --in . --gtpack-out ./dist/messaging-dummy.gtpack

cd /path/to/greentic-setup
rm -rf /tmp/test-bundle
gtc setup bundle init /tmp/test-bundle --name "Conditional Test"
gtc setup bundle add \
  ../greentic-messaging-providers/packs/messaging-dummy/dist/messaging-dummy.gtpack \
  --bundle /tmp/test-bundle
```

### 4.2 Test with auth_method = "api_key"

```bash
cat > /tmp/answers.json << 'EOF'
{
  "bundle_source": "/tmp/test-bundle",
  "env": "dev",
  "greentic_setup_version": "1.0.0",
  "setup_answers": {
    "messaging-dummy": {
      "auth_method": "api_key",
      "api_key": "sk-secret-12345",
      "webhook_url": "https://example.com/webhook"
    }
  },
  "team": null,
  "tenant": "demo"
}
EOF

gtc setup --answers /tmp/answers.json /tmp/test-bundle
```

**Expected:** Success (oauth fields not required)

### 4.3 Test with auth_method = "oauth"

```bash
cat > /tmp/answers.json << 'EOF'
{
  "bundle_source": "/tmp/test-bundle",
  "env": "dev",
  "greentic_setup_version": "1.0.0",
  "setup_answers": {
    "messaging-dummy": {
      "auth_method": "oauth",
      "oauth_client_id": "client-123",
      "oauth_client_secret": "secret-456",
      "webhook_url": "https://example.com/webhook"
    }
  },
  "team": null,
  "tenant": "demo"
}
EOF

gtc setup --answers /tmp/answers.json /tmp/test-bundle
```

**Expected:** Success (api_key not required)

### 4.4 Test Missing Required Field (Should Fail)

```bash
cat > /tmp/answers.json << 'EOF'
{
  "bundle_source": "/tmp/test-bundle",
  "env": "dev",
  "greentic_setup_version": "1.0.0",
  "setup_answers": {
    "messaging-dummy": {
      "auth_method": "api_key",
      "webhook_url": "https://example.com/webhook"
    }
  },
  "team": null,
  "tenant": "demo"
}
EOF

gtc setup --answers /tmp/answers.json /tmp/test-bundle
```

**Expected:** Should fail - api_key is required when auth_method = "api_key"

---

## Test 5: Locale / i18n

### 5.1 Test Japanese Locale

```bash
gtc setup bundle status --bundle /tmp/test-bundle --locale ja
```

**Expected output:**
```
Bundle: /tmp/test-bundle
Valid: はい
Pack: 1 インストール済み
...
```

### 5.2 Test Indonesian Locale

```bash
gtc setup bundle status --bundle /tmp/test-bundle --locale id
```

**Expected output:**
```
Bundle: /tmp/test-bundle
Valid: ya
Pack: 1 terinstal
...
```

### 5.3 Test List with Locale

```bash
gtc setup bundle list --bundle /tmp/test-bundle --locale ja
```

**Expected output:**
```
Bundle: /tmp/test-bundle
Domain: messaging
見つかったpack: 1
  - messaging-dummy (messaging)
```

---

## Test 6: Update Provider

### 6.1 Update Configuration

```bash
cat > /tmp/update-answers.json << 'EOF'
{
  "messaging-dummy": {
    "webhook_url": "https://new-webhook.example.com/callback"
  }
}
EOF

gtc setup bundle update messaging-dummy \
  --bundle /tmp/test-bundle \
  --answers /tmp/update-answers.json
```

**Expected:** Configuration updated successfully

---

## Test 7: Remove Provider

### 7.1 Remove with Force

```bash
gtc setup bundle remove messaging-dummy \
  --bundle /tmp/test-bundle \
  --force
```

**Expected output:**
```
Removing provider: messaging-dummy
Provider removed successfully.
```

### 7.2 Verify Removal

```bash
gtc setup bundle status --bundle /tmp/test-bundle
```

**Expected:** Packs: 0 installed

---

## Test 8: Admin API Types (Code Test)

### 8.1 Run Unit Tests

```bash
cargo test admin -- --nocapture
```

**Expected:** All admin tests pass

### 8.2 Test TLS Config Validation

```bash
cargo test tls -- --nocapture
```

**Expected:** TLS config tests pass

---

## Test 9: Card Setup Session (Code Test)

### 9.1 Run Card Setup Tests

```bash
cargo test card_setup -- --nocapture
```

**Expected output:**
```
test card_setup::tests::session_not_expired_within_ttl ... ok
test card_setup::tests::session_expired_with_zero_ttl ... ok
test card_setup::tests::merge_answers_accumulates ... ok
test card_setup::tests::setup_link_generation_signed ... ok
...
```

---

## Test 10: Hot Reload Diff (Code Test)

### 10.1 Run Reload Tests

```bash
cargo test reload -- --nocapture
```

**Expected:** All reload/diff tests pass

---

## Test 11: Full CI Check

```bash
bash ci/local_check.sh
```

**Expected:** All steps pass:
- fmt check
- clippy
- test (97+ tests)
- build
- doc
- package

---

## Test Checklist

| # | Test | Command | Expected |
|---|------|---------|----------|
| 1.1 | Bundle init | `gtc setup bundle init` | Creates bundle dir |
| 1.2 | Bundle add | `gtc setup bundle add` | Resolves packs: 1 |
| 1.3 | Bundle list | `gtc setup bundle list` | Shows 1 pack |
| 1.4 | Bundle status | `gtc setup bundle status` | Valid: yes |
| 2.1 | Interactive wizard | `gtc setup /tmp/test-bundle` | Prompts for input |
| 2.2 | Dry run | `gtc setup --dry-run` | No execution |
| 3.1 | Emit answers | `--emit-answers` | JSON template |
| 3.2 | Apply answers | `--answers` | Setup complete |
| 4.1 | visible_if api_key | auth_method=api_key | api_key required |
| 4.2 | visible_if oauth | auth_method=oauth | oauth fields required |
| 5.1 | Locale ja | `--locale ja` | Japanese output |
| 5.2 | Locale id | `--locale id` | Indonesian output |
| 6.1 | Update provider | `bundle update` | Config updated |
| 7.1 | Remove provider | `bundle remove --force` | Provider removed |
| 8.1 | Admin tests | `cargo test admin` | All pass |
| 9.1 | Card tests | `cargo test card_setup` | All pass |
| 10.1 | Reload tests | `cargo test reload` | All pass |
| 11 | Full CI | `ci/local_check.sh` | All pass |

---

## Cleanup

```bash
# Restore original setup.yaml
cat > ../greentic-messaging-providers/packs/messaging-dummy/setup.yaml << 'EOF'
provider_id: dummy
version: 1
title: Dummy provider setup
questions: []
EOF

# Rebuild
cd ../greentic-messaging-providers/packs/messaging-dummy
greentic-pack build --in . --gtpack-out ./dist/messaging-dummy.gtpack

# Remove test bundle
rm -rf /tmp/test-bundle
rm -f /tmp/answers.json /tmp/update-answers.json
```

---

## Troubleshooting

### "command not found: gtc"

```bash
# Check if greentic is installed
which gtc
# If not, install:
cargo install --path ../greentic
```

### "Bundle not found"

```bash
# Ensure bundle exists
ls -la /tmp/test-bundle
# If not, init first:
gtc setup bundle init /tmp/test-bundle --name "Test"
```

### "Pack ref not found"

```bash
# Check pack exists
ls -la ../greentic-messaging-providers/packs/messaging-dummy/dist/
# If not, build:
cd ../greentic-messaging-providers/packs/messaging-dummy
greentic-pack build --in . --gtpack-out ./dist/messaging-dummy.gtpack
```

### Interactive wizard shows "Device not configured"

This happens when running in non-TTY environment (e.g., scripts). Use `--answers` instead:

```bash
# Generate template
gtc setup --dry-run --emit-answers /tmp/answers.json /tmp/test-bundle
# Edit and apply
gtc setup --answers /tmp/answers.json /tmp/test-bundle
```