Skip to content

Commit 1b5c15f

Browse files
authored
fix: distribute also AI-generated ideas to orchestrator (#575)
1 parent 088500e commit 1b5c15f

File tree

7 files changed

+152
-1741
lines changed

7 files changed

+152
-1741
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default [
3333
},
3434
...fixupConfigRules(
3535
compat.extends(
36-
"airbnb",
36+
"airbnb",
3737
"plugin:import/typescript", // this is needed because airbnb uses eslint-plugin-import
3838
"prettier",
3939
"plugin:cypress/recommended",

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@
7676
"check": "concurrently --kill-others-on-fail -s all -n \"type-check,linter,prettier\" \"yarn type-check\" \"yarn lint\" \"yarn prettier:check\"",
7777
"pre-commit": "concurrently --kill-others-on-fail -s all -n \"checks,tests\" \"yarn check\" \"yarn test\"",
7878
"cypress:open": "env-cmd -f ./.env.test cypress open",
79-
"test": "concurrently -k -s first -n \"test-server,cypress\" \"yarn start:test\" \"yarn test:ci\" ",
79+
"test": "concurrently -k -s first -n \"test-server,cypress\" \"yarn start:test\" \"yarn test:ci\"",
8080
"test:ci": "env-cmd -f ./.env.test cypress run --browser chrome --headless && nyc report --reporter=text --reporter=text-summary",
81-
"unit-tests": "vitest",
81+
"unit-tests": "vitest run",
8282
"cov:report": "open ./coverage/lcov-report/index.html"
8383
},
8484
"devDependencies": {
@@ -114,7 +114,6 @@
114114
"eslint": "9.12.0",
115115
"eslint-config-airbnb": "19.0.4",
116116
"eslint-config-prettier": "9.1.0",
117-
"eslint-config-react-app": "7.0.1",
118117
"eslint-import-resolver-typescript": "^3.6.1",
119118
"eslint-plugin-cypress": "4.0.0",
120119
"eslint-plugin-import": "2.31.0",

src/hooks/utils/responses.test.ts

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import { afterAll, beforeAll, expect, test, vi } from 'vitest';
44
import { ResponseAppData } from '@/config/appDataTypes';
55

66
import { mockItem, mockMembers } from '../../mocks/db';
7-
import { buildMockResponses } from '../../mocks/mockResponses';
7+
import {
8+
buildMockBotResponses,
9+
buildMockResponses,
10+
} from '../../mocks/mockResponses';
811
import {
912
extractNResponsesThatDontHaveMemberAsCreator,
1013
filterBotResponses,
1114
recursivelyCreateAllPartiallyBlindSets,
1215
} from './responses';
1316

14-
const getMapResponses = (): Map<string, ResponseAppData> => {
15-
const mockResponses = buildMockResponses(mockItem, mockMembers);
17+
const getMapResponses = (
18+
responsesAppData: ResponseAppData[],
19+
): Map<string, ResponseAppData> => {
20+
const mockResponses = responsesAppData;
1621
return new Map(mockResponses.map((r) => [r.id, r]));
1722
};
1823

@@ -24,15 +29,19 @@ afterAll(() => {
2429
});
2530

2631
test('the mocks are good', () => {
27-
const mapResponses = getMapResponses();
32+
const mapResponses = getMapResponses(
33+
buildMockResponses(mockItem, mockMembers),
34+
);
2835
expect(mapResponses).to.be.a('map');
2936
expect(mapResponses).not.toBeUndefined();
3037
// This value should more or less correspond to the mocks.
3138
expect(mapResponses.size).to.be.greaterThanOrEqual(12);
3239
});
3340

3441
test('the response map is passed by reference and remains the same', () => {
35-
const mapResponses = getMapResponses();
42+
const mapResponses = getMapResponses(
43+
buildMockResponses(mockItem, mockMembers),
44+
);
3645

3746
const [, newMapR] = extractNResponsesThatDontHaveMemberAsCreator(
3847
mapResponses,
@@ -43,7 +52,9 @@ test('the response map is passed by reference and remains the same', () => {
4352
});
4453

4554
test('extracting two responses', () => {
46-
const mapResponses = getMapResponses();
55+
const mapResponses = getMapResponses(
56+
buildMockResponses(mockItem, mockMembers),
57+
);
4758
const n = 2;
4859
const initialSize = mapResponses.size;
4960

@@ -57,7 +68,9 @@ test('extracting two responses', () => {
5768
});
5869

5970
test('extracting zero responses gives empty array', () => {
60-
const mapResponses = getMapResponses();
71+
const mapResponses = getMapResponses(
72+
buildMockResponses(mockItem, mockMembers),
73+
);
6174
const copyOfMapResponses = cloneDeep(mapResponses);
6275
const n = 0;
6376

@@ -66,12 +79,14 @@ test('extracting zero responses gives empty array', () => {
6679
n,
6780
mockMembers[0].id,
6881
);
69-
expect(r).to.be.empty('');
82+
expect(r).to.have.length(0);
7083
expect(newMapR).to.be.deep.equals(copyOfMapResponses);
7184
});
7285

7386
test('extracting more responses than available gives all available', () => {
74-
const mapResponses = getMapResponses();
87+
const mapResponses = getMapResponses(
88+
buildMockResponses(mockItem, mockMembers),
89+
);
7590
const n = mapResponses.size + 2;
7691
const accountId = mockMembers[0].id;
7792

@@ -86,22 +101,53 @@ test('extracting more responses than available gives all available', () => {
86101
.that.does.not.include(false);
87102
});
88103

89-
test('recursively create all sets', () => {
90-
const mapResponses = getMapResponses();
104+
test('recursively create all sets with no bot responses', () => {
105+
const mapResponses = getMapResponses(
106+
buildMockResponses(mockItem, mockMembers),
107+
);
91108
const participantIterator = mockMembers.entries();
92109
const sets = recursivelyCreateAllPartiallyBlindSets(
93110
participantIterator,
94111
mapResponses,
95112
new Map(),
96113
3,
114+
0,
115+
);
116+
expect(sets.size).not.toBe(0);
117+
expect(sets).to.have.keys(mockMembers.map(({ id }) => id));
118+
mockMembers.forEach(({ id }) => {
119+
const set = sets.get(id);
120+
expect(set).to.have.length(3);
121+
});
122+
});
123+
124+
test('recursively create all sets with bot responses', () => {
125+
const mapResponses = getMapResponses(
126+
buildMockResponses(mockItem, mockMembers),
127+
);
128+
const mapBotResponses = getMapResponses(
129+
buildMockBotResponses(mockItem, mockMembers),
130+
);
131+
const participantIterator = mockMembers.entries();
132+
const sets = recursivelyCreateAllPartiallyBlindSets(
133+
participantIterator,
134+
mapResponses,
135+
mapBotResponses,
136+
2,
97137
1,
98138
);
99139
expect(sets.size).not.toBe(0);
100140
expect(sets).to.have.keys(mockMembers.map(({ id }) => id));
141+
mockMembers.forEach(({ id }) => {
142+
const set = sets.get(id);
143+
expect(set).to.have.length(3);
144+
});
101145
});
102146

103147
test('filtering bot responses', () => {
104-
const responsesMap = getMapResponses();
148+
const responsesMap = getMapResponses(
149+
buildMockResponses(mockItem, mockMembers),
150+
);
105151
const responses = Array.from(responsesMap.values());
106152

107153
expect(responses.length).toBeGreaterThanOrEqual(3);

src/hooks/utils/responses.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ export const extractNResponsesThatDontHaveMemberAsCreator = (
1010
accountId: Member['id'],
1111
keepExtracted = false,
1212
): [ResponseAppData[], Map<string, ResponseAppData>] => {
13-
// console.log('Responses to extract: ', responses);
14-
// console.log('n: ', n);
15-
// console.log('accountId: ', accountId);
1613
const responsesIterator = responses.entries();
1714
const toDelete: string[] = [];
1815
const responsesArray = [];
@@ -57,7 +54,8 @@ export const recursivelyCreateAllPartiallyBlindSets = <
5754
extractNResponsesThatDontHaveMemberAsCreator(
5855
botResponsesLocal,
5956
numberOfBotResponsesPerSet,
60-
participantId,
57+
'', // Hack: we don't need to filter out the creator because those are
58+
// bots ideas
6159
!exclusiveResponseDistribution,
6260
);
6361
const [participantsResponsesForMember, newParticipantsResponses] =

src/mocks/mockResponses.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,42 @@ const buildMockResponses = (
188188
},
189189
];
190190

191-
export { buildMockResponses };
191+
const buildMockBotResponses = (
192+
mockItem: DiscriminatedItem,
193+
mockMembers: Member[],
194+
): ResponseAppData[] => [
195+
{
196+
id: '000-bot',
197+
item: mockItem,
198+
creator: mockMembers[0],
199+
type: AppDataTypes.Response,
200+
account: mockMembers[0],
201+
visibility: AppDataVisibility.Item,
202+
createdAt: new Date().toISOString(),
203+
updatedAt: new Date().toISOString(),
204+
data: {
205+
response: 'A giant robots factory.',
206+
round: 0,
207+
bot: true,
208+
assistantId: 'assistant-1',
209+
},
210+
},
211+
{
212+
id: '001-bot',
213+
item: mockItem,
214+
creator: mockMembers[0],
215+
type: AppDataTypes.Response,
216+
account: mockMembers[0],
217+
visibility: AppDataVisibility.Item,
218+
createdAt: new Date().toISOString(),
219+
updatedAt: new Date().toISOString(),
220+
data: {
221+
response: 'Downloading human consciousness into robotic bodies.',
222+
round: 0,
223+
bot: true,
224+
assistantId: 'assistant-1',
225+
},
226+
},
227+
];
228+
229+
export { buildMockResponses, buildMockBotResponses };

vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default ({ mode }: { mode: string }): UserConfigExport => {
3535
: checker({
3636
typescript: true,
3737
eslint: {
38+
useFlatConfig: true,
3839
lintCommand: 'eslint "src/**/*.{ts,tsx}"',
3940
},
4041
}),

0 commit comments

Comments
 (0)