Index `first`, apply `change`, sync and compare with a fresh index; `looked` says how the pass went.
(first: Record<string, string>, change: (root: string) => void)
| 721 | |
| 722 | /** Index `first`, apply `change`, sync and compare with a fresh index; `looked` says how the pass went. */ |
| 723 | async function synced(first: Record<string, string>, change: (root: string) => void): Promise<{ cg: CodeGraph; root: string; looked: 'the change' | 'the project'; files: number }> { |
| 724 | const project = vi.spyOn(ParameterFlowQueries.prototype, 'getReachedMethods'); |
| 725 | const { root, cg } = await indexed(first); |
| 726 | project.mockClear(); |
| 727 | const adapter = rubyParameterFlow.adapter.bind(rubyParameterFlow); |
| 728 | let files = 0; |
| 729 | const made = vi.spyOn(rubyParameterFlow, 'adapter').mockImplementation((...args) => { |
| 730 | const flow = adapter(...args); |
| 731 | const written = flow.written.bind(flow); |
| 732 | flow.written = (names, list) => { |
| 733 | files = Math.max(files, list.length); |
| 734 | return written(names, list); |
| 735 | }; |
| 736 | return flow; |
| 737 | }); |
| 738 | change(root); |
| 739 | await cg.sync(); |
| 740 | const looked = project.mock.calls.length > 0 ? 'the project' : 'the change'; |
| 741 | project.mockRestore(); |
| 742 | made.mockRestore(); |
| 743 | const fresh = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-parameter-flow-fresh-')); |
| 744 | roots.push(fresh); |
| 745 | fs.cpSync(root, fresh, { recursive: true, filter: (src) => !src.includes('.codegraph') }); |
| 746 | const rebuilt = await CodeGraph.init(fresh, { index: true }); |
| 747 | open.push(rebuilt); |
| 748 | expect(graphOf(cg)).toEqual(graphOf(rebuilt)); |
| 749 | return { cg, root, looked, files }; |
| 750 | } |
| 751 | |
| 752 | const record = (cg: CodeGraph): string | null => (cg as unknown as { queries: QueryBuilder }).queries.getMetadata('parameter_flow_record_ruby'); |
| 753 | const setRecord = (cg: CodeGraph, value: string): void => (cg as unknown as { queries: QueryBuilder }).queries.setMetadata('parameter_flow_record_ruby', value); |