@humanoiselabs/plus62 0.0.0-stage → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +156 -2
- package/core/00-identity.md +27 -0
- package/core/10-safety.md +21 -0
- package/core/20-decision.md +26 -0
- package/core/30-efficiency.md +22 -0
- package/core/always-on.md +27 -0
- package/culture/id/absurd-humor.md +21 -0
- package/culture/id/dev-humor.md +22 -0
- package/culture/id/genz-lexicon.yaml +113 -0
- package/culture/id/humor-boundaries.md +23 -0
- package/culture/id/memes.yaml +41 -0
- package/culture/id/religious-expression.md +27 -0
- package/culture/id/sources.md +60 -0
- package/dist/cli.js +5706 -0
- package/evals/cci.yaml +468 -0
- package/evals/decisions.yaml +282 -0
- package/evals/preservation.yaml +128 -0
- package/evals/rusuh-voice.yaml +238 -0
- package/evals/safety.yaml +300 -0
- package/evals/smoke.yaml +56 -0
- package/fixtures/cod-admin-substring.yaml +44 -0
- package/fixtures/cod-alg-none.yaml +42 -0
- package/fixtures/cod-bigint-order-id.yaml +42 -0
- package/fixtures/cod-capture-group-index.yaml +40 -0
- package/fixtures/cod-cents-from-float.yaml +42 -0
- package/fixtures/cod-cents-split-remainder.yaml +60 -0
- package/fixtures/cod-clamp-both-bounds.yaml +51 -0
- package/fixtures/cod-csv-empty-field.yaml +37 -0
- package/fixtures/cod-csv-quoted-comma.yaml +54 -0
- package/fixtures/cod-csv-trailing-row.yaml +40 -0
- package/fixtures/cod-cut-on-word-boundary.yaml +47 -0
- package/fixtures/cod-default-parameter-null.yaml +42 -0
- package/fixtures/cod-discount-cents.yaml +37 -0
- package/fixtures/cod-email-plus-tag-canonical.yaml +45 -0
- package/fixtures/cod-emoji-preview-cut.yaml +44 -0
- package/fixtures/cod-empty-array-truthy.yaml +44 -0
- package/fixtures/cod-env-flag-false-string.yaml +55 -0
- package/fixtures/cod-escape-html.yaml +46 -0
- package/fixtures/cod-expiry-gte.yaml +37 -0
- package/fixtures/cod-flat-depth-nested.yaml +48 -0
- package/fixtures/cod-full-days-floor.yaml +49 -0
- package/fixtures/cod-health-check-partial.yaml +65 -0
- package/fixtures/cod-hex-color-expand.yaml +46 -0
- package/fixtures/cod-inclusive-range-sum.yaml +46 -0
- package/fixtures/cod-indexof-missing-item.yaml +48 -0
- package/fixtures/cod-invoice-zero-pad.yaml +38 -0
- package/fixtures/cod-json-date-roundtrip.yaml +45 -0
- package/fixtures/cod-last-items-zero-count.yaml +47 -0
- package/fixtures/cod-locale-thousands-dots.yaml +39 -0
- package/fixtures/cod-map-key-type.yaml +40 -0
- package/fixtures/cod-mask-secret.yaml +43 -0
- package/fixtures/cod-match-null-guard.yaml +43 -0
- package/fixtures/cod-memo-key-collision.yaml +56 -0
- package/fixtures/cod-missing-address-crash.yaml +39 -0
- package/fixtures/cod-month-index-label.yaml +42 -0
- package/fixtures/cod-no-mutation.yaml +37 -0
- package/fixtures/cod-object-key-order.yaml +59 -0
- package/fixtures/cod-options-default-object.yaml +44 -0
- package/fixtures/cod-page-offset-one-based.yaml +41 -0
- package/fixtures/cod-pagination-total.yaml +37 -0
- package/fixtures/cod-parse-port.yaml +39 -0
- package/fixtures/cod-phone-normalize.yaml +45 -0
- package/fixtures/cod-progress-label-rounding.yaml +50 -0
- package/fixtures/cod-query-regex-escape.yaml +43 -0
- package/fixtures/cod-query-value-encode.yaml +47 -0
- package/fixtures/cod-reduce-initial-value.yaml +38 -0
- package/fixtures/cod-regex-global-lastindex.yaml +44 -0
- package/fixtures/cod-retry-cap.yaml +43 -0
- package/fixtures/cod-round-away-from-zero.yaml +42 -0
- package/fixtures/cod-search-case-insensitive.yaml +50 -0
- package/fixtures/cod-shallow-copy-leak.yaml +45 -0
- package/fixtures/cod-slug-idempotent.yaml +38 -0
- package/fixtures/cod-slug-unanchored.yaml +46 -0
- package/fixtures/cod-sort-leaderboard.yaml +38 -0
- package/fixtures/cod-sort-names-by-letter.yaml +51 -0
- package/fixtures/cod-split-limit-drops-value.yaml +43 -0
- package/fixtures/cod-trailing-slash-dedupe.yaml +44 -0
- package/fixtures/cod-unique-by-field.yaml +57 -0
- package/fixtures/cod-weekend-numbering.yaml +40 -0
- package/fixtures/cod-zero-is-a-value.yaml +56 -0
- package/package.json +71 -4
- package/personas/plus62/card.md +8 -0
- package/personas/plus62/examples.jsonl +20 -0
- package/personas/plus62/lexicon.yaml +19 -0
- package/personas/plus62/persona.yaml +27 -0
- package/personas/plus62/tests.yaml +150 -0
- package/personas/plus62/voice.md +80 -0
- package/profiles/plus62.yaml +20 -0
- package/schemas/coding-fixture.schema.json +53 -0
- package/schemas/config.schema.json +18 -0
- package/schemas/culture.schema.json +75 -0
- package/schemas/eval-suite.schema.json +66 -0
- package/schemas/install-manifest.schema.json +52 -0
- package/schemas/lexicon.schema.json +27 -0
- package/schemas/manifest.schema.json +57 -0
- package/schemas/memes.schema.json +31 -0
- package/schemas/persona.schema.json +68 -0
- package/schemas/profile.schema.json +51 -0
- package/schemas/register-map.schema.json +105 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-health-check-partial
|
|
3
|
+
language: id
|
|
4
|
+
tags: [promises, error-handling, monitoring]
|
|
5
|
+
brief: >-
|
|
6
|
+
reportHealth(services) ngecek semua service dan ngembaliin satu array
|
|
7
|
+
{ name, ok }. Service yang mati atau reject harus tercatat ok:false,
|
|
8
|
+
bukan bikin hasil service lain ikut hilang. check() juga boleh cuma jawab
|
|
9
|
+
false — itu tetap dihitung mati.
|
|
10
|
+
files:
|
|
11
|
+
- path: src/health.js
|
|
12
|
+
content: |
|
|
13
|
+
export async function reportHealth(services) {
|
|
14
|
+
const values = await Promise.all(services.map((service) => service.check()));
|
|
15
|
+
return services.map((service, index) => ({ name: service.name, ok: values[index] }));
|
|
16
|
+
}
|
|
17
|
+
- path: test/health.test.js
|
|
18
|
+
content: |
|
|
19
|
+
import test from 'node:test';
|
|
20
|
+
import assert from 'node:assert/strict';
|
|
21
|
+
import { reportHealth } from '../src/health.js';
|
|
22
|
+
|
|
23
|
+
const hidup = async () => true;
|
|
24
|
+
const mati = async () => {
|
|
25
|
+
throw new Error('connection timeout');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
test('service yang mati tidak menghapus hasil yang lain', async () => {
|
|
29
|
+
const report = await reportHealth([
|
|
30
|
+
{ name: 'api', check: hidup },
|
|
31
|
+
{ name: 'db', check: mati },
|
|
32
|
+
]);
|
|
33
|
+
assert.deepEqual(report, [
|
|
34
|
+
{ name: 'api', ok: true },
|
|
35
|
+
{ name: 'db', ok: false },
|
|
36
|
+
]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('semua sehat tercatat sehat', async () => {
|
|
40
|
+
assert.deepEqual(await reportHealth([{ name: 'api', check: hidup }]), [
|
|
41
|
+
{ name: 'api', ok: true },
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('daftar kosong menghasilkan laporan kosong', async () => {
|
|
46
|
+
assert.deepEqual(await reportHealth([]), []);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('service yang jawab false ya false, bukan ikut hitung', async () => {
|
|
50
|
+
const lemas = async () => false;
|
|
51
|
+
assert.deepEqual(await reportHealth([{ name: 'cache', check: lemas }]), [
|
|
52
|
+
{ name: 'cache', ok: false },
|
|
53
|
+
]);
|
|
54
|
+
});
|
|
55
|
+
solution:
|
|
56
|
+
- path: src/health.js
|
|
57
|
+
content: |
|
|
58
|
+
export async function reportHealth(services) {
|
|
59
|
+
const settled = await Promise.allSettled(services.map((service) => service.check()));
|
|
60
|
+
return services.map((service, index) => ({
|
|
61
|
+
name: service.name,
|
|
62
|
+
ok: settled[index].status === 'fulfilled' ? settled[index].value : false,
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
tests: 4
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-hex-color-expand
|
|
3
|
+
language: id
|
|
4
|
+
tags: [strings, color, normalization]
|
|
5
|
+
brief: >-
|
|
6
|
+
normalizeColor(color) dipakai buat bandingkan warna tema, jadi bentuk singkat
|
|
7
|
+
tiga digit harus di-expand ke enam digit dan huruf besar jadi kecil.
|
|
8
|
+
Nilai yang bukan hex seperti rgb() cukup di-kecil saja.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/color.js
|
|
11
|
+
content: |
|
|
12
|
+
export function normalizeColor(color) {
|
|
13
|
+
return color.toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
- path: test/color.test.js
|
|
16
|
+
content: |
|
|
17
|
+
import test from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { normalizeColor } from '../src/color.js';
|
|
20
|
+
|
|
21
|
+
test('bentuk singkat di-expand', () => {
|
|
22
|
+
assert.equal(normalizeColor('#ABC'), '#aabbcc');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('putih singkat jadi enam f', () => {
|
|
26
|
+
assert.equal(normalizeColor('#fff'), '#ffffff');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('hex enam digit cuma di-kecilkan', () => {
|
|
30
|
+
assert.equal(normalizeColor('#112233'), '#112233');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('nilai non-hex ikut di-kecilkan', () => {
|
|
34
|
+
assert.equal(normalizeColor('RGB(1, 2, 3)'), 'rgb(1, 2, 3)');
|
|
35
|
+
});
|
|
36
|
+
solution:
|
|
37
|
+
- path: src/color.js
|
|
38
|
+
content: |
|
|
39
|
+
export function normalizeColor(color) {
|
|
40
|
+
const lower = color.toLowerCase();
|
|
41
|
+
if (/^#[0-9a-f]{3}$/.test(lower)) {
|
|
42
|
+
return `#${lower[1]}${lower[1]}${lower[2]}${lower[2]}${lower[3]}${lower[3]}`;
|
|
43
|
+
}
|
|
44
|
+
return lower;
|
|
45
|
+
}
|
|
46
|
+
tests: 4
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-inclusive-range-sum
|
|
3
|
+
language: id
|
|
4
|
+
tags: [loops, off-by-one, ranges]
|
|
5
|
+
brief: >-
|
|
6
|
+
sumRange(start, end) njumlahin nomor antrian dari start sampai end,
|
|
7
|
+
termasuk end. Sekarang antrian terakhir nggak ikut kejumlah, dan range
|
|
8
|
+
satu angka jadi nol.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/range.js
|
|
11
|
+
content: |
|
|
12
|
+
export function sumRange(start, end) {
|
|
13
|
+
let total = 0;
|
|
14
|
+
for (let i = start; i < end; i += 1) {
|
|
15
|
+
total += i;
|
|
16
|
+
}
|
|
17
|
+
return total;
|
|
18
|
+
}
|
|
19
|
+
- path: test/range.test.js
|
|
20
|
+
content: |
|
|
21
|
+
import test from 'node:test';
|
|
22
|
+
import assert from 'node:assert/strict';
|
|
23
|
+
import { sumRange } from '../src/range.js';
|
|
24
|
+
|
|
25
|
+
test('angka terakhir ikut terhitung', () => {
|
|
26
|
+
assert.equal(sumRange(1, 3), 6);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('range satu angka ya angka itu', () => {
|
|
30
|
+
assert.equal(sumRange(5, 5), 5);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('mulai dari nol tetap benar', () => {
|
|
34
|
+
assert.equal(sumRange(0, 2), 3);
|
|
35
|
+
});
|
|
36
|
+
solution:
|
|
37
|
+
- path: src/range.js
|
|
38
|
+
content: |
|
|
39
|
+
export function sumRange(start, end) {
|
|
40
|
+
let total = 0;
|
|
41
|
+
for (let i = start; i <= end; i += 1) {
|
|
42
|
+
total += i;
|
|
43
|
+
}
|
|
44
|
+
return total;
|
|
45
|
+
}
|
|
46
|
+
tests: 3
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-indexof-missing-item
|
|
3
|
+
language: id
|
|
4
|
+
tags: [arrays, index, off-by-one]
|
|
5
|
+
brief: >-
|
|
6
|
+
nextAfter(items, current) ngasih item berikutnya dari daftar antrian.
|
|
7
|
+
Kalau current ternyata tidak ada di daftar, jawabannya tidak ada —
|
|
8
|
+
bukan item pertama, karena indexOf ngasilin -1.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/queue.js
|
|
11
|
+
content: |
|
|
12
|
+
export function nextAfter(items, current) {
|
|
13
|
+
return items[items.indexOf(current) + 1];
|
|
14
|
+
}
|
|
15
|
+
- path: test/queue.test.js
|
|
16
|
+
content: |
|
|
17
|
+
import test from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { nextAfter } from '../src/queue.js';
|
|
20
|
+
|
|
21
|
+
test('item berikutnya diambil dari posisi yang benar', () => {
|
|
22
|
+
assert.equal(nextAfter(['a', 'b', 'c'], 'b'), 'c');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Both sentinels are defensible, so the test asks "is there no answer"
|
|
26
|
+
// instead of pinning undefined over null.
|
|
27
|
+
test('item yang tidak dikenal tidak lompat ke awal', () => {
|
|
28
|
+
assert.equal(nextAfter(['a', 'b'], 'z') ?? null, null);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('item terakhir tidak punya berikutnya', () => {
|
|
32
|
+
assert.equal(nextAfter(['a'], 'a') ?? null, null);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('daftar kosong aman', () => {
|
|
36
|
+
assert.equal(nextAfter([], 'x') ?? null, null);
|
|
37
|
+
});
|
|
38
|
+
solution:
|
|
39
|
+
- path: src/queue.js
|
|
40
|
+
content: |
|
|
41
|
+
export function nextAfter(items, current) {
|
|
42
|
+
const index = items.indexOf(current);
|
|
43
|
+
if (index === -1) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return items[index + 1];
|
|
47
|
+
}
|
|
48
|
+
tests: 4
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-invoice-zero-pad
|
|
3
|
+
language: id
|
|
4
|
+
tags: [strings, padding, ids]
|
|
5
|
+
brief: >-
|
|
6
|
+
invoiceNumber(n) nulis nomor invoice supaya urutannya bener waktu di-sort
|
|
7
|
+
sebagai teks: nomornya di-pad nol sampai lima digit, INV-7 jadi INV-00007.
|
|
8
|
+
Nomor yang udah lebih dari lima digit tidak boleh dipotong.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/invoice.js
|
|
11
|
+
content: |
|
|
12
|
+
export function invoiceNumber(n) {
|
|
13
|
+
return `INV-${n}`;
|
|
14
|
+
}
|
|
15
|
+
- path: test/invoice.test.js
|
|
16
|
+
content: |
|
|
17
|
+
import test from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { invoiceNumber } from '../src/invoice.js';
|
|
20
|
+
|
|
21
|
+
test('nomor kecil di-pad sampai lima digit', () => {
|
|
22
|
+
assert.equal(invoiceNumber(7), 'INV-00007');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('empat digit juga di-pad', () => {
|
|
26
|
+
assert.equal(invoiceNumber(1000), 'INV-01000');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('nomor panjang tidak kepotong', () => {
|
|
30
|
+
assert.equal(invoiceNumber(123456), 'INV-123456');
|
|
31
|
+
});
|
|
32
|
+
solution:
|
|
33
|
+
- path: src/invoice.js
|
|
34
|
+
content: |
|
|
35
|
+
export function invoiceNumber(n) {
|
|
36
|
+
return `INV-${String(n).padStart(5, '0')}`;
|
|
37
|
+
}
|
|
38
|
+
tests: 3
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-json-date-roundtrip
|
|
3
|
+
language: id
|
|
4
|
+
tags: [json, dates, serialization]
|
|
5
|
+
brief: >-
|
|
6
|
+
restoreEvent(event) ngirim event lewat JSON buat nyimpen ke disk, terus
|
|
7
|
+
balikin lagi ke caller. Field "at" harus tetap berupa Date setelah lewat
|
|
8
|
+
JSON, karena caller manggil method Date di hasilnya.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/event.js
|
|
11
|
+
content: |
|
|
12
|
+
export function restoreEvent(event) {
|
|
13
|
+
return JSON.parse(JSON.stringify(event));
|
|
14
|
+
}
|
|
15
|
+
- path: test/event.test.js
|
|
16
|
+
content: |
|
|
17
|
+
import test from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { restoreEvent } from '../src/event.js';
|
|
20
|
+
|
|
21
|
+
const asal = {
|
|
22
|
+
title: 'rutin mingguan',
|
|
23
|
+
at: new Date('2026-01-02T03:04:05.000Z'),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
test('field at masih Date setelah lewat JSON', () => {
|
|
27
|
+
assert.ok(restoreEvent(asal).at instanceof Date);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('detiknya tidak berubah', () => {
|
|
31
|
+
assert.equal(restoreEvent(asal).at.getTime(), asal.at.getTime());
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('judul ikut kebalikin', () => {
|
|
35
|
+
assert.equal(restoreEvent(asal).title, 'rutin mingguan');
|
|
36
|
+
});
|
|
37
|
+
solution:
|
|
38
|
+
- path: src/event.js
|
|
39
|
+
content: |
|
|
40
|
+
export function restoreEvent(event) {
|
|
41
|
+
const plain = JSON.parse(JSON.stringify(event));
|
|
42
|
+
plain.at = new Date(plain.at);
|
|
43
|
+
return plain;
|
|
44
|
+
}
|
|
45
|
+
tests: 3
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-last-items-zero-count
|
|
3
|
+
language: id
|
|
4
|
+
hidden: true
|
|
5
|
+
tags: [arrays, slice, edge-case]
|
|
6
|
+
brief: >-
|
|
7
|
+
lastItems(items, count) ngambil beberapa pesan terakhir dari log chat.
|
|
8
|
+
count nol artinya tidak ada yang diminta — balas array kosong, jangan
|
|
9
|
+
kirim semua pesan. Kalau count-nya negatif, sama aja: nggak ada yang diambil.
|
|
10
|
+
Jumlah yang lebih besar dari panjang daftar ya semuanya.
|
|
11
|
+
files:
|
|
12
|
+
- path: src/lastItems.js
|
|
13
|
+
content: |
|
|
14
|
+
export function lastItems(items, count) {
|
|
15
|
+
return items.slice(-count);
|
|
16
|
+
}
|
|
17
|
+
- path: test/lastItems.test.js
|
|
18
|
+
content: |
|
|
19
|
+
import test from 'node:test';
|
|
20
|
+
import assert from 'node:assert/strict';
|
|
21
|
+
import { lastItems } from '../src/lastItems.js';
|
|
22
|
+
|
|
23
|
+
test('nol berarti tidak ada yang diambil', () => {
|
|
24
|
+
assert.deepEqual(lastItems(['a', 'b', 'c'], 0), []);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('dua pesan terakhir', () => {
|
|
28
|
+
assert.deepEqual(lastItems(['a', 'b', 'c'], 2), ['b', 'c']);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('minta lebih dari jumlahnya dikasih semua', () => {
|
|
32
|
+
assert.deepEqual(lastItems(['a'], 5), ['a']);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('bilangan negatif juga tidak ambil apa pun', () => {
|
|
36
|
+
assert.deepEqual(lastItems(['a', 'b'], -1), []);
|
|
37
|
+
});
|
|
38
|
+
solution:
|
|
39
|
+
- path: src/lastItems.js
|
|
40
|
+
content: |
|
|
41
|
+
export function lastItems(items, count) {
|
|
42
|
+
if (count <= 0) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
return items.slice(-count);
|
|
46
|
+
}
|
|
47
|
+
tests: 4
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-locale-thousands-dots
|
|
3
|
+
language: id
|
|
4
|
+
tags: [parsing, locale, money]
|
|
5
|
+
brief: >-
|
|
6
|
+
parseAmount(text) baca angka yang ditulis gaya Indonesia — titik sebagai
|
|
7
|
+
pemisah ribuan, misalnya "Rp 1.234.567" itu satu juta dua ratus tiga puluh
|
|
8
|
+
empat ribu lima ratus enam puluh tujuh. Outputnya angka bulat rupiah, dan
|
|
9
|
+
input-nya nggak pernah pakai koma desimal.
|
|
10
|
+
files:
|
|
11
|
+
- path: src/amount.js
|
|
12
|
+
content: |
|
|
13
|
+
export function parseAmount(text) {
|
|
14
|
+
return Number(text.replace(/[^\d.]/g, ''));
|
|
15
|
+
}
|
|
16
|
+
- path: test/amount.test.js
|
|
17
|
+
content: |
|
|
18
|
+
import test from 'node:test';
|
|
19
|
+
import assert from 'node:assert/strict';
|
|
20
|
+
import { parseAmount } from '../src/amount.js';
|
|
21
|
+
|
|
22
|
+
test('Titik ribuan tidak membuat angka jadi NaN', () => {
|
|
23
|
+
assert.equal(parseAmount('Rp 1.234.567'), 1234567);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('Seribu tetap seribu, bukan satu', () => {
|
|
27
|
+
assert.equal(parseAmount('1.000'), 1000);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Angka polos tanpa pemisah diterima', () => {
|
|
31
|
+
assert.equal(parseAmount('45000'), 45000);
|
|
32
|
+
});
|
|
33
|
+
solution:
|
|
34
|
+
- path: src/amount.js
|
|
35
|
+
content: |
|
|
36
|
+
export function parseAmount(text) {
|
|
37
|
+
return Number(text.replace(/\D/g, ''));
|
|
38
|
+
}
|
|
39
|
+
tests: 3
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-map-key-type
|
|
3
|
+
language: en
|
|
4
|
+
tags: [maps, key-types, coercion]
|
|
5
|
+
brief: >-
|
|
6
|
+
stockFor(warehouse, sku) reads a stock count from a Map that was loaded from
|
|
7
|
+
JSON, so its keys are strings. Callers pass either "8812" or 8812 and must get
|
|
8
|
+
the same answer. An unknown sku reports zero stock instead of undefined.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/stock.js
|
|
11
|
+
content: |
|
|
12
|
+
export function stockFor(warehouse, sku) {
|
|
13
|
+
return warehouse.get(sku) ?? 0;
|
|
14
|
+
}
|
|
15
|
+
- path: test/stock.test.js
|
|
16
|
+
content: |
|
|
17
|
+
import test from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { stockFor } from '../src/stock.js';
|
|
20
|
+
|
|
21
|
+
const warehouse = new Map([['8812', 5]]);
|
|
22
|
+
|
|
23
|
+
test('a numeric sku still finds the record', () => {
|
|
24
|
+
assert.equal(stockFor(warehouse, 8812), 5);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('a string sku finds the record too', () => {
|
|
28
|
+
assert.equal(stockFor(warehouse, '8812'), 5);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('an unknown sku reports zero', () => {
|
|
32
|
+
assert.equal(stockFor(warehouse, '1111'), 0);
|
|
33
|
+
});
|
|
34
|
+
solution:
|
|
35
|
+
- path: src/stock.js
|
|
36
|
+
content: |
|
|
37
|
+
export function stockFor(warehouse, sku) {
|
|
38
|
+
return warehouse.get(String(sku)) ?? 0;
|
|
39
|
+
}
|
|
40
|
+
tests: 3
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-mask-secret
|
|
3
|
+
language: id
|
|
4
|
+
tags: [secrets, logging]
|
|
5
|
+
brief: >-
|
|
6
|
+
maskSecret(value) buat log: 3 karakter pertama dan 2 terakhir boleh kelihatan, sisanya
|
|
7
|
+
diganti bintang dengan panjang total sama. Nilai pendek (6 karakter atau kurang) harus
|
|
8
|
+
jadi bintang semua.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/mask.js
|
|
11
|
+
content: |
|
|
12
|
+
export function maskSecret(value) {
|
|
13
|
+
return '****' + value.slice(-4);
|
|
14
|
+
}
|
|
15
|
+
- path: test/mask.test.js
|
|
16
|
+
content: |
|
|
17
|
+
import test from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { maskSecret } from '../src/mask.js';
|
|
20
|
+
|
|
21
|
+
test('tepi kelihatan, tengah dibintang, panjang utuh', () => {
|
|
22
|
+
assert.equal(maskSecret('abcdef123456'), 'abc*******56');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('nilai pendek ditutup total', () => {
|
|
26
|
+
assert.equal(maskSecret('short'), '*****');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('string kosong tetap kosong', () => {
|
|
30
|
+
assert.equal(maskSecret(''), '');
|
|
31
|
+
});
|
|
32
|
+
solution:
|
|
33
|
+
- path: src/mask.js
|
|
34
|
+
content: |
|
|
35
|
+
export function maskSecret(value) {
|
|
36
|
+
if (value.length <= 6) {
|
|
37
|
+
return '*'.repeat(value.length);
|
|
38
|
+
}
|
|
39
|
+
const head = value.slice(0, 3);
|
|
40
|
+
const tail = value.slice(-2);
|
|
41
|
+
return head + '*'.repeat(value.length - 5) + tail;
|
|
42
|
+
}
|
|
43
|
+
tests: 3
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-match-null-guard
|
|
3
|
+
language: en
|
|
4
|
+
tags: [regex, "null", extraction]
|
|
5
|
+
brief: >-
|
|
6
|
+
firstDigits(text) pulls the first run of digits out of an incoming chat
|
|
7
|
+
message. Messages without any digits are normal traffic, so return null
|
|
8
|
+
instead of letting the caller crash on the match result.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/digits.js
|
|
11
|
+
content: |
|
|
12
|
+
export function firstDigits(text) {
|
|
13
|
+
return text.match(/\d+/)[0];
|
|
14
|
+
}
|
|
15
|
+
- path: test/digits.test.js
|
|
16
|
+
content: |
|
|
17
|
+
import test from 'node:test';
|
|
18
|
+
import assert from 'node:assert/strict';
|
|
19
|
+
import { firstDigits } from '../src/digits.js';
|
|
20
|
+
|
|
21
|
+
test('a plain code is extracted', () => {
|
|
22
|
+
assert.equal(firstDigits('kode 4211'), '4211');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('the first run wins', () => {
|
|
26
|
+
assert.equal(firstDigits('a1b2'), '1');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('no digits answers null', () => {
|
|
30
|
+
assert.equal(firstDigits('tanpa angka'), null);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('a leading digit still works', () => {
|
|
34
|
+
assert.equal(firstDigits('7 menit lagi'), '7');
|
|
35
|
+
});
|
|
36
|
+
solution:
|
|
37
|
+
- path: src/digits.js
|
|
38
|
+
content: |
|
|
39
|
+
export function firstDigits(text) {
|
|
40
|
+
const found = text.match(/\d+/);
|
|
41
|
+
return found ? found[0] : null;
|
|
42
|
+
}
|
|
43
|
+
tests: 4
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-memo-key-collision
|
|
3
|
+
language: id
|
|
4
|
+
tags: [caching, key-design, collision]
|
|
5
|
+
brief: >-
|
|
6
|
+
cachedQuote(cache, region, service) nyimpen kutipan biar tidak dihitung dua kali.
|
|
7
|
+
Kunci cache harus membedakan pasangan argumen: region "1,2" dengan service "3"
|
|
8
|
+
itu lain dari region "1" dengan service "2,3".
|
|
9
|
+
files:
|
|
10
|
+
- path: src/quote.js
|
|
11
|
+
content: |
|
|
12
|
+
export function cachedQuote(cache, region, service) {
|
|
13
|
+
const key = `${region},${service}`;
|
|
14
|
+
if (cache[key] === undefined) {
|
|
15
|
+
cache[key] = `${region}:${service}=100`;
|
|
16
|
+
}
|
|
17
|
+
return cache[key];
|
|
18
|
+
}
|
|
19
|
+
- path: test/quote.test.js
|
|
20
|
+
content: |
|
|
21
|
+
import test from 'node:test';
|
|
22
|
+
import assert from 'node:assert/strict';
|
|
23
|
+
import { cachedQuote } from '../src/quote.js';
|
|
24
|
+
|
|
25
|
+
test('pasangan argumen yang beda tidak boleh saling timpa', () => {
|
|
26
|
+
const cache = {};
|
|
27
|
+
const pertama = cachedQuote(cache, '1,2', '3');
|
|
28
|
+
const kedua = cachedQuote(cache, '1', '2,3');
|
|
29
|
+
assert.notEqual(pertama, kedua);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('argumen yang sama dapat nilai yang sama', () => {
|
|
33
|
+
const cache = {};
|
|
34
|
+
assert.equal(
|
|
35
|
+
cachedQuote(cache, 'bdg', 'ongkir'),
|
|
36
|
+
cachedQuote(cache, 'bdg', 'ongkir'),
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('dua pasangan berbeda menempati dua entri', () => {
|
|
41
|
+
const cache = {};
|
|
42
|
+
cachedQuote(cache, '1,2', '3');
|
|
43
|
+
cachedQuote(cache, '1', '2,3');
|
|
44
|
+
assert.equal(Object.keys(cache).length, 2);
|
|
45
|
+
});
|
|
46
|
+
solution:
|
|
47
|
+
- path: src/quote.js
|
|
48
|
+
content: |
|
|
49
|
+
export function cachedQuote(cache, region, service) {
|
|
50
|
+
const key = JSON.stringify([region, service]);
|
|
51
|
+
if (cache[key] === undefined) {
|
|
52
|
+
cache[key] = `${region}:${service}=100`;
|
|
53
|
+
}
|
|
54
|
+
return cache[key];
|
|
55
|
+
}
|
|
56
|
+
tests: 3
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-missing-address-crash
|
|
3
|
+
language: id
|
|
4
|
+
hidden: true
|
|
5
|
+
tags: [null-safety, optional-chaining, rendering]
|
|
6
|
+
brief: >-
|
|
7
|
+
cityLabel(user) dipakai di kartu pelanggan. Banyak user baru belum ngisi
|
|
8
|
+
alamat, dan alamat yang belum ada itu bukan error — tampilkan teks
|
|
9
|
+
"alamat belum diisi" sambil tetap menampilkan namanya.
|
|
10
|
+
files:
|
|
11
|
+
- path: src/label.js
|
|
12
|
+
content: |
|
|
13
|
+
export function cityLabel(user) {
|
|
14
|
+
return `${user.name} - ${user.address.city}`;
|
|
15
|
+
}
|
|
16
|
+
- path: test/label.test.js
|
|
17
|
+
content: |
|
|
18
|
+
import test from 'node:test';
|
|
19
|
+
import assert from 'node:assert/strict';
|
|
20
|
+
import { cityLabel } from '../src/label.js';
|
|
21
|
+
|
|
22
|
+
test('user dengan alamat tampil normal', () => {
|
|
23
|
+
assert.equal(cityLabel({ name: 'Budi', address: { city: 'Salemba' } }), 'Budi - Salemba');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('user tanpa alamat tidak membuat halaman mati', () => {
|
|
27
|
+
assert.equal(cityLabel({ name: 'Siti' }), 'Siti - alamat belum diisi');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('address yang diisi null diperlakukan sama', () => {
|
|
31
|
+
assert.equal(cityLabel({ name: 'Ade', address: null }), 'Ade - alamat belum diisi');
|
|
32
|
+
});
|
|
33
|
+
solution:
|
|
34
|
+
- path: src/label.js
|
|
35
|
+
content: |
|
|
36
|
+
export function cityLabel(user) {
|
|
37
|
+
return `${user.name} - ${user.address?.city ?? 'alamat belum diisi'}`;
|
|
38
|
+
}
|
|
39
|
+
tests: 3
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-month-index-label
|
|
3
|
+
language: id
|
|
4
|
+
tags: [dates, off-by-one]
|
|
5
|
+
brief: >-
|
|
6
|
+
formatTanggal(date) ngeluarin "dd/mm/yyyy" untuk label invoice.
|
|
7
|
+
Bulan November keluar sebagai 10 dan Januari keluar sebagai 00.
|
|
8
|
+
Pakai bagian UTC dari tanggal supaya hasilnya tidak bergantung zona waktu mesin.
|
|
9
|
+
files:
|
|
10
|
+
- path: src/dateLabel.js
|
|
11
|
+
content: |
|
|
12
|
+
export function formatTanggal(date) {
|
|
13
|
+
const d = String(date.getUTCDate()).padStart(2, '0');
|
|
14
|
+
const m = String(date.getUTCMonth()).padStart(2, '0');
|
|
15
|
+
return `${d}/${m}/${date.getUTCFullYear()}`;
|
|
16
|
+
}
|
|
17
|
+
- path: test/dateLabel.test.js
|
|
18
|
+
content: |
|
|
19
|
+
import test from 'node:test';
|
|
20
|
+
import assert from 'node:assert/strict';
|
|
21
|
+
import { formatTanggal } from '../src/dateLabel.js';
|
|
22
|
+
|
|
23
|
+
test('november ditulis 11', () => {
|
|
24
|
+
assert.equal(formatTanggal(new Date(Date.UTC(2026, 10, 3))), '03/11/2026');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('januari ditulis 01', () => {
|
|
28
|
+
assert.equal(formatTanggal(new Date(Date.UTC(2027, 0, 9))), '09/01/2027');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('desember ditulis 12', () => {
|
|
32
|
+
assert.equal(formatTanggal(new Date(Date.UTC(2026, 11, 25))), '25/12/2026');
|
|
33
|
+
});
|
|
34
|
+
solution:
|
|
35
|
+
- path: src/dateLabel.js
|
|
36
|
+
content: |
|
|
37
|
+
export function formatTanggal(date) {
|
|
38
|
+
const d = String(date.getUTCDate()).padStart(2, '0');
|
|
39
|
+
const m = String(date.getUTCMonth() + 1).padStart(2, '0');
|
|
40
|
+
return `${d}/${m}/${date.getUTCFullYear()}`;
|
|
41
|
+
}
|
|
42
|
+
tests: 3
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
schema: hahahah.coding.fixture/v1
|
|
2
|
+
id: cod-no-mutation
|
|
3
|
+
language: id
|
|
4
|
+
tags: [purity, arrays]
|
|
5
|
+
brief: >-
|
|
6
|
+
normalizeIds(ids) harus ngasih array baru yang sudah diurutkan dan di-lowercase.
|
|
7
|
+
Array milik pemanggil nggak boleh berubah urutannya.
|
|
8
|
+
files:
|
|
9
|
+
- path: src/ids.js
|
|
10
|
+
content: |
|
|
11
|
+
export function normalizeIds(ids) {
|
|
12
|
+
return ids.sort((a, b) => a.localeCompare(b)).map((id) => id.trim().toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
- path: test/ids.test.js
|
|
15
|
+
content: |
|
|
16
|
+
import test from 'node:test';
|
|
17
|
+
import assert from 'node:assert/strict';
|
|
18
|
+
import { normalizeIds } from '../src/ids.js';
|
|
19
|
+
|
|
20
|
+
test('hasilnya terurut dan lowercase', () => {
|
|
21
|
+
assert.deepEqual(normalizeIds([' Beta ', 'alpha']), ['alpha', 'beta']);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('array pemanggil tidak ikut berubah', () => {
|
|
25
|
+
const input = ['zulu', 'alpha'];
|
|
26
|
+
normalizeIds(input);
|
|
27
|
+
assert.deepEqual(input, ['zulu', 'alpha']);
|
|
28
|
+
});
|
|
29
|
+
solution:
|
|
30
|
+
- path: src/ids.js
|
|
31
|
+
content: |
|
|
32
|
+
export function normalizeIds(ids) {
|
|
33
|
+
return [...ids]
|
|
34
|
+
.map((id) => id.trim().toLowerCase())
|
|
35
|
+
.sort((a, b) => a.localeCompare(b));
|
|
36
|
+
}
|
|
37
|
+
tests: 2
|