Skip to content

Commit

Permalink
fix: distribute also AI-generated ideas to orchestrator (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
swouf authored Oct 17, 2024
1 parent 088500e commit 1b5c15f
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 1,741 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default [
},
...fixupConfigRules(
compat.extends(
"airbnb",
"airbnb",
"plugin:import/typescript", // this is needed because airbnb uses eslint-plugin-import
"prettier",
"plugin:cypress/recommended",
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
"check": "concurrently --kill-others-on-fail -s all -n \"type-check,linter,prettier\" \"yarn type-check\" \"yarn lint\" \"yarn prettier:check\"",
"pre-commit": "concurrently --kill-others-on-fail -s all -n \"checks,tests\" \"yarn check\" \"yarn test\"",
"cypress:open": "env-cmd -f ./.env.test cypress open",
"test": "concurrently -k -s first -n \"test-server,cypress\" \"yarn start:test\" \"yarn test:ci\" ",
"test": "concurrently -k -s first -n \"test-server,cypress\" \"yarn start:test\" \"yarn test:ci\"",
"test:ci": "env-cmd -f ./.env.test cypress run --browser chrome --headless && nyc report --reporter=text --reporter=text-summary",
"unit-tests": "vitest",
"unit-tests": "vitest run",
"cov:report": "open ./coverage/lcov-report/index.html"
},
"devDependencies": {
Expand Down Expand Up @@ -114,7 +114,6 @@
"eslint": "9.12.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "9.1.0",
"eslint-config-react-app": "7.0.1",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-cypress": "4.0.0",
"eslint-plugin-import": "2.31.0",
Expand Down
70 changes: 58 additions & 12 deletions src/hooks/utils/responses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import { afterAll, beforeAll, expect, test, vi } from 'vitest';
import { ResponseAppData } from '@/config/appDataTypes';

import { mockItem, mockMembers } from '../../mocks/db';
import { buildMockResponses } from '../../mocks/mockResponses';
import {
buildMockBotResponses,
buildMockResponses,
} from '../../mocks/mockResponses';
import {
extractNResponsesThatDontHaveMemberAsCreator,
filterBotResponses,
recursivelyCreateAllPartiallyBlindSets,
} from './responses';

const getMapResponses = (): Map<string, ResponseAppData> => {
const mockResponses = buildMockResponses(mockItem, mockMembers);
const getMapResponses = (
responsesAppData: ResponseAppData[],
): Map<string, ResponseAppData> => {
const mockResponses = responsesAppData;
return new Map(mockResponses.map((r) => [r.id, r]));
};

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

test('the mocks are good', () => {
const mapResponses = getMapResponses();
const mapResponses = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);
expect(mapResponses).to.be.a('map');
expect(mapResponses).not.toBeUndefined();
// This value should more or less correspond to the mocks.
expect(mapResponses.size).to.be.greaterThanOrEqual(12);
});

test('the response map is passed by reference and remains the same', () => {
const mapResponses = getMapResponses();
const mapResponses = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);

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

test('extracting two responses', () => {
const mapResponses = getMapResponses();
const mapResponses = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);
const n = 2;
const initialSize = mapResponses.size;

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

test('extracting zero responses gives empty array', () => {
const mapResponses = getMapResponses();
const mapResponses = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);
const copyOfMapResponses = cloneDeep(mapResponses);
const n = 0;

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

test('extracting more responses than available gives all available', () => {
const mapResponses = getMapResponses();
const mapResponses = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);
const n = mapResponses.size + 2;
const accountId = mockMembers[0].id;

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

test('recursively create all sets', () => {
const mapResponses = getMapResponses();
test('recursively create all sets with no bot responses', () => {
const mapResponses = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);
const participantIterator = mockMembers.entries();
const sets = recursivelyCreateAllPartiallyBlindSets(
participantIterator,
mapResponses,
new Map(),
3,
0,
);
expect(sets.size).not.toBe(0);
expect(sets).to.have.keys(mockMembers.map(({ id }) => id));
mockMembers.forEach(({ id }) => {
const set = sets.get(id);
expect(set).to.have.length(3);
});
});

test('recursively create all sets with bot responses', () => {
const mapResponses = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);
const mapBotResponses = getMapResponses(
buildMockBotResponses(mockItem, mockMembers),
);
const participantIterator = mockMembers.entries();
const sets = recursivelyCreateAllPartiallyBlindSets(
participantIterator,
mapResponses,
mapBotResponses,
2,
1,
);
expect(sets.size).not.toBe(0);
expect(sets).to.have.keys(mockMembers.map(({ id }) => id));
mockMembers.forEach(({ id }) => {
const set = sets.get(id);
expect(set).to.have.length(3);
});
});

test('filtering bot responses', () => {
const responsesMap = getMapResponses();
const responsesMap = getMapResponses(
buildMockResponses(mockItem, mockMembers),
);
const responses = Array.from(responsesMap.values());

expect(responses.length).toBeGreaterThanOrEqual(3);
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/utils/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export const extractNResponsesThatDontHaveMemberAsCreator = (
accountId: Member['id'],
keepExtracted = false,
): [ResponseAppData[], Map<string, ResponseAppData>] => {
// console.log('Responses to extract: ', responses);
// console.log('n: ', n);
// console.log('accountId: ', accountId);
const responsesIterator = responses.entries();
const toDelete: string[] = [];
const responsesArray = [];
Expand Down Expand Up @@ -57,7 +54,8 @@ export const recursivelyCreateAllPartiallyBlindSets = <
extractNResponsesThatDontHaveMemberAsCreator(
botResponsesLocal,
numberOfBotResponsesPerSet,
participantId,
'', // Hack: we don't need to filter out the creator because those are
// bots ideas
!exclusiveResponseDistribution,
);
const [participantsResponsesForMember, newParticipantsResponses] =
Expand Down
40 changes: 39 additions & 1 deletion src/mocks/mockResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,42 @@ const buildMockResponses = (
},
];

export { buildMockResponses };
const buildMockBotResponses = (
mockItem: DiscriminatedItem,
mockMembers: Member[],
): ResponseAppData[] => [
{
id: '000-bot',
item: mockItem,
creator: mockMembers[0],
type: AppDataTypes.Response,
account: mockMembers[0],
visibility: AppDataVisibility.Item,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
data: {
response: 'A giant robots factory.',
round: 0,
bot: true,
assistantId: 'assistant-1',
},
},
{
id: '001-bot',
item: mockItem,
creator: mockMembers[0],
type: AppDataTypes.Response,
account: mockMembers[0],
visibility: AppDataVisibility.Item,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
data: {
response: 'Downloading human consciousness into robotic bodies.',
round: 0,
bot: true,
assistantId: 'assistant-1',
},
},
];

export { buildMockResponses, buildMockBotResponses };
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default ({ mode }: { mode: string }): UserConfigExport => {
: checker({
typescript: true,
eslint: {
useFlatConfig: true,
lintCommand: 'eslint "src/**/*.{ts,tsx}"',
},
}),
Expand Down
Loading

0 comments on commit 1b5c15f

Please sign in to comment.